2014-11-12 20:49:55 +00:00
|
|
|
require_relative "../../../base"
|
|
|
|
|
|
|
|
require Vagrant.source_root.join("plugins/pushes/atlas/config")
|
|
|
|
|
|
|
|
describe VagrantPlugins::AtlasPush::Config do
|
|
|
|
include_context "unit"
|
|
|
|
|
|
|
|
before(:all) do
|
|
|
|
I18n.load_path << Vagrant.source_root.join("plugins/pushes/atlas/locales/en.yml")
|
|
|
|
I18n.reload!
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:machine) { double("machine") }
|
|
|
|
|
2014-12-10 03:32:14 +00:00
|
|
|
before do
|
|
|
|
subject.token = "foo"
|
2014-12-09 00:54:19 +00:00
|
|
|
end
|
|
|
|
|
2014-12-10 03:32:14 +00:00
|
|
|
describe "#address" do
|
2014-12-09 00:54:19 +00:00
|
|
|
it "defaults to nil" do
|
|
|
|
subject.finalize!
|
2014-12-10 03:32:14 +00:00
|
|
|
expect(subject.address).to be(nil)
|
2014-12-09 00:54:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-12 20:49:55 +00:00
|
|
|
describe "#app" do
|
|
|
|
it "defaults to nil" do
|
|
|
|
subject.finalize!
|
|
|
|
expect(subject.app).to be(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#dir" do
|
|
|
|
it "defaults to ." do
|
|
|
|
subject.finalize!
|
|
|
|
expect(subject.dir).to eq(".")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#vcs" do
|
|
|
|
it "defaults to true" do
|
|
|
|
subject.finalize!
|
|
|
|
expect(subject.vcs).to be(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#uploader_path" do
|
|
|
|
it "defaults to nil" do
|
|
|
|
subject.finalize!
|
|
|
|
expect(subject.uploader_path).to be(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#validate" do
|
|
|
|
before do
|
|
|
|
allow(machine).to receive(:env)
|
|
|
|
.and_return(double("env",
|
|
|
|
root_path: "",
|
2014-12-09 08:08:23 +00:00
|
|
|
data_dir: Pathname.new(""),
|
2014-11-12 20:49:55 +00:00
|
|
|
))
|
|
|
|
|
|
|
|
subject.app = "sethvargo/bacon"
|
|
|
|
subject.dir = "."
|
|
|
|
subject.vcs = true
|
|
|
|
subject.uploader_path = "uploader"
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:result) { subject.validate(machine) }
|
|
|
|
let(:errors) { result["Atlas push"] }
|
|
|
|
|
2014-12-09 00:54:19 +00:00
|
|
|
context "when the token is missing" do
|
|
|
|
context "when a vagrant-login token exists" do
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:token_from_vagrant_login)
|
|
|
|
.and_return("token_from_vagrant_login")
|
|
|
|
|
|
|
|
allow(ENV).to receive(:[]).and_call_original
|
|
|
|
allow(ENV).to receive(:[])
|
|
|
|
.with("ATLAS_TOKEN").and_return("token_from_env")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "uses the token in the Vagrantfile" do
|
|
|
|
subject.token = ""
|
|
|
|
subject.finalize!
|
|
|
|
expect(errors).to be_empty
|
|
|
|
expect(subject.token).to eq("token_from_vagrant_login")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when ATLAS_TOKEN is set in the environment" do
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:token_from_vagrant_login)
|
|
|
|
.and_return(nil)
|
|
|
|
|
|
|
|
allow(ENV).to receive(:[]).and_call_original
|
|
|
|
allow(ENV).to receive(:[])
|
|
|
|
.with("ATLAS_TOKEN").and_return("token_from_env")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "uses the token in the environment" do
|
|
|
|
subject.token = ""
|
|
|
|
subject.finalize!
|
|
|
|
expect(errors).to be_empty
|
|
|
|
expect(subject.token).to eq("token_from_env")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when a token is given in the Vagrantfile" do
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:token_from_vagrant_login)
|
|
|
|
.and_return("token_from_vagrant_login")
|
|
|
|
|
|
|
|
allow(ENV).to receive(:[]).and_call_original
|
|
|
|
allow(ENV).to receive(:[])
|
|
|
|
.with("ATLAS_TOKEN").and_return("token_from_env")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "uses the token in the Vagrantfile" do
|
|
|
|
subject.token = "token_from_vagrantfile"
|
|
|
|
subject.finalize!
|
|
|
|
expect(errors).to be_empty
|
|
|
|
expect(subject.token).to eq("token_from_vagrantfile")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when no token is given" do
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:token_from_vagrant_login)
|
|
|
|
.and_return(nil)
|
|
|
|
|
|
|
|
allow(ENV).to receive(:[]).and_call_original
|
|
|
|
allow(ENV).to receive(:[])
|
|
|
|
.with("ATLAS_TOKEN").and_return(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns an error" do
|
|
|
|
subject.token = ""
|
|
|
|
subject.finalize!
|
|
|
|
expect(errors).to include(I18n.t("atlas_push.errors.missing_token"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-12 20:49:55 +00:00
|
|
|
context "when the app is missing" do
|
|
|
|
it "returns an error" do
|
|
|
|
subject.app = ""
|
|
|
|
subject.finalize!
|
|
|
|
expect(errors).to include(I18n.t("atlas_push.errors.missing_attribute",
|
|
|
|
attribute: "app",
|
|
|
|
))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the dir is missing" do
|
|
|
|
it "returns an error" do
|
|
|
|
subject.dir = ""
|
|
|
|
subject.finalize!
|
|
|
|
expect(errors).to include(I18n.t("atlas_push.errors.missing_attribute",
|
|
|
|
attribute: "dir",
|
|
|
|
))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the vcs is missing" do
|
|
|
|
it "does not return an error" do
|
|
|
|
subject.vcs = ""
|
|
|
|
subject.finalize!
|
|
|
|
expect(errors).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the uploader_path is missing" do
|
|
|
|
it "returns an error" do
|
|
|
|
subject.uploader_path = ""
|
|
|
|
subject.finalize!
|
|
|
|
expect(errors).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#merge" do
|
|
|
|
context "when includes are given" do
|
|
|
|
let(:one) { described_class.new }
|
|
|
|
let(:two) { described_class.new }
|
|
|
|
|
|
|
|
it "merges the result" do
|
|
|
|
one.includes = %w(a b c)
|
|
|
|
two.includes = %w(c d e)
|
|
|
|
result = one.merge(two)
|
|
|
|
expect(result.includes).to eq(%w(a b c d e))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when excludes are given" do
|
|
|
|
let(:one) { described_class.new }
|
|
|
|
let(:two) { described_class.new }
|
|
|
|
|
|
|
|
it "merges the result" do
|
|
|
|
one.excludes = %w(a b c)
|
|
|
|
two.excludes = %w(c d e)
|
|
|
|
result = one.merge(two)
|
|
|
|
expect(result.excludes).to eq(%w(a b c d e))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#include" do
|
|
|
|
it "adds the item to the list" do
|
|
|
|
subject.include("me")
|
|
|
|
expect(subject.includes).to include("me")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#exclude" do
|
|
|
|
it "adds the item to the list" do
|
|
|
|
subject.exclude("not me")
|
|
|
|
expect(subject.excludes).to include("not me")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|