summaryrefslogtreecommitdiff
path: root/spec/functional/knife
diff options
context:
space:
mode:
authorMal Graty <mal.graty@googlemail.com>2017-11-28 11:22:40 +0000
committerMal Graty <mal.graty@googlemail.com>2017-11-28 11:37:22 +0000
commite01022409857d219d9e40438c900531ef433d622 (patch)
tree317abb2b76194243e376091ea8d4fb2d96f3a7c5 /spec/functional/knife
parentedd8a50fed5899129dff538be0e92f125c5c12fd (diff)
downloadchef-e01022409857d219d9e40438c900531ef433d622.tar.gz
Add custom prefix attribute support to knife ssh
Signed-off-by: Mal Graty <mal.graty@googlemail.com>
Diffstat (limited to 'spec/functional/knife')
-rw-r--r--spec/functional/knife/ssh_spec.rb47
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/functional/knife/ssh_spec.rb b/spec/functional/knife/ssh_spec.rb
index 3872d34322..3defbe781f 100644
--- a/spec/functional/knife/ssh_spec.rb
+++ b/spec/functional/knife/ssh_spec.rb
@@ -219,6 +219,53 @@ describe Chef::Knife::Ssh do
end
end
+ describe "prefix" do
+ context "when knife[:prefix_attribute] is set" do
+ before do
+ setup_knife(["*:*", "uptime"])
+ Chef::Config[:knife][:prefix_attribute] = "name"
+ end
+
+ it "uses the prefix_attribute" do
+ @knife.run
+ expect(@knife.get_prefix_attribute({ "prefix" => "name" })).to eq("name")
+ end
+ end
+
+ context "when knife[:prefix_attribute] is not provided" do
+ before do
+ setup_knife(["*:*", "uptime"])
+ Chef::Config[:knife][:prefix_attribute] = nil
+ end
+
+ it "falls back to nil" do
+ @knife.run
+ expect(@knife.get_prefix_attribute({})).to eq(nil)
+ end
+ end
+
+ context "when --prefix-attribute ec2.public_public_hostname is provided" do
+ before do
+ setup_knife(["--prefix-attribute", "ec2.public_hostname", "*:*", "uptime"])
+ Chef::Config[:knife][:prefix_attribute] = nil
+ end
+
+ it "should use the value on the command line" do
+ @knife.run
+ expect(@knife.config[:prefix_attribute]).to eq("ec2.public_hostname")
+ end
+
+ it "should override what is set in knife.rb" do
+ # This is the setting imported from knife.rb
+ Chef::Config[:knife][:prefix_attribute] = "fqdn"
+ # Then we run knife with the -b flag, which sets the above variable
+ setup_knife(["--prefix-attribute", "ec2.public_hostname", "*:*", "uptime"])
+ @knife.run
+ expect(@knife.config[:prefix_attribute]).to eq("ec2.public_hostname")
+ end
+ end
+ end
+
describe "gateway" do
context "when knife[:ssh_gateway] is set" do
before do