2014-01-17 02:03:38 +00:00
|
|
|
require_relative "../../../../base"
|
|
|
|
|
|
|
|
require Vagrant.source_root.join("plugins/provisioners/chef/provisioner/base")
|
|
|
|
|
|
|
|
describe VagrantPlugins::Chef::Provisioner::Base do
|
|
|
|
include_context "unit"
|
|
|
|
|
2015-11-19 19:25:34 +00:00
|
|
|
let(:iso_env) do
|
|
|
|
# We have to create a Vagrantfile so there is a root path
|
|
|
|
env = isolated_environment
|
|
|
|
env.vagrantfile("")
|
|
|
|
env.create_vagrant_env
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:machine) { iso_env.machine(iso_env.machine_names[0], :dummy) }
|
2014-01-17 02:03:38 +00:00
|
|
|
let(:config) { double("config") }
|
|
|
|
|
|
|
|
subject { described_class.new(machine, config) }
|
|
|
|
|
2015-11-19 19:25:34 +00:00
|
|
|
before do
|
|
|
|
allow(config).to receive(:node_name)
|
|
|
|
allow(config).to receive(:node_name=)
|
|
|
|
end
|
|
|
|
|
2016-03-18 01:15:11 +00:00
|
|
|
describe "#node_name" do
|
|
|
|
let(:env) { double("env") }
|
|
|
|
let(:root_path) { "/my/root" }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(machine).to receive(:env).and_return(env)
|
|
|
|
allow(env).to receive(:root_path).and_return(root_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "defaults to node_name if given" do
|
|
|
|
config = OpenStruct.new(node_name: "name")
|
|
|
|
instance = described_class.new(machine, config)
|
|
|
|
expect(instance.config.node_name).to eq("name")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "defaults to hostname if given" do
|
|
|
|
machine.config.vm.hostname = "by.hostname"
|
|
|
|
instance = described_class.new(machine, OpenStruct.new)
|
|
|
|
expect(instance.config.node_name).to eq("by.hostname")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "generates a random name if no hostname or node_name is given" do
|
|
|
|
config = OpenStruct.new(node_name: nil)
|
|
|
|
machine.config.vm.hostname = nil
|
|
|
|
instance = described_class.new(machine, OpenStruct.new)
|
|
|
|
expect(instance.config.node_name).to match(/vagrant\-.+/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-01-17 02:03:38 +00:00
|
|
|
describe "#encrypted_data_bag_secret_key_path" do
|
|
|
|
let(:env) { double("env") }
|
|
|
|
let(:root_path) { "/my/root" }
|
|
|
|
|
|
|
|
before do
|
2014-03-14 15:02:07 +00:00
|
|
|
allow(machine).to receive(:env).and_return(env)
|
|
|
|
allow(env).to receive(:root_path).and_return(root_path)
|
2014-01-17 02:03:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns absolute path as is" do
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(config).to receive(:encrypted_data_bag_secret_key_path).
|
2014-01-17 02:03:38 +00:00
|
|
|
and_return("/foo/bar")
|
|
|
|
expect(subject.encrypted_data_bag_secret_key_path).to eq "/foo/bar"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns relative path joined to root_path" do
|
2014-03-14 15:02:07 +00:00
|
|
|
expect(config).to receive(:encrypted_data_bag_secret_key_path).
|
2014-01-17 02:03:38 +00:00
|
|
|
and_return("secret")
|
|
|
|
expect(subject.encrypted_data_bag_secret_key_path).to eq "/my/root/secret"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#guest_encrypted_data_bag_secret_key_path" do
|
2014-02-16 21:14:56 +00:00
|
|
|
it "returns nil if host path is not configured" do
|
2014-03-14 15:02:07 +00:00
|
|
|
allow(config).to receive(:encrypted_data_bag_secret_key_path).and_return(nil)
|
|
|
|
allow(config).to receive(:provisioning_path).and_return("/tmp/foo")
|
2014-02-16 21:14:56 +00:00
|
|
|
expect(subject.guest_encrypted_data_bag_secret_key_path).to be_nil
|
|
|
|
end
|
|
|
|
|
2014-01-17 02:03:38 +00:00
|
|
|
it "returns path under config.provisioning_path" do
|
2014-03-14 15:02:07 +00:00
|
|
|
allow(config).to receive(:encrypted_data_bag_secret_key_path).and_return("secret")
|
|
|
|
allow(config).to receive(:provisioning_path).and_return("/tmp/foo")
|
2014-01-17 02:03:38 +00:00
|
|
|
expect(File.dirname(subject.guest_encrypted_data_bag_secret_key_path)).
|
|
|
|
to eq "/tmp/foo"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|