File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
spec/octocatalog-diff/tests Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,15 @@ def dup
41
41
self . class . new ( @options , @orig_facts )
42
42
end
43
43
44
+ # Node - get the node name, either as set explicitly or as determined from the facts themselves.
45
+ # @return [String] Node name, explicit or guessed
46
+ def node
47
+ return @node unless @node . nil? || @node . empty?
48
+ return facts [ 'name' ] if facts . key? ( 'name' )
49
+ return facts [ 'values' ] [ 'fqdn' ] if facts . key? ( 'values' ) && facts [ 'values' ] . key? ( 'fqdn' )
50
+ ''
51
+ end
52
+
44
53
# Facts - returned the 'cleansed' facts.
45
54
# Clean up facts by setting 'name' to the node if given, and deleting _timestamp and expiration
46
55
# which may cause Puppet catalog compilation to fail if the facts are old.
Original file line number Diff line number Diff line change 80
80
end
81
81
end
82
82
83
+ describe '#node' do
84
+ let ( :opts ) { { backend : :yaml , fact_file_string : File . read ( OctocatalogDiff ::Spec . fixture_path ( 'facts/facts.yaml' ) ) } }
85
+
86
+ it 'should return the node if set explicitly' do
87
+ obj = OctocatalogDiff ::Facts . new ( opts . merge ( node : 'fluffy-kittens.example.com' ) )
88
+ expect ( obj . node ) . to eq ( 'fluffy-kittens.example.com' )
89
+ end
90
+
91
+ it 'should return the node from the facts name in the fact file' do
92
+ obj = OctocatalogDiff ::Facts . new ( opts )
93
+ expect ( obj . node ) . to eq ( 'rspec-node.xyz.github.net' )
94
+ end
95
+
96
+ it 'should return the FQDN' do
97
+ obj = OctocatalogDiff ::Facts . new ( opts )
98
+ allow ( obj ) . to receive ( :facts ) . and_return ( 'values' => { 'fqdn' => 'foobar.example.com' } )
99
+ expect ( obj . node ) . to eq ( 'foobar.example.com' )
100
+ end
101
+
102
+ it 'should return empty if all else fails' do
103
+ obj = OctocatalogDiff ::Facts . new ( opts )
104
+ allow ( obj ) . to receive ( :facts ) . and_return ( { } )
105
+ expect ( obj . node ) . to eq ( '' )
106
+ end
107
+ end
108
+
83
109
context 'test individual methods' do
84
110
before ( :all ) do
85
111
opts = {
You can’t perform that action at this time.
0 commit comments