diff options
author | Tim Smith <tsmith@chef.io> | 2019-08-07 16:09:52 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-07 16:09:52 -0700 |
commit | 1029cd105060359853d4ec6f7810effd8b242fbf (patch) | |
tree | 022423aaeaba60021a5d73b4214086929d9d2ade /spec/unit/knife | |
parent | e0ef72885027ee44eb5025c82ded084315b5df27 (diff) | |
parent | 104f68b71ba523b7fa4e8a6c28a45449a2a67751 (diff) | |
download | chef-1029cd105060359853d4ec6f7810effd8b242fbf.tar.gz |
Merge pull request #8795 from MsysTechnologiesllc/VSingh/temp-dir-using-mkdir-instead-of-mktemp
Chef-15: Make temp dir using mkdir instead of mktemp
Diffstat (limited to 'spec/unit/knife')
-rw-r--r-- | spec/unit/knife/bootstrap/train_connector_spec.rb | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/spec/unit/knife/bootstrap/train_connector_spec.rb b/spec/unit/knife/bootstrap/train_connector_spec.rb index 52345f3cde..a2b7a571b0 100644 --- a/spec/unit/knife/bootstrap/train_connector_spec.rb +++ b/spec/unit/knife/bootstrap/train_connector_spec.rb @@ -155,21 +155,26 @@ describe Chef::Knife::Bootstrap::TrainConnector do context "under linux and unix-like" do let(:family) { "debian" } let(:name) { "ubuntu" } + let(:random) { "wScHX6" } + let(:dir) { "/tmp/chef_#{random}" } + + before do + allow(SecureRandom).to receive(:alphanumeric).with(6).and_return(random) + end + it "uses the *nix command to create the temp dir and sets ownership to logged-in user" do - expected_command = Chef::Knife::Bootstrap::TrainConnector::MKTEMP_NIX_COMMAND + expected_command = "mkdir -p #{dir} && sudo chown user1 '#{dir}'" expect(subject).to receive(:run_command!).with(expected_command) - .and_return double("result", stdout: "/a/path") - expect(subject).to receive(:run_command!).with("chown user1 '/a/path'") - expect(subject.temp_dir).to eq "/a/path" + .and_return double("result", stdout: "\r\n") + expect(subject.temp_dir).to eq(dir) end context "with noise in stderr" do it "uses the *nix command to create the temp dir and sets ownership to logged-in user" do - expected_command = Chef::Knife::Bootstrap::TrainConnector::MKTEMP_NIX_COMMAND + expected_command = "mkdir -p #{dir} && sudo chown user1 '#{dir}'" expect(subject).to receive(:run_command!).with(expected_command) - .and_return double("result", stdout: "sudo: unable to resolve host hostname.localhost\r\n" + "/a/path\r\n") - expect(subject).to receive(:run_command!).with("chown user1 '/a/path'") - expect(subject.temp_dir).to eq "/a/path" + .and_return double("result", stdout: "sudo: unable to resolve host hostname.localhost\r\n" + "#{dir}\r\n") + expect(subject.temp_dir).to eq(dir) end end end |