hiera-puppet 0.3.0 → 1.0.0rc2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Puppet::Parser::Functions#hiera_array' do
4
+ let(:scope) { PuppetlabsSpec::PuppetSeams.parser_scope }
5
+
6
+ it 'should require a key argument' do
7
+ expect { scope.function_hiera_array([]) }.to raise_error(Puppet::ParseError)
8
+ end
9
+
10
+ it 'should raise a useful error when nil is returned' do
11
+ Hiera.any_instance.expects(:lookup).returns(nil)
12
+ expect { scope.function_hiera_array("badkey") }.to raise_error(Puppet::ParseError, /Could not find data item badkey/ )
13
+ end
14
+
15
+ it 'should use the array resolution_type' do
16
+ Hiera.any_instance.expects(:lookup).with() { |*args| args[4].should be :array }.returns([])
17
+ scope.function_hiera_array(['key'])
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Puppet::Parser::Functions#hiera_hash' do
4
+ let(:scope) { PuppetlabsSpec::PuppetSeams.parser_scope }
5
+
6
+ it 'should require a key argument' do
7
+ expect { scope.function_hiera_hash([]) }.to raise_error(Puppet::ParseError)
8
+ end
9
+
10
+ it 'should raise a useful error when nil is returned' do
11
+ Hiera.any_instance.expects(:lookup).returns(nil)
12
+ expect { scope.function_hiera_hash("badkey") }.to raise_error(Puppet::ParseError, /Could not find data item badkey/ )
13
+ end
14
+
15
+ it 'should use the hash resolution_type' do
16
+ Hiera.any_instance.expects(:lookup).with() { |*args| args[4].should be :hash }.returns({})
17
+ scope.function_hiera_hash(['key'])
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Puppet::Parser::Functions#hiera_include' do
4
+ let(:scope) { PuppetlabsSpec::PuppetSeams.parser_scope }
5
+
6
+ it 'should require a key argument' do
7
+ expect { scope.function_hiera_include([]) }.to raise_error(Puppet::ParseError)
8
+ end
9
+
10
+ it 'should raise a useful error when nil is returned' do
11
+ Hiera.any_instance.expects(:lookup).returns(nil)
12
+ expect { scope.function_hiera_include("badkey") }.to raise_error(Puppet::ParseError, /Could not find data item badkey/ )
13
+ end
14
+
15
+ it 'should use the array resolution_type' do
16
+ Hiera.any_instance.expects(:lookup).with() { |*args| args[4].should be :array }.returns([])
17
+ scope.function_hiera_include(['key'])
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ #! /usr/bin/env ruby -S rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'Puppet::Parser::Functions#hiera' do
6
+ let(:scope) { PuppetlabsSpec::PuppetSeams.parser_scope }
7
+
8
+ it 'should require a key argument' do
9
+ expect { scope.function_hiera([]) }.to raise_error(Puppet::ParseError)
10
+ end
11
+
12
+ it 'should raise a useful error when nil is returned' do
13
+ Hiera.any_instance.expects(:lookup).returns(nil)
14
+ expect { scope.function_hiera("badkey") }.to raise_error(Puppet::ParseError, /Could not find data item badkey/ )
15
+ end
16
+
17
+ it 'should use the priority resolution_type' do
18
+ Hiera.any_instance.expects(:lookup).with() { |*args| args[4].should be :priority }.returns('foo_result')
19
+ scope.function_hiera(['key']).should == 'foo_result'
20
+ end
21
+ end
@@ -0,0 +1,79 @@
1
+ ENV['FOG_MOCK'] ||= 'true'
2
+ ENV['AUTOTEST'] = 'true'
3
+ ENV['WATCHR'] = '1'
4
+
5
+ system 'clear'
6
+
7
+ def growl(message)
8
+ growlnotify = `which growlnotify`.chomp
9
+ title = "Watchr Test Results"
10
+ image = case message
11
+ when /(\d+)\s+?(failure|error)/i
12
+ ($1.to_i == 0) ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png"
13
+ else
14
+ '~/.watchr_images/unknown.png'
15
+ end
16
+ options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
17
+ system %(#{growlnotify} #{options} &)
18
+ end
19
+
20
+ def run(cmd)
21
+ puts(cmd)
22
+ `#{cmd}`
23
+ end
24
+
25
+ def run_spec_test(file)
26
+ if File.exist? file
27
+ result = run "rspec --format p --color #{file}"
28
+ growl result.split("\n").last
29
+ puts result
30
+ else
31
+ puts "FIXME: No test #{file} [#{Time.now}]"
32
+ end
33
+ end
34
+
35
+ def filter_rspec(data)
36
+ data.split("\n").find_all do |l|
37
+ l =~ /^(\d+)\s+exampl\w+.*?(\d+).*?failur\w+.*?(\d+).*?pending/
38
+ end.join("\n")
39
+ end
40
+
41
+ def run_all_tests
42
+ system('clear')
43
+ files = Dir.glob("spec/**/*_spec.rb").join(" ")
44
+ result = run "rspec #{files}"
45
+ growl_results = filter_rspec result
46
+ growl growl_results
47
+ puts result
48
+ puts "GROWL: #{growl_results}"
49
+ end
50
+
51
+ # Ctrl-\
52
+ Signal.trap 'QUIT' do
53
+ puts " --- Running all tests ---\n\n"
54
+ run_all_tests
55
+ end
56
+
57
+ @interrupted = false
58
+
59
+ # Ctrl-C
60
+ Signal.trap 'INT' do
61
+ if @interrupted then
62
+ @wants_to_quit = true
63
+ abort("\n")
64
+ else
65
+ puts "Interrupt a second time to quit"
66
+ @interrupted = true
67
+ Kernel.sleep 1.5
68
+ # raise Interrupt, nil # let the run loop catch it
69
+ run_suite
70
+ end
71
+ end
72
+
73
+ watch( 'spec/.*_spec\.rb' ) do |md|
74
+ run_all_tests
75
+ end
76
+
77
+ watch( 'lib/.*\.rb' ) do |md|
78
+ run_all_tests
79
+ end
metadata CHANGED
@@ -1,13 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiera-puppet
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease:
4
+ hash: 2711208307
5
+ prerelease: 5
6
6
  segments:
7
+ - 1
7
8
  - 0
8
- - 3
9
9
  - 0
10
- version: 0.3.0
10
+ - rc
11
+ - 2
12
+ version: 1.0.0rc2
11
13
  platform: ruby
12
14
  authors:
13
15
  - Puppet Labs
@@ -15,7 +17,7 @@ autorequire:
15
17
  bindir: bin
16
18
  cert_chain: []
17
19
 
18
- date: 2012-01-12 00:00:00 Z
20
+ date: 2012-07-20 00:00:00 Z
19
21
  dependencies:
20
22
  - !ruby/object:Gem::Dependency
21
23
  name: hiera
@@ -25,12 +27,11 @@ dependencies:
25
27
  requirements:
26
28
  - - ~>
27
29
  - !ruby/object:Gem::Version
28
- hash: 19
30
+ hash: 15
29
31
  segments:
32
+ - 1
30
33
  - 0
31
- - 3
32
- - 0
33
- version: 0.3.0
34
+ version: "1.0"
34
35
  type: :runtime
35
36
  version_requirements: *id001
36
37
  description: Store and query Hiera data from Puppet
@@ -45,13 +46,21 @@ files:
45
46
  - bin/extlookup2hiera
46
47
  - lib/hiera/backend/puppet_backend.rb
47
48
  - lib/hiera/scope.rb
49
+ - lib/hiera_puppet.rb
48
50
  - lib/puppet/parser/functions/hiera.rb
49
51
  - lib/puppet/parser/functions/hiera_array.rb
50
52
  - lib/puppet/parser/functions/hiera_hash.rb
51
53
  - lib/puppet/parser/functions/hiera_include.rb
54
+ - spec/helpers.rb
52
55
  - spec/spec_helper.rb
53
- - spec/unit/puppet_backend_spec.rb
54
- - spec/unit/scope_spec.rb
56
+ - spec/unit/hiera/backend/puppet_backend_spec.rb
57
+ - spec/unit/hiera/scope_spec.rb
58
+ - spec/unit/hiera_puppet_spec.rb
59
+ - spec/unit/puppet/parser/functions/hiera_array_spec.rb
60
+ - spec/unit/puppet/parser/functions/hiera_hash_spec.rb
61
+ - spec/unit/puppet/parser/functions/hiera_include_spec.rb
62
+ - spec/unit/puppet/parser/functions/hiera_spec.rb
63
+ - spec/watchr.rb
55
64
  homepage: https://github.com/puppetlabs/hiera-puppet
56
65
  licenses: []
57
66
 
@@ -72,20 +81,29 @@ required_ruby_version: !ruby/object:Gem::Requirement
72
81
  required_rubygems_version: !ruby/object:Gem::Requirement
73
82
  none: false
74
83
  requirements:
75
- - - ">="
84
+ - - ">"
76
85
  - !ruby/object:Gem::Version
77
- hash: 3
86
+ hash: 25
78
87
  segments:
79
- - 0
80
- version: "0"
88
+ - 1
89
+ - 3
90
+ - 1
91
+ version: 1.3.1
81
92
  requirements: []
82
93
 
83
94
  rubyforge_project:
84
- rubygems_version: 1.8.10
95
+ rubygems_version: 1.8.24
85
96
  signing_key:
86
97
  specification_version: 3
87
98
  summary: Puppet query interface and backend for Hiera
88
99
  test_files:
100
+ - spec/helpers.rb
89
101
  - spec/spec_helper.rb
90
- - spec/unit/puppet_backend_spec.rb
91
- - spec/unit/scope_spec.rb
102
+ - spec/unit/hiera/backend/puppet_backend_spec.rb
103
+ - spec/unit/hiera/scope_spec.rb
104
+ - spec/unit/hiera_puppet_spec.rb
105
+ - spec/unit/puppet/parser/functions/hiera_array_spec.rb
106
+ - spec/unit/puppet/parser/functions/hiera_hash_spec.rb
107
+ - spec/unit/puppet/parser/functions/hiera_include_spec.rb
108
+ - spec/unit/puppet/parser/functions/hiera_spec.rb
109
+ - spec/watchr.rb
@@ -1,118 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- class Hiera
4
- module Backend
5
- describe Puppet_backend do
6
- before do
7
- Hiera.stubs(:warn)
8
- Hiera.stubs(:debug)
9
- Backend.stubs(:datasources).yields([])
10
- Puppet::Parser::Functions.stubs(:function).with(:include)
11
-
12
- @mockresource = mock
13
- @mockresource.stubs(:name).returns("ntp::config")
14
-
15
- @mockscope = mock
16
- @mockscope.stubs(:resource).returns(@mockresource)
17
-
18
- @scope = Scope.new(@mockscope)
19
-
20
- @backend = Puppet_backend.new
21
- end
22
-
23
- describe "#hierarchy" do
24
- it "should use the configured datasource" do
25
- Config.expects("[]").with(:puppet).returns({:datasource => "rspec"})
26
- Config.expects("[]").with(:hierarchy)
27
-
28
- ["ntp", "ntp::config"].each do |klass|
29
- Backend.expects(:parse_string).with(klass, @scope, {"calling_module" => "ntp", "calling_class" => "ntp::config"}).returns(klass)
30
- end
31
-
32
- @backend.hierarchy(@scope, nil).should == ["rspec::ntp::config", "rspec::ntp", "ntp::config::rspec", "ntp::rspec"]
33
- end
34
-
35
- it "should not include empty class names" do
36
- Config.expects("[]").with(:puppet).returns({:datasource => "rspec"})
37
- Config.expects("[]").with(:hierarchy).returns(["%{foo}", "common"])
38
-
39
- Backend.expects(:parse_string).with("common", @scope, {"calling_module" => "ntp", "calling_class" => "ntp::config"}).returns("common")
40
- Backend.expects(:parse_string).with("%{foo}", @scope, {"calling_module" => "ntp", "calling_class" => "ntp::config"}).returns("")
41
-
42
- @backend.hierarchy(@scope, nil).should == ["rspec::common", "ntp::config::rspec", "ntp::rspec"]
43
- end
44
-
45
- it "should allow for an override data source" do
46
- Config.expects("[]").with(:puppet).returns({:datasource => "rspec"})
47
- Config.expects("[]").with(:hierarchy)
48
-
49
- ["ntp", "ntp::config"].each do |klass|
50
- Backend.expects(:parse_string).with(klass, @scope, {"calling_module" => "ntp", "calling_class" => "ntp::config"}).returns(klass)
51
- end
52
-
53
- @backend.hierarchy(@scope, "override").should == ["rspec::override", "rspec::ntp::config", "rspec::ntp", "ntp::config::rspec", "ntp::rspec"]
54
- end
55
-
56
- describe "#lookup" do
57
- it "should attempt to load data from unincluded classes" do
58
- Backend.expects(:empty_answer).returns(nil)
59
- Backend.expects(:parse_answer).with("rspec", @scope).returns("rspec")
60
-
61
- catalog = mock
62
- catalog.expects(:classes).returns([])
63
-
64
- @scope.expects(:catalog).returns(catalog)
65
- @scope.expects(:function_include).with("rspec")
66
- @mockscope.expects(:lookupvar).with("rspec::key").returns("rspec")
67
-
68
- @backend.expects(:hierarchy).with(@scope, nil).returns(["rspec"])
69
- @backend.lookup("key", @scope, nil, nil).should == "rspec"
70
- end
71
-
72
- it "should not load loaded classes" do
73
- Backend.expects(:empty_answer).returns(nil)
74
- Backend.expects(:parse_answer).with("rspec", @scope).returns("rspec")
75
- catalog = mock
76
- catalog.expects(:classes).returns(["rspec"])
77
- @mockscope.expects(:catalog).returns(catalog)
78
- @mockscope.expects(:function_include).never
79
- @mockscope.expects(:lookupvar).with("rspec::key").returns("rspec")
80
-
81
- @backend.expects(:hierarchy).with(@scope, nil).returns(["rspec"])
82
- @backend.lookup("key", @scope, nil, nil).should == "rspec"
83
- end
84
-
85
- it "should return the first found data" do
86
- Backend.expects(:empty_answer).returns(nil)
87
- Backend.expects(:parse_answer).with("rspec", @scope).returns("rspec")
88
- catalog = mock
89
- catalog.expects(:classes).returns(["rspec", "override"])
90
- @mockscope.expects(:catalog).returns(catalog)
91
- @mockscope.expects(:function_include).never
92
- @mockscope.expects(:lookupvar).with("override::key").returns("rspec")
93
- @mockscope.expects(:lookupvar).with("rspec::key").never
94
-
95
- @backend.expects(:hierarchy).with(@scope, "override").returns(["override", "rspec"])
96
- @backend.lookup("key", @scope, "override", nil).should == "rspec"
97
- end
98
-
99
- it "should return an array of found data for array searches" do
100
- Backend.expects(:empty_answer).returns([])
101
- Backend.expects(:parse_answer).with("rspec::key", @scope).returns("rspec::key")
102
- Backend.expects(:parse_answer).with("test::key", @scope).returns("test::key")
103
- catalog = mock
104
- catalog.expects(:classes).returns(["rspec", "test"])
105
- @mockscope.expects(:catalog).returns(catalog)
106
- @mockscope.expects(:function_include).never
107
- @mockscope.expects(:lookupvar).with("rspec::key").returns("rspec::key")
108
- @mockscope.expects(:lookupvar).with("test::key").returns("test::key")
109
-
110
- @backend.expects(:hierarchy).with(@scope, nil).returns(["rspec", "test"])
111
- @backend.lookup("key", @scope, nil, :array).should == ["rspec::key", "test::key"]
112
- end
113
- end
114
- end
115
- end
116
- end
117
- end
118
-
@@ -1,64 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- class Hiera
4
- describe Scope do
5
- describe "#initialize" do
6
- it "should store the supplied puppet scope" do
7
- real = {}
8
- scope = Scope.new(real)
9
- scope.real.should == real
10
- end
11
- end
12
-
13
- describe "#[]" do
14
- it "should treat '' as nil" do
15
- real = mock
16
- real.expects(:lookupvar).with("foo").returns("")
17
-
18
- scope = Scope.new(real)
19
- scope["foo"].should == nil
20
- end
21
-
22
- it "sould return found data" do
23
- real = mock
24
- real.expects(:lookupvar).with("foo").returns("bar")
25
-
26
- scope = Scope.new(real)
27
- scope["foo"].should == "bar"
28
- end
29
-
30
- it "should get calling_class and calling_module from puppet scope" do
31
- real = mock
32
- resource = mock
33
- resource.expects(:name).returns("Foo::Bar").twice
34
-
35
- real.expects(:resource).returns(resource).twice
36
-
37
- scope = Scope.new(real)
38
- scope["calling_class"].should == "foo::bar"
39
- scope["calling_module"].should == "foo"
40
- end
41
- end
42
-
43
- describe "#include?" do
44
- it "should correctly report missing data" do
45
- real = mock
46
- real.expects(:lookupvar).with("foo").returns("")
47
-
48
- scope = Scope.new(real)
49
- scope.include?("foo").should == false
50
- end
51
-
52
- it "should always return true for calling_class and calling_module" do
53
- real = mock
54
- real.expects(:lookupvar).with("calling_class").never
55
- real.expects(:lookupvar).with("calling_module").never
56
-
57
- scope = Scope.new(real)
58
- scope.include?("calling_class").should == true
59
- scope.include?("calling_module").should == true
60
- end
61
- end
62
- end
63
- end
64
-