spec/unit/nodes_spec.rb in kitchen-nodes-0.4.1 vs spec/unit/nodes_spec.rb in kitchen-nodes-0.5.0

- old
+ new

@@ -25,21 +25,26 @@ platform: platform, transport: transport, driver: Kitchen::Driver::Dummy.new ) end - let(:transport) { Kitchen::Transport::Dummy.new } + let(:transport) { Kitchen::Transport::Ssh.new } let(:platform) { double('platform', os_type: nil, name: 'ubuntu') } let(:suite) { double('suite', name: 'suite') } let(:state) { { hostname: '192.168.1.10' } } let(:node) { JSON.parse(File.read(subject.node_file), symbolize_names: true) } before do FakeFS.activate! FileUtils.mkdir_p(config[:test_base_path]) allow_any_instance_of(Kitchen::StateFile) .to receive(:read).and_return(state) + allow(transport).to receive(:connection) + .and_return(Kitchen::Transport::Base::Connection.new) + allow_any_instance_of(Kitchen::Transport::Base::Connection) + .to receive(:node_execute).with('hostname -f') + .and_return('fakehostname') end after do FakeFS.deactivate! FakeFS::FileSystem.clear end @@ -80,10 +85,29 @@ subject.create_node expect(node[:automatic][:ipaddress]).to eq state[:hostname] end + it 'sets the fqdn' do + subject.create_node + + expect(node[:automatic][:fqdn]).to eq 'fakehostname' + end + + context 'cannot obtain fqdn' do + before do + allow_any_instance_of(Kitchen::Transport::Base::Connection) + .to receive(:node_execute).with('hostname -f') + .and_raise(Kitchen::Transport::TransportFailed.new('')) + end + + it 'sets the fqdn to nil' do + subject.create_node + expect(node[:automatic][:fqdn]).to be_nil + end + end + context 'no environment explicitly set' do before { config.delete(:client_rb) } it 'sets the environment' do subject.create_node @@ -97,11 +121,9 @@ let(:machine_ips) { ['192.168.1.1', '192.168.1.2', '192.168.1.3'] } before do allow_any_instance_of(Net::Ping::External).to receive(:ping) .and_return(true) - allow(transport).to receive(:connection) - .and_return(Kitchen::Transport::Base::Connection.new) end context 'cannot find an ip' do let(:ifconfig_response) do FakeFS.deactivate!