File tree Expand file tree Collapse file tree
spec/octocatalog-diff/tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -41,6 +41,15 @@ def dup
4141 self . class . new ( @options , @orig_facts )
4242 end
4343
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+
4453 # Facts - returned the 'cleansed' facts.
4554 # Clean up facts by setting 'name' to the node if given, and deleting _timestamp and expiration
4655 # which may cause Puppet catalog compilation to fail if the facts are old.
Original file line number Diff line number Diff line change 8080 end
8181 end
8282
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+
83109 context 'test individual methods' do
84110 before ( :all ) do
85111 opts = {
You can’t perform that action at this time.
0 commit comments