diff options
Diffstat (limited to 'spec/unit/knife/bootstrap/train_connector_spec.rb')
-rw-r--r-- | spec/unit/knife/bootstrap/train_connector_spec.rb | 81 |
1 files changed, 71 insertions, 10 deletions
diff --git a/spec/unit/knife/bootstrap/train_connector_spec.rb b/spec/unit/knife/bootstrap/train_connector_spec.rb index 08bf21dd42..385a192648 100644 --- a/spec/unit/knife/bootstrap/train_connector_spec.rb +++ b/spec/unit/knife/bootstrap/train_connector_spec.rb @@ -25,20 +25,26 @@ describe Chef::Knife::Bootstrap::TrainConnector do let(:release) { "unknown" } # version let(:name) { "unknown" } let(:arch) { "x86_64" } + let(:connection_opts) { {} } # connection opts let(:host_url) { "mock://user1@example.com" } - let(:opts) { {} } + let(:mock_connection) { true } + subject do - # Create a valid TargetHost with the backend stubbed out. - Chef::Knife::Bootstrap::TrainConnector.test_instance(host_url, - protocol: protocol, - family: family, - name: name, - release: release, - arch: arch, - opts: opts) + # Example groups can still override by setting explicitly it in 'connection_opts' + tc = Chef::Knife::Bootstrap::TrainConnector.new(host_url, protocol, connection_opts) + tc end - context "connect!" do + before(:each) do + if mock_connection + subject.connect! + subject.connection.mock_os( + family: family, + name: name, + release: release, + arch: arch + ) + end end describe "platform helpers" do @@ -78,6 +84,61 @@ describe Chef::Knife::Bootstrap::TrainConnector do end end + describe "#initialize" do + let(:mock_connection) { false } + + context "when provided target is a proper URL" do + let(:protocol) { "ssh" } + let(:host_url) { "mock://user1@localhost:2200" } + it "correctly configures the instance from the URL" do + expect(subject.config[:backend]).to eq "mock" + expect(subject.config[:port]).to eq 2200 + expect(subject.config[:host]).to eq "localhost" + expect(subject.config[:user]).to eq "user1" + end + + context "and conflicting options are given" do + let(:connection_opts) { { user: "user2", host: "example.com", port: 15 } } + it "resolves them from the URI" do + expect(subject.config[:backend]).to eq "mock" + expect(subject.config[:port]).to eq 2200 + expect(subject.config[:host]).to eq "localhost" + expect(subject.config[:user]).to eq "user1" + end + end + end + + context "when provided target is just a hostname" do + let(:host_url) { "localhost" } + let(:protocol) { "mock" } + it "correctly sets backend protocol from the default" do + expect(subject.config[:backend]).to eq "mock" + end + + context "and options have been provided that are supported by the transport" do + let(:protocol) { "ssh" } + let(:connection_opts) { { port: 15, user: "user2" } } + + it "sets hostname and transport from arguments and provided fields from options" do + expect(subject.config[:backend]).to eq "ssh" + expect(subject.config[:host]).to eq "localhost" + expect(subject.config[:user]).to eq "user2" + expect(subject.config[:port]).to eq 15 + end + + end + + end + + context "when provided target is just a an IP address" do + let(:host_url) { "127.0.0.1" } + let(:protocol) { "mock" } + it "correctly sets backend protocol from the default" do + expect(subject.config[:backend]).to eq "mock" + end + end + end + describe "#temp_dir" do context "under windows" do let(:family) { "windows" } |