Rename Harmony to Atlas, minor config changes

This commit is contained in:
Seth Vargo 2014-11-12 15:49:55 -05:00
parent c8bdf53c7e
commit ed605c9aac
8 changed files with 215 additions and 134 deletions

View File

@ -1,5 +1,5 @@
module VagrantPlugins
module HarmonyPush
module AtlasPush
class Config < Vagrant.plugin("2", :config)
# The name of the application to push to. This will be created (with
# user confirmation) if it doesn't already exist.
@ -23,8 +23,8 @@ module VagrantPlugins
# to the directory being packaged.
#
# @return [Array<String>]
attr_accessor :include
attr_accessor :exclude
attr_accessor :includes
attr_accessor :excludes
# If set to true, Vagrant will automatically use VCS data to determine
# the files to upload. As a caveat: uncommitted changes will not be
@ -45,20 +45,15 @@ module VagrantPlugins
@app = UNSET_VALUE
@dir = UNSET_VALUE
@vcs = UNSET_VALUE
@include = []
@exclude = []
@includes = []
@excludes = []
@uploader_path = UNSET_VALUE
end
def merge(other)
super.tap do |result|
inc = self.include.dup
inc.concat(other.include)
result.include = inc
exc = self.exclude.dup
exc.concat(other.exclude)
result.exclude = exc
result.includes = self.includes.dup.concat(other.includes).uniq
result.excludes = self.excludes.dup.concat(other.excludes).uniq
end
end
@ -72,11 +67,41 @@ module VagrantPlugins
def validate(machine)
errors = _detected_errors
if @app.to_s.strip.empty?
errors << I18n.t("push_harmony.errors.config.app_required")
if missing?(@app)
errors << I18n.t("atlas_push.errors.missing_attribute",
attribute: "app",
)
end
{ "Harmony push" => errors }
if missing?(@dir)
errors << I18n.t("atlas_push.errors.missing_attribute",
attribute: "dir",
)
end
{ "Atlas push" => errors }
end
# Add the filepath to the list of includes
# @param [String] filepath
def include(filepath)
@includes << filepath
end
alias_method :include=, :include
# Add the filepath to the list of excludes
# @param [String] filepath
def exclude(filepath)
@excludes << filepath
end
alias_method :exclude=, :exclude
private
# Determine if the given string is "missing" (blank)
# @return [true, false]
def missing?(obj)
obj.to_s.strip.empty?
end
end
end

View File

@ -1,8 +1,8 @@
module VagrantPlugins
module HarmonyPush
module AtlasPush
module Errors
class Error < Vagrant::Errors::VagrantError
error_namespace("harmony_push.errors")
error_namespace("atlas_push.errors")
end
class UploaderNotFound < Error

View File

@ -0,0 +1,11 @@
en:
atlas_push:
errors:
missing_attribute: |-
Missing required attribute '%{attribute}'. The Vagrant Atlas Push plugin
requires you set this attribute. Please set this attribute in your
Vagrantfile, for example:
config.push.define "atlas" do |push|
push.%{attribute} = "..."
end

View File

@ -1,22 +1,22 @@
require "vagrant"
module VagrantPlugins
module HarmonyPush
module AtlasPush
autoload :Errors, File.expand_path("../errors", __FILE__)
class Plugin < Vagrant.plugin("2")
name "harmony"
name "atlas"
description <<-DESC
Deploy using HashiCorp's Harmony service.
Deploy using HashiCorp's Atlas service.
DESC
config(:harmony, :push) do
config(:atlas, :push) do
require_relative "config"
init!
Config
end
push(:harmony) do
push(:atlas) do
require_relative "push"
init!
Push

View File

@ -3,9 +3,9 @@ require "vagrant/util/subprocess"
require "vagrant/util/which"
module VagrantPlugins
module HarmonyPush
module AtlasPush
class Push < Vagrant.plugin("2", :push)
UPLOADER_BIN = "harmony-upload".freeze
UPLOADER_BIN = "atlas-upload".freeze
def push
uploader = self.uploader_path
@ -24,8 +24,8 @@ module VagrantPlugins
def execute(uploader)
cmd = []
cmd << "-vcs" if config.vcs
cmd += config.include.map { |v| ["-include", v] }
cmd += config.exclude.map { |v| ["-exclude", v] }
cmd += config.includes.map { |v| ["-include", v] }
cmd += config.excludes.map { |v| ["-exclude", v] }
cmd << config.app
cmd << File.expand_path(config.dir, env.root_path)
Vagrant::Util::SafeExec.exec(uploader, *cmd.flatten)

View File

@ -0,0 +1,135 @@
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") }
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: "",
))
subject.app = "sethvargo/bacon"
subject.dir = "."
subject.vcs = true
subject.uploader_path = "uploader"
end
let(:result) { subject.validate(machine) }
let(:errors) { result["Atlas push"] }
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

View File

@ -1,27 +1,28 @@
require_relative "../../../base"
require Vagrant.source_root.join("plugins/pushes/harmony/config")
require Vagrant.source_root.join("plugins/pushes/harmony/push")
require Vagrant.source_root.join("plugins/pushes/atlas/config")
require Vagrant.source_root.join("plugins/pushes/atlas/push")
describe VagrantPlugins::HarmonyPush::Push do
describe VagrantPlugins::AtlasPush::Push do
include_context "unit"
let(:env) do
double("env",
root_path: File.expand_path("..", __FILE__)
)
end
let(:config) do
VagrantPlugins::HarmonyPush::Config.new.tap do |c|
VagrantPlugins::AtlasPush::Config.new.tap do |c|
c.finalize!
end
end
let(:environment) { double("environment") }
subject { described_class.new(environment, config) }
subject { described_class.new(env, config) }
before do
# Stub this right away to avoid real execs
allow(Vagrant::Util::SafeExec).to receive(:exec)
allow(environment).to receive(:root_path).and_return(
File.expand_path("../", __FILE__))
end
describe "#push" do
@ -37,7 +38,7 @@ describe VagrantPlugins::HarmonyPush::Push do
expect(subject).to receive(:uploader_path).and_return(nil)
expect { subject.push }.to raise_error(
VagrantPlugins::HarmonyPush::Errors::UploaderNotFound)
VagrantPlugins::AtlasPush::Errors::UploaderNotFound)
end
end
@ -50,14 +51,14 @@ describe VagrantPlugins::HarmonyPush::Push do
it "sends the basic flags" do
expect(Vagrant::Util::SafeExec).to receive(:exec).
with("foo", "-vcs", app, environment.root_path.to_s)
with("foo", "-vcs", app, env.root_path.to_s)
subject.execute("foo")
end
it "doesn't send VCS if disabled" do
expect(Vagrant::Util::SafeExec).to receive(:exec).
with("foo", app, environment.root_path.to_s)
with("foo", app, env.root_path.to_s)
config.vcs = false
subject.execute("foo")
@ -66,18 +67,18 @@ describe VagrantPlugins::HarmonyPush::Push do
it "sends includes" do
expect(Vagrant::Util::SafeExec).to receive(:exec).
with("foo", "-vcs", "-include", "foo", "-include",
"bar", app, environment.root_path.to_s)
"bar", app, env.root_path.to_s)
config.include = ["foo", "bar"]
config.includes = ["foo", "bar"]
subject.execute("foo")
end
it "sends excludes" do
expect(Vagrant::Util::SafeExec).to receive(:exec).
with("foo", "-vcs", "-exclude", "foo", "-exclude",
"bar", app, environment.root_path.to_s)
"bar", app, env.root_path.to_s)
config.exclude = ["foo", "bar"]
config.excludes = ["foo", "bar"]
subject.execute("foo")
end
end

View File

@ -1,91 +0,0 @@
require_relative "../../../base"
require Vagrant.source_root.join("plugins/pushes/harmony/config")
describe VagrantPlugins::HarmonyPush::Config do
include_context "unit"
let(:machine) { double("machine") }
# For testing merging
let(:one) { described_class.new }
let(:two) { described_class.new }
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
def valid_defaults
end
describe "defaults" do
before { subject.finalize! }
its(:app) { should be_nil }
its(:dir) { should eq(".") }
its(:exclude) { should be_empty }
its(:include) { should be_empty }
its(:uploader_path) { should be_nil }
its(:vcs) { should be_true }
end
describe "app" do
before do
valid_defaults
end
it "is invalid if not set" do
subject.app = ""
subject.finalize!
assert_invalid
end
it "is invalid if blank" do
subject.app = " "
subject.finalize!
assert_invalid
end
it "is valid if set" do
subject.app = "foo/bar"
subject.finalize!
assert_valid
end
end
describe "exclude" do
context "merge" do
subject { one.merge(two) }
it "appends" do
one.exclude = ["foo"]
two.exclude = ["bar"]
expect(subject.exclude).to eq(["foo", "bar"])
end
end
end
describe "include" do
context "merge" do
subject { one.merge(two) }
it "appends" do
one.include = ["foo"]
two.include = ["bar"]
expect(subject.include).to eq(["foo", "bar"])
end
end
end
end