forked from puppetlabs/puppet
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(PUP-1952) Fix hiera and lookup specs
Instead of trying to reload these files on every test from a different temporary directory, which was not working due to caching in jruby, just load once from a fixture.
- Loading branch information
Showing
5 changed files
with
74 additions
and
104 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
spec/fixtures/unit/functions/hiera/hiera/backend/hieraspec_backend.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class Hiera::Backend::Hieraspec_backend | ||
def initialize(cache = nil) | ||
Hiera.debug('Custom_backend starting') | ||
end | ||
|
||
def lookup(key, scope, order_override, resolution_type, context) | ||
case key | ||
when 'datasources' | ||
Hiera::Backend.datasources(scope, order_override) { |source| source } | ||
when 'resolution_type' | ||
if resolution_type == :hash | ||
{ key => resolution_type.to_s } | ||
elsif resolution_type == :array | ||
[ key, resolution_type.to_s ] | ||
else | ||
"resolution_type=#{resolution_type}" | ||
end | ||
else | ||
throw :no_such_key | ||
end | ||
end | ||
end |
18 changes: 18 additions & 0 deletions
18
spec/fixtures/unit/functions/lookup/hiera/backend/custom_backend.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class Hiera::Backend::Custom_backend | ||
def lookup(key, scope, order_override, resolution_type, context) | ||
case key | ||
when 'hash_c' | ||
{ 'hash_ca' => { 'cad' => 'value hash_c.hash_ca.cad (from global custom)' }} | ||
when 'hash' | ||
{ 'array' => [ 'x5,x6' ] } | ||
when 'array' | ||
[ 'x5,x6' ] | ||
when 'datasources' | ||
Hiera::Backend.datasources(scope, order_override) { |source| source } | ||
when 'dotted.key' | ||
'custom backend received request for dotted.key value' | ||
else | ||
throw :no_such_key | ||
end | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
spec/fixtures/unit/functions/lookup/hiera/backend/other_backend.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Hiera::Backend::Other_backend | ||
def lookup(key, scope, order_override, resolution_type, context) | ||
value = Hiera::Config[:other][key.to_sym] | ||
throw :no_such_key if value.nil? | ||
value | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters