hiera 1.3.0 → 1.3.1.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of hiera might be problematic. Click here for more details.

@@ -17,10 +17,10 @@ class Hiera
17
17
  Hiera.debug("Looking for data source #{source}")
18
18
  yamlfile = Backend.datafile(:yaml, scope, source, "yaml") || next
19
19
 
20
- next unless File.exist?(yamlfile)
20
+ next unless file_exists?(yamlfile)
21
21
 
22
22
  data = @cache.read_file(yamlfile, Hash) do |data|
23
- YAML.load(data)
23
+ YAML.load(data) || {}
24
24
  end
25
25
 
26
26
  next if data.empty?
@@ -55,6 +55,12 @@ class Hiera
55
55
 
56
56
  return answer
57
57
  end
58
+
59
+ private
60
+
61
+ def file_exists?(path)
62
+ File.exist? path
63
+ end
58
64
  end
59
65
  end
60
66
  end
@@ -7,7 +7,7 @@
7
7
 
8
8
 
9
9
  class Hiera
10
- VERSION = "1.3.0"
10
+ VERSION = "1.3.1-rc1"
11
11
 
12
12
  ##
13
13
  # version is a public API method intended to always provide a fast and
@@ -3,12 +3,29 @@ require 'hiera/backend/yaml_backend'
3
3
 
4
4
  class Hiera
5
5
  module Backend
6
+ class FakeCache
7
+ attr_accessor :value
8
+ def read(path, expected_type, default, &block)
9
+ read_file(path, expected_type, &block)
10
+ rescue => e
11
+ default
12
+ end
13
+
14
+ def read_file(path, expected_type, &block)
15
+ output = block.call(@value)
16
+ if !output.is_a? expected_type
17
+ raise TypeError
18
+ end
19
+ output
20
+ end
21
+ end
22
+
6
23
  describe Yaml_backend do
7
24
  before do
8
25
  Config.load({})
9
26
  Hiera.stubs(:debug)
10
27
  Hiera.stubs(:warn)
11
- @cache = mock
28
+ @cache = FakeCache.new
12
29
  @backend = Yaml_backend.new(@cache)
13
30
  end
14
31
 
@@ -32,8 +49,9 @@ class Hiera
32
49
  Backend.expects(:datasources).multiple_yields(["one"], ["two"])
33
50
  Backend.expects(:datafile).with(:yaml, {}, "one", "yaml").returns("/nonexisting/one.yaml")
34
51
  Backend.expects(:datafile).with(:yaml, {}, "two", "yaml").returns(nil).never
35
- @cache.expects(:read_file).with("/nonexisting/one.yaml", Hash).returns({"key"=>"answer"})
36
- File.stubs(:exist?).with("/nonexisting/one.yaml").returns(true)
52
+
53
+ @backend.stubs(:file_exists?).with("/nonexisting/one.yaml").returns(true)
54
+ @cache.value = "---\nkey: answer"
37
55
 
38
56
  @backend.lookup("key", {}, nil, :priority).should == "answer"
39
57
  end
@@ -46,13 +64,27 @@ class Hiera
46
64
  @backend.lookup("key", {}, nil, :priority)
47
65
  end
48
66
 
49
- it "should return nil for empty data files" do
50
- Backend.expects(:datasources).multiple_yields(["one"])
51
- Backend.expects(:datafile).with(:yaml, {}, "one", "yaml").returns("/nonexisting/one.yaml")
52
- File.stubs(:exist?).with("/nonexisting/one.yaml").returns(true)
53
- @cache.expects(:read_file).with("/nonexisting/one.yaml", Hash).returns({})
54
-
55
- @backend.lookup("key", {}, nil, :priority).should be_nil
67
+ describe "handling unexpected YAML values" do
68
+ before do
69
+ Backend.expects(:datasources).multiple_yields(["one"])
70
+ Backend.expects(:datafile).with(:yaml, {}, "one", "yaml").returns("/nonexisting/one.yaml")
71
+ @backend.stubs(:file_exists?).with("/nonexisting/one.yaml").returns(true)
72
+ end
73
+
74
+ it "returns nil when the YAML value is nil" do
75
+ @cache.value = "---\n"
76
+ @backend.lookup("key", {}, nil, :priority).should be_nil
77
+ end
78
+
79
+ it "returns nil when the YAML file is false" do
80
+ @cache.value = ""
81
+ @backend.lookup("key", {}, nil, :priority).should be_nil
82
+ end
83
+
84
+ it "raises a TypeError when the YAML value is not a hash" do
85
+ @cache.value = "---\n[one, two, three]"
86
+ expect { @backend.lookup("key", {}, nil, :priority) }.to raise_error(TypeError)
87
+ end
56
88
  end
57
89
 
58
90
  it "should build an array of all data sources for array searches" do
@@ -135,9 +167,8 @@ class Hiera
135
167
  Backend.expects(:datafile).with(:yaml, {}, "one", "yaml").returns("/nonexisting/one.yaml").times(3)
136
168
  File.stubs(:exist?).with("/nonexisting/one.yaml").returns(true)
137
169
 
138
- yaml = "---\nstringval: 'string'\nboolval: true\nnumericval: 1"
139
170
 
140
- @cache.expects(:read_file).with("/nonexisting/one.yaml", Hash).times(3).returns({"boolval"=>true, "numericval"=>1, "stringval"=>"string"})
171
+ @cache.value = "---\nstringval: 'string'\nboolval: true\nnumericval: 1"
141
172
 
142
173
  @backend.lookup("stringval", {}, nil, :priority).should == "string"
143
174
  @backend.lookup("boolval", {}, nil, :priority).should == true
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiera
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
5
- prerelease:
4
+ version: 1.3.1.rc1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Puppet Labs
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-21 00:00:00.000000000 Z
12
+ date: 2013-12-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json_pure
@@ -35,35 +35,35 @@ extensions: []
35
35
  extra_rdoc_files: []
36
36
  files:
37
37
  - bin/hiera
38
- - lib/hiera/puppet_logger.rb
38
+ - lib/hiera.rb
39
39
  - lib/hiera/console_logger.rb
40
+ - lib/hiera/noop_logger.rb
41
+ - lib/hiera/backend/yaml_backend.rb
42
+ - lib/hiera/backend/json_backend.rb
43
+ - lib/hiera/fallback_logger.rb
40
44
  - lib/hiera/filecache.rb
41
45
  - lib/hiera/version.rb
42
- - lib/hiera/fallback_logger.rb
43
- - lib/hiera/error.rb
46
+ - lib/hiera/config.rb
44
47
  - lib/hiera/interpolate.rb
45
- - lib/hiera/util.rb
46
48
  - lib/hiera/recursive_guard.rb
49
+ - lib/hiera/util.rb
47
50
  - lib/hiera/backend.rb
48
- - lib/hiera/noop_logger.rb
49
- - lib/hiera/config.rb
50
- - lib/hiera/backend/yaml_backend.rb
51
- - lib/hiera/backend/json_backend.rb
52
- - lib/hiera.rb
51
+ - lib/hiera/puppet_logger.rb
52
+ - lib/hiera/error.rb
53
53
  - COPYING
54
54
  - README.md
55
55
  - LICENSE
56
- - spec/unit/util_spec.rb
57
- - spec/unit/puppet_logger_spec.rb
58
- - spec/unit/version_spec.rb
59
- - spec/unit/config_spec.rb
60
- - spec/unit/backend_spec.rb
61
- - spec/unit/filecache_spec.rb
62
56
  - spec/unit/hiera_spec.rb
63
- - spec/unit/console_logger_spec.rb
57
+ - spec/unit/filecache_spec.rb
64
58
  - spec/unit/backend/yaml_backend_spec.rb
65
59
  - spec/unit/backend/json_backend_spec.rb
60
+ - spec/unit/console_logger_spec.rb
61
+ - spec/unit/backend_spec.rb
62
+ - spec/unit/version_spec.rb
63
+ - spec/unit/puppet_logger_spec.rb
64
+ - spec/unit/config_spec.rb
66
65
  - spec/unit/fallback_logger_spec.rb
66
+ - spec/unit/util_spec.rb
67
67
  - spec/spec_helper.rb
68
68
  homepage: https://github.com/puppetlabs/hiera
69
69
  licenses: []
@@ -80,9 +80,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
80
  required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
83
- - - ! '>='
83
+ - - ! '>'
84
84
  - !ruby/object:Gem::Version
85
- version: '0'
85
+ version: 1.3.1
86
86
  requirements: []
87
87
  rubyforge_project:
88
88
  rubygems_version: 1.8.23
@@ -90,15 +90,15 @@ signing_key:
90
90
  specification_version: 3
91
91
  summary: Light weight hierarchical data store
92
92
  test_files:
93
- - spec/unit/util_spec.rb
94
- - spec/unit/puppet_logger_spec.rb
95
- - spec/unit/version_spec.rb
96
- - spec/unit/config_spec.rb
97
- - spec/unit/backend_spec.rb
98
- - spec/unit/filecache_spec.rb
99
93
  - spec/unit/hiera_spec.rb
100
- - spec/unit/console_logger_spec.rb
94
+ - spec/unit/filecache_spec.rb
101
95
  - spec/unit/backend/yaml_backend_spec.rb
102
96
  - spec/unit/backend/json_backend_spec.rb
97
+ - spec/unit/console_logger_spec.rb
98
+ - spec/unit/backend_spec.rb
99
+ - spec/unit/version_spec.rb
100
+ - spec/unit/puppet_logger_spec.rb
101
+ - spec/unit/config_spec.rb
103
102
  - spec/unit/fallback_logger_spec.rb
103
+ - spec/unit/util_spec.rb
104
104
  - spec/spec_helper.rb