Please review pull request #3: (maint) Use two spaces for indentation opened by (kelseyhightower)
Description:
- Opened: Mon Apr 30 23:37:58 UTC 2012
- Based on: puppetlabs:master (4d5d5979b1b58fd1b634caca13e6282f756e508f)
- Requested merge: kelseyhightower:master (2911386e66deba92a99c42ed759c64cbc9b1cf35)
Diff follows:
diff --git a/README.md b/README.md
index b856399..d7641f2 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,10 @@
What?
-=====
+-----
A JSON backend for Hiera
Configuration?
-==============
+--------------
A sample Hiera config file that activates this backend and stores
data in _/etc/puppet/hieradata_ can be seen below:
@@ -18,7 +18,7 @@ data in _/etc/puppet/hieradata_ can be seen below:
:datadir: /etc/puppet/hieradata
</pre>
-Constact?
-=========
+Support
+-------
-R.I.Pienaar / [email protected] / @ripienaar / www.devco.net
+Please log tickets and issues at our [Projects site](http://projects.puppetlabs.com)
diff --git a/Rakefile b/Rakefile
index a9ad774..efd2e37 100644
--- a/Rakefile
+++ b/Rakefile
@@ -26,8 +26,8 @@ end
desc "Run all specs"
RSpec::Core::RakeTask.new(:test) do |t|
- t.pattern = 'spec/**/*_spec.rb'
- t.rspec_opts = File.read("spec/spec.opts").chomp || ""
+ t.pattern = 'spec/**/*_spec.rb'
+ t.rspec_opts = File.read("spec/spec.opts").chomp || ""
end
task :default => [:test, :repackage]
diff --git a/lib/hiera/backend/json_backend.rb b/lib/hiera/backend/json_backend.rb
index 997a396..eb2f76e 100644
--- a/lib/hiera/backend/json_backend.rb
+++ b/lib/hiera/backend/json_backend.rb
@@ -1,43 +1,43 @@
class Hiera
- module Backend
- class Json_backend
- def initialize
- require 'json'
+ module Backend
+ class Json_backend
+ def initialize
+ require 'json'
- Hiera.debug("Hiera JSON backend starting")
- end
+ Hiera.debug("Hiera JSON backend starting")
+ end
- def lookup(key, scope, order_override, resolution_type)
- answer = Backend.empty_answer(resolution_type)
+ def lookup(key, scope, order_override, resolution_type)
+ answer = Backend.empty_answer(resolution_type)
- Hiera.debug("Looking up #{key} in JSON backend")
+ Hiera.debug("Looking up #{key} in JSON backend")
- Backend.datasources(scope, order_override) do |source|
- Hiera.debug("Looking for data source #{source}")
+ Backend.datasources(scope, order_override) do |source|
+ Hiera.debug("Looking for data source #{source}")
- jsonfile = Backend.datafile(:json, scope, source, "json") || next
+ jsonfile = Backend.datafile(:json, scope, source, "json") || next
- data = ""
+ data = ""
- next if data.empty?
- next unless data.include?(key)
+ next if data.empty?
+ next unless data.include?(key)
- # for array resolution we just append to the array whatever
- # we find, we then goes onto the next file and keep adding to
- # the array
- #
- # for priority searches we break after the first found data item
- case resolution_type
- when :array
- answer << Backend.parse_answer(data[key], scope)
- else
- answer = Backend.parse_answer(data[key], scope)
- break
- end
- end
-
- return answer
- end
+ # for array resolution we just append to the array whatever
+ # we find, we then goes onto the next file and keep adding to
+ # the array
+ #
+ # for priority searches we break after the first found data item
+ case resolution_type
+ when :array
+ answer << Backend.parse_answer(data[key], scope)
+ else
+ answer = Backend.parse_answer(data[key], scope)
+ break
+ end
end
+
+ return answer
+ end
end
+ end
end
diff --git a/spec/json_backend_spec.rb b/spec/json_backend_spec.rb
index b9064d5..69241e5 100644
--- a/spec/json_backend_spec.rb
+++ b/spec/json_backend_spec.rb
@@ -7,92 +7,92 @@
require 'hiera/backend/json_backend'
RSpec.configure do |config|
- config.mock_with :mocha
+ config.mock_with :mocha
end
class Hiera
- module Backend
- describe Json_backend do
- before do
- Hiera.stubs(:debug)
- Hiera.stubs(:warn)
- Hiera::Backend.stubs(:empty_answer).returns(nil)
- @backend = Json_backend.new
- end
-
- describe "#initialize" do
- it "should announce its creation" do # because other specs checks this
- Hiera.expects(:debug).with("Hiera JSON backend starting")
- Json_backend.new
- end
- end
-
- describe "#lookup" do
- it "should look for data in all sources" do
- Backend.expects(:datasources).multiple_yields(["one"], ["two"])
- Backend.expects(:datafile).with(:json, {}, "one", "json").returns(nil)
- Backend.expects(:datafile).with(:json, {}, "two", "json").returns(nil)
-
- @backend.lookup("key", {}, nil, :priority)
- end
-
- it "should retain the data types found in data files" do
- Backend.expects(:datasources).yields("one").times(3)
- Backend.expects(:datafile).with(:json, {}, "one", "json").returns("/nonexisting/one.json").times(3)
- File.expects(:read).with("/nonexisting/one.json").returns('{"stringval":"string",
- "boolval":true,
- "numericval":1}').times(3)
-
- Backend.stubs(:parse_answer).with('string', {}).returns('string')
- Backend.stubs(:parse_answer).with(true, {}).returns(true)
- Backend.stubs(:parse_answer).with(1, {}).returns(1)
-
- @backend.lookup("stringval", {}, nil, :priority).should == "string"
- @backend.lookup("boolval", {}, nil, :priority).should == true
- @backend.lookup("numericval", {}, nil, :priority).should == 1
- end
-
- it "should pick data earliest source that has it for priority searches" do
- scope = {"rspec" => "test"}
- Backend.stubs(:parse_answer).with('answer', scope).returns("answer")
- Backend.stubs(:parse_answer).with('test_%{rspec}', scope).returns("test_test")
- Backend.expects(:datasources).multiple_yields(["one"], ["two"])
- Backend.expects(:datafile).with(:json, scope, "one", "json").returns("/nonexisting/one.json")
- Backend.expects(:datafile).with(:json, scope, "two", "json").returns(nil).never
- File.expects(:read).with("/nonexisting/one.json").returns("one.json")
- JSON.expects(:parse).with("one.json").returns({"key" => "test_%{rspec}"})
-
- @backend.lookup("key", scope, nil, :priority).should == "test_test"
- end
-
- it "should build an array of all data sources for array searches" do
- Hiera::Backend.stubs(:empty_answer).returns([])
- Backend.stubs(:parse_answer).with('answer', {}).returns("answer")
- Backend.expects(:datafile).with(:json, {}, "one", "json").returns("/nonexisting/one.json")
- Backend.expects(:datafile).with(:json, {}, "two", "json").returns("/nonexisting/two.json")
-
- Backend.expects(:datasources).multiple_yields(["one"], ["two"])
-
- File.expects(:read).with("/nonexisting/one.json").returns("one.json")
- File.expects(:read).with("/nonexisting/two.json").returns("two.json")
-
- JSON.expects(:parse).with("one.json").returns({"key" => "answer"})
- JSON.expects(:parse).with("two.json").returns({"key" => "answer"})
-
- @backend.lookup("key", {}, nil, :array).should == ["answer", "answer"]
- end
-
- it "should parse the answer for scope variables" do
- Backend.stubs(:parse_answer).with('test_%{rspec}', {'rspec' => 'test'}).returns("test_test")
- Backend.expects(:datasources).yields("one")
- Backend.expects(:datafile).with(:json, {"rspec" => "test"}, "one", "json").returns("/nonexisting/one.json")
-
- File.expects(:read).with("/nonexisting/one.json").returns("one.json")
- JSON.expects(:parse).with("one.json").returns({"key" => "test_%{rspec}"})
-
- @backend.lookup("key", {"rspec" => "test"}, nil, :priority).should == "test_test"
- end
- end
+ module Backend
+ describe Json_backend do
+ before do
+ Hiera.stubs(:debug)
+ Hiera.stubs(:warn)
+ Hiera::Backend.stubs(:empty_answer).returns(nil)
+ @backend = Json_backend.new
+ end
+
+ describe "#initialize" do
+ it "should announce its creation" do # because other specs checks this
+ Hiera.expects(:debug).with("Hiera JSON backend starting")
+ Json_backend.new
end
+ end
+
+ describe "#lookup" do
+ it "should look for data in all sources" do
+ Backend.expects(:datasources).multiple_yields(["one"], ["two"])
+ Backend.expects(:datafile).with(:json, {}, "one", "json").returns(nil)
+ Backend.expects(:datafile).with(:json, {}, "two", "json").returns(nil)
+
+ @backend.lookup("key", {}, nil, :priority)
+ end
+
+ it "should retain the data types found in data files" do
+ Backend.expects(:datasources).yields("one").times(3)
+ Backend.expects(:datafile).with(:json, {}, "one", "json").returns("/nonexisting/one.json").times(3)
+ File.expects(:read).with("/nonexisting/one.json").returns('{"stringval":"string",
+ "boolval":true,
+ "numericval":1}').times(3)
+
+ Backend.stubs(:parse_answer).with('string', {}).returns('string')
+ Backend.stubs(:parse_answer).with(true, {}).returns(true)
+ Backend.stubs(:parse_answer).with(1, {}).returns(1)
+
+ @backend.lookup("stringval", {}, nil, :priority).should == "string"
+ @backend.lookup("boolval", {}, nil, :priority).should == true
+ @backend.lookup("numericval", {}, nil, :priority).should == 1
+ end
+
+ it "should pick data earliest source that has it for priority searches" do
+ scope = {"rspec" => "test"}
+ Backend.stubs(:parse_answer).with('answer', scope).returns("answer")
+ Backend.stubs(:parse_answer).with('test_%{rspec}', scope).returns("test_test")
+ Backend.expects(:datasources).multiple_yields(["one"], ["two"])
+ Backend.expects(:datafile).with(:json, scope, "one", "json").returns("/nonexisting/one.json")
+ Backend.expects(:datafile).with(:json, scope, "two", "json").returns(nil).never
+ File.expects(:read).with("/nonexisting/one.json").returns("one.json")
+ JSON.expects(:parse).with("one.json").returns({"key" => "test_%{rspec}"})
+
+ @backend.lookup("key", scope, nil, :priority).should == "test_test"
+ end
+
+ it "should build an array of all data sources for array searches" do
+ Hiera::Backend.stubs(:empty_answer).returns([])
+ Backend.stubs(:parse_answer).with('answer', {}).returns("answer")
+ Backend.expects(:datafile).with(:json, {}, "one", "json").returns("/nonexisting/one.json")
+ Backend.expects(:datafile).with(:json, {}, "two", "json").returns("/nonexisting/two.json")
+
+ Backend.expects(:datasources).multiple_yields(["one"], ["two"])
+
+ File.expects(:read).with("/nonexisting/one.json").returns("one.json")
+ File.expects(:read).with("/nonexisting/two.json").returns("two.json")
+
+ JSON.expects(:parse).with("one.json").returns({"key" => "answer"})
+ JSON.expects(:parse).with("two.json").returns({"key" => "answer"})
+
+ @backend.lookup("key", {}, nil, :array).should == ["answer", "answer"]
+ end
+
+ it "should parse the answer for scope variables" do
+ Backend.stubs(:parse_answer).with('test_%{rspec}', {'rspec' => 'test'}).returns("test_test")
+ Backend.expects(:datasources).yields("one")
+ Backend.expects(:datafile).with(:json, {"rspec" => "test"}, "one", "json").returns("/nonexisting/one.json")
+
+ File.expects(:read).with("/nonexisting/one.json").returns("one.json")
+ JSON.expects(:parse).with("one.json").returns({"key" => "test_%{rspec}"})
+
+ @backend.lookup("key", {"rspec" => "test"}, nil, :priority).should == "test_test"
+ end
+ end
end
+ end
end
diff --git a/tasks/release.rb b/tasks/release.rb
index b472d5a..3b494d4 100644
--- a/tasks/release.rb
+++ b/tasks/release.rb
@@ -1,16 +1,13 @@
-
def described_version
- # This ugly bit removes the gSHA1 portion of the describe as that causes failing tests
- %x{git describe}.gsub('-', '.').split('.')[0..3].join('.').to_s.gsub('v', '')
+ # This ugly bit removes the gSHA1 portion of the describe as that causes failing tests
+ %x{git describe}.gsub('-', '.').split('.')[0..3].join('.').to_s.gsub('v', '')
end
namespace :pkg do
-
desc "Build Package"
task :release => [ :default ] do
Rake::Task[:package].invoke
end
-
end # namespace
task :clean => [ :clobber_package ] do
-- You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
