diff options
-rw-r--r-- | lib/chef/knife/bootstrap/train_connector.rb | 21 | ||||
-rw-r--r-- | spec/unit/knife/bootstrap/train_connector_spec.rb | 29 |
2 files changed, 17 insertions, 33 deletions
diff --git a/lib/chef/knife/bootstrap/train_connector.rb b/lib/chef/knife/bootstrap/train_connector.rb index 5230d6638c..429874dc07 100644 --- a/lib/chef/knife/bootstrap/train_connector.rb +++ b/lib/chef/knife/bootstrap/train_connector.rb @@ -44,27 +44,6 @@ class Chef @config = transport_config(host_url, opts.merge(uri_opts)) end - # Because creating a valid train connection for testing is a two-step process in which - # we need to connect before mocking config, - # we expose test_instance as a way for tests to create actual instances - # but ensure that they don't connect to any back end. - def self.test_instance(url, protocol: "ssh", - family: "unknown", name: "unknown", - release: "unknown", arch: "x86_64", - opts: {}) - # Specifying sudo: false ensures that attempted operations - # don't fail because the mock platform doesn't support sudo - tc = TrainConnector.new(url, protocol, { sudo: false }.merge(opts)) - tc.connect! - tc.connection.mock_os( - family: family, - name: name, - release: release, - arch: arch - ) - tc - end - def connect! # Force connection to establish connection.wait_until_ready diff --git a/spec/unit/knife/bootstrap/train_connector_spec.rb b/spec/unit/knife/bootstrap/train_connector_spec.rb index 08bf21dd42..c976a805ee 100644 --- a/spec/unit/knife/bootstrap/train_connector_spec.rb +++ b/spec/unit/knife/bootstrap/train_connector_spec.rb @@ -20,7 +20,7 @@ require "ostruct" require "chef/knife/bootstrap/train_connector" describe Chef::Knife::Bootstrap::TrainConnector do - let(:protocol) { "mock" } + let(:transport) { "mock" } let(:family) { "unknown" } let(:release) { "unknown" } # version let(:name) { "unknown" } @@ -28,17 +28,18 @@ describe Chef::Knife::Bootstrap::TrainConnector do let(:host_url) { "mock://user1@example.com" } let(:opts) { {} } 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) - end - - context "connect!" 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 + ) + tc end describe "platform helpers" do @@ -78,6 +79,10 @@ describe Chef::Knife::Bootstrap::TrainConnector do end end + describe "::new" do + + end + describe "#temp_dir" do context "under windows" do let(:family) { "windows" } |