Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ begin
rescue LoadError
end

task :validate do
Dir['bin/**/*.rb','lib/**/*.rb'].each do |ruby_file|
sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/
end
end

def run_puppet (type, modulename, facts={})
args = [ 'puppet', 'apply', '--debug' ]
Expand Down Expand Up @@ -64,4 +69,4 @@ end


task :integration_tests => [:test_hiera, :test_hiera_compat, :test_hiera_compat_with_autorun, :test_data_binding, :test_policy_override]
task :default => [:integration_tests, :spec]
task :default => [:validate, :integration_tests, :spec]
7 changes: 5 additions & 2 deletions lib/jerakia/server/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,15 @@ def mandatory_params(mandatory, params)
end

get '/v1/lookup/:key' do
mandatory_params(['namespace'], params)

request_opts = {
:key => params['key'],
:namespace => params['namespace'].split(/\//),
}

if params['namespace']
request_opts[:namespace] = params['namespace'].split(/\//)
end

metadata = params.select { |k,v| k =~ /^metadata_.*/ }
scope_opts = params.select { |k,v| k =~ /^scope_.*/ }

Expand Down
54 changes: 54 additions & 0 deletions spec/features/namespaceless_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require 'spec_helper'

describe Jerakia do
let(:subject) { Jerakia.new(:config => "#{JERAKIA_ROOT}/test/fixtures/etc/jerakia/jerakia.yaml") }
let(:request) { Jerakia::Request.new }
let(:answer) { subject.lookup(request) }

describe 'Without namespace' do
context 'first result lookup' do
let(:request) do
Jerakia::Request.new(
metadata: { env: 'dev' },
key: 'biscuits'
)
end

it 'should return a response' do
expect(answer).to be_a(Jerakia::Answer)
end

it 'should have an array as a payload' do
expect(answer.payload).to be_a(Array)
end

it 'should contain the entries for dev' do
expect(answer.payload).to eq(["gingernuts", "jammiedodgers", "custardcreams"])
end
end
context 'array lookup' do
let(:request) do
Jerakia::Request.new(
metadata: { env: 'dev' },
key: 'biscuits',
lookup_type: :cascade,
merge: :array
)
end

it 'should return a response' do
expect(answer).to be_a(Jerakia::Answer)
end

it 'should have an array as a payload' do
expect(answer.payload).to be_a(Array)
end

it 'should contain all the elements' do
expect(answer.payload).to eq(["gingernuts", "jammiedodgers", "custardcreams", "richtea", "digestive"])
end
end
end
end


9 changes: 9 additions & 0 deletions test/fixtures/var/lib/jerakia/data/common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
# Data from this file would be looked up when not using namespaces.
#

biscuits:
- richtea
- digestive


9 changes: 9 additions & 0 deletions test/fixtures/var/lib/jerakia/data/env/dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
# Data from this file would be looked up when not using namespaces.
#

biscuits:
- gingernuts
- jammiedodgers
- custardcreams