2014-04-10 15:50:14 +00:00
|
|
|
require_relative "../../../base"
|
|
|
|
|
2014-04-11 01:26:19 +00:00
|
|
|
require "vagrant/util/platform"
|
|
|
|
|
2014-04-10 15:50:14 +00:00
|
|
|
require Vagrant.source_root.join("plugins/providers/docker/config")
|
|
|
|
|
|
|
|
describe VagrantPlugins::DockerProvider::Config do
|
2014-04-19 02:52:02 +00:00
|
|
|
include_context "unit"
|
|
|
|
|
2014-04-11 01:26:19 +00:00
|
|
|
let(:machine) { double("machine") }
|
|
|
|
|
2014-04-19 02:52:02 +00:00
|
|
|
let(:build_dir) do
|
2016-05-29 04:34:00 +00:00
|
|
|
Dir.mktmpdir("vagrant-test-docker-provider-build-dir").tap do |dir|
|
|
|
|
File.open(File.join(dir, "Dockerfile"), "wb+") do |f|
|
2014-04-19 02:52:02 +00:00
|
|
|
f.write("Hello")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-29 04:34:00 +00:00
|
|
|
after do
|
|
|
|
FileUtils.rm_rf(build_dir)
|
|
|
|
end
|
|
|
|
|
2014-04-11 01:26:19 +00:00
|
|
|
def assert_invalid
|
|
|
|
errors = subject.validate(machine)
|
|
|
|
if !errors.values.any? { |v| !v.empty? }
|
|
|
|
raise "No errors: #{errors.inspect}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def assert_valid
|
|
|
|
errors = subject.validate(machine)
|
|
|
|
if !errors.values.all? { |v| v.empty? }
|
|
|
|
raise "Errors: #{errors.inspect}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-19 02:52:02 +00:00
|
|
|
def valid_defaults
|
|
|
|
subject.image = "foo"
|
|
|
|
end
|
|
|
|
|
2014-04-11 01:26:19 +00:00
|
|
|
describe "defaults" do
|
|
|
|
before { subject.finalize! }
|
|
|
|
|
2014-04-18 22:53:12 +00:00
|
|
|
its(:build_dir) { should be_nil }
|
2014-04-28 01:37:25 +00:00
|
|
|
its(:expose) { should eq([]) }
|
2014-04-11 01:26:19 +00:00
|
|
|
its(:cmd) { should eq([]) }
|
2014-04-18 01:07:57 +00:00
|
|
|
its(:env) { should eq({}) }
|
2014-04-19 02:58:26 +00:00
|
|
|
its(:force_host_vm) { should be_false }
|
2014-05-09 01:46:03 +00:00
|
|
|
its(:host_vm_build_dir_options) { should be_nil }
|
2014-04-11 01:26:19 +00:00
|
|
|
its(:image) { should be_nil }
|
2014-04-18 01:40:04 +00:00
|
|
|
its(:name) { should be_nil }
|
2014-04-11 01:26:19 +00:00
|
|
|
its(:privileged) { should be_false }
|
2014-10-22 00:50:45 +00:00
|
|
|
its(:stop_timeout) { should eq(1) }
|
2014-04-11 01:26:19 +00:00
|
|
|
its(:vagrant_machine) { should be_nil }
|
|
|
|
its(:vagrant_vagrantfile) { should be_nil }
|
2014-10-22 20:12:31 +00:00
|
|
|
|
|
|
|
its(:auth_server) { should be_nil }
|
|
|
|
its(:email) { should eq("") }
|
|
|
|
its(:username) { should eq("") }
|
|
|
|
its(:password) { should eq("") }
|
2014-04-11 01:26:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
# By default lets be Linux for validations
|
|
|
|
Vagrant::Util::Platform.stub(linux: true)
|
2016-05-27 21:36:07 +00:00
|
|
|
Vagrant::Util::Platform.stub(linux?: true)
|
2014-04-11 01:26:19 +00:00
|
|
|
end
|
|
|
|
|
2014-04-19 02:52:02 +00:00
|
|
|
it "should be invalid if both build dir and image are set" do
|
|
|
|
subject.build_dir = build_dir
|
|
|
|
subject.image = "foo"
|
2014-04-11 01:26:19 +00:00
|
|
|
subject.finalize!
|
2014-04-19 02:52:02 +00:00
|
|
|
assert_invalid
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#build_dir" do
|
|
|
|
it "should be valid if not set with image" do
|
|
|
|
subject.build_dir = nil
|
|
|
|
subject.image = "foo"
|
|
|
|
subject.finalize!
|
|
|
|
assert_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be valid with a valid directory" do
|
|
|
|
subject.build_dir = build_dir
|
|
|
|
subject.finalize!
|
|
|
|
assert_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-07-08 16:25:32 +00:00
|
|
|
describe "#create_args" do
|
|
|
|
before do
|
|
|
|
valid_defaults
|
|
|
|
end
|
|
|
|
|
|
|
|
it "is invalid if it isn't an array" do
|
|
|
|
subject.create_args = "foo"
|
|
|
|
subject.finalize!
|
|
|
|
assert_invalid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-28 01:37:25 +00:00
|
|
|
describe "#expose" do
|
|
|
|
before do
|
|
|
|
valid_defaults
|
|
|
|
end
|
|
|
|
|
|
|
|
it "uniqs the ports" do
|
|
|
|
subject.expose = [1, 1, 4, 5]
|
|
|
|
subject.finalize!
|
|
|
|
assert_valid
|
|
|
|
|
|
|
|
expect(subject.expose).to eq([1, 4, 5])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-19 02:52:02 +00:00
|
|
|
describe "#image" do
|
|
|
|
it "should be valid if set" do
|
|
|
|
subject.image = "foo"
|
|
|
|
subject.finalize!
|
|
|
|
assert_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be invalid if not set" do
|
|
|
|
subject.image = nil
|
|
|
|
subject.finalize!
|
|
|
|
assert_invalid
|
|
|
|
end
|
2014-04-11 01:26:19 +00:00
|
|
|
end
|
2014-04-18 01:07:57 +00:00
|
|
|
|
2014-04-18 01:33:46 +00:00
|
|
|
describe "#link" do
|
2014-04-19 02:52:02 +00:00
|
|
|
before do
|
|
|
|
valid_defaults
|
|
|
|
end
|
|
|
|
|
2014-04-18 01:33:46 +00:00
|
|
|
it "should be valid with good links" do
|
|
|
|
subject.link "foo:bar"
|
|
|
|
subject.link "db:blah"
|
|
|
|
subject.finalize!
|
|
|
|
assert_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be invalid if not name:alias" do
|
|
|
|
subject.link "foo"
|
|
|
|
subject.finalize!
|
|
|
|
assert_invalid
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be invalid if too many colons" do
|
|
|
|
subject.link "foo:bar:baz"
|
|
|
|
subject.finalize!
|
|
|
|
assert_invalid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-18 01:07:57 +00:00
|
|
|
describe "#merge" do
|
2014-04-18 01:33:46 +00:00
|
|
|
let(:one) { described_class.new }
|
|
|
|
let(:two) { described_class.new }
|
2014-04-18 01:07:57 +00:00
|
|
|
|
2014-04-18 01:33:46 +00:00
|
|
|
subject { one.merge(two) }
|
2014-04-18 01:07:57 +00:00
|
|
|
|
2014-04-19 03:31:49 +00:00
|
|
|
context "#build_dir and #image" do
|
|
|
|
it "overrides image if build_dir is set previously" do
|
|
|
|
one.build_dir = "foo"
|
|
|
|
two.image = "bar"
|
|
|
|
|
|
|
|
expect(subject.build_dir).to be_nil
|
|
|
|
expect(subject.image).to eq("bar")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "overrides image if build_dir is set previously" do
|
|
|
|
one.image = "foo"
|
|
|
|
two.build_dir = "bar"
|
|
|
|
|
|
|
|
expect(subject.image).to be_nil
|
|
|
|
expect(subject.build_dir).to eq("bar")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "preserves if both set" do
|
|
|
|
one.image = "foo"
|
|
|
|
two.image = "baz"
|
|
|
|
two.build_dir = "bar"
|
|
|
|
|
|
|
|
expect(subject.image).to eq("baz")
|
|
|
|
expect(subject.build_dir).to eq("bar")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-18 01:33:46 +00:00
|
|
|
context "env vars" do
|
2014-04-18 01:07:57 +00:00
|
|
|
it "should merge the values" do
|
|
|
|
one.env["foo"] = "bar"
|
|
|
|
two.env["bar"] = "baz"
|
|
|
|
|
|
|
|
expect(subject.env).to eq({
|
|
|
|
"foo" => "bar",
|
|
|
|
"bar" => "baz",
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
2014-04-18 01:33:46 +00:00
|
|
|
|
2014-04-28 01:37:25 +00:00
|
|
|
context "exposed ports" do
|
|
|
|
it "merges the exposed ports" do
|
|
|
|
one.expose << 1234
|
|
|
|
two.expose = [42, 54]
|
|
|
|
|
|
|
|
expect(subject.expose).to eq([
|
|
|
|
1234, 42, 54])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-18 01:33:46 +00:00
|
|
|
context "links" do
|
|
|
|
it "should merge the links" do
|
|
|
|
one.link "foo"
|
|
|
|
two.link "bar"
|
|
|
|
|
|
|
|
expect(subject._links).to eq([
|
|
|
|
"foo", "bar"])
|
|
|
|
end
|
|
|
|
end
|
2014-04-18 01:07:57 +00:00
|
|
|
end
|
2014-04-19 02:52:02 +00:00
|
|
|
|
2014-05-06 04:13:15 +00:00
|
|
|
describe "#vagrant_machine" do
|
|
|
|
before { valid_defaults }
|
|
|
|
|
|
|
|
it "should convert to a symbol" do
|
|
|
|
subject.vagrant_machine = "foo"
|
|
|
|
subject.finalize!
|
|
|
|
assert_valid
|
|
|
|
expect(subject.vagrant_machine).to eq(:foo)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-19 02:52:02 +00:00
|
|
|
describe "#vagrant_vagrantfile" do
|
|
|
|
before { valid_defaults }
|
|
|
|
|
|
|
|
it "should be valid if set to a file" do
|
|
|
|
subject.vagrant_vagrantfile = temporary_file.to_s
|
|
|
|
subject.finalize!
|
|
|
|
assert_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not be valid if set to a non-existent place" do
|
|
|
|
subject.vagrant_vagrantfile = "/i/shouldnt/exist"
|
|
|
|
subject.finalize!
|
|
|
|
assert_invalid
|
|
|
|
end
|
|
|
|
end
|
2014-04-10 15:50:14 +00:00
|
|
|
end
|