diff options
author | Marc A. Paradise <marc.paradise@gmail.com> | 2019-04-30 15:55:04 -0400 |
---|---|---|
committer | Marc A. Paradise <marc.paradise@gmail.com> | 2019-05-02 12:44:32 -0400 |
commit | b4668dc854258ea65f2bbf71a31e19210d01ad95 (patch) | |
tree | 7532484d16c1fb9e74c50620ba51bbe8936627b9 /spec | |
parent | e177c05fb6f0e3d0bd4fb0d905842ef71e508614 (diff) | |
download | chef-b4668dc854258ea65f2bbf71a31e19210d01ad95.tar.gz |
Ensure that requested protocol is available and correct
There are a few related changes here:
* ensure that we always have the requested protocol, and
use the default when we can't otherwise resolve it. This corrects
the first part of CHEF-8432
* This also finishes the work started in a previous branch
that moves the config handling out of TrainConnector::initialize
and into a lazy loader for config.
* Ensure that the baseline configuration contains only things
that will not be picked up when merging user-provided config. This
meant moving :non_interactive out to the caller (bootstrap).
* Removed helpers that weren't helping much.
Signed-off-by: Marc A. Paradise <marc.paradise@gmail.com>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/knife/bootstrap/train_connector_spec.rb | 84 |
1 files changed, 70 insertions, 14 deletions
diff --git a/spec/unit/knife/bootstrap/train_connector_spec.rb b/spec/unit/knife/bootstrap/train_connector_spec.rb index c976a805ee..385a192648 100644 --- a/spec/unit/knife/bootstrap/train_connector_spec.rb +++ b/spec/unit/knife/bootstrap/train_connector_spec.rb @@ -20,28 +20,33 @@ require "ostruct" require "chef/knife/bootstrap/train_connector" describe Chef::Knife::Bootstrap::TrainConnector do - let(:transport) { "mock" } + let(:protocol) { "mock" } let(:family) { "unknown" } 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 - # Specifying sudo: false ensures that attempted operations - # don't fail because the mock platform doesn't support sudo. - # Example groups can still override by setting explicitly it in 'opts' - tc = Chef::Knife::Bootstrap::TrainConnector.new(host_url, transport, { sudo: false }.merge(opts)) - tc.connect! - tc.connection.mock_os( - family: family, - name: name, - release: release, - arch: arch - ) + # 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 + 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 context "on linux" do let(:family) { "debian" } @@ -79,8 +84,59 @@ describe Chef::Knife::Bootstrap::TrainConnector do end end - describe "::new" do + 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 |