pushes/harmony: boilerplate, config

This commit is contained in:
Mitchell Hashimoto 2014-10-28 20:54:16 -07:00 committed by Seth Vargo
parent 9af7675bd3
commit e7b0661a93
4 changed files with 188 additions and 0 deletions

View File

@ -0,0 +1,73 @@
module VagrantPlugins
module HarmonyPush
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.
#
# @return [String]
attr_accessor :app
# The base directory with file contents to upload. By default this
# is the same directory as the Vagrantfile, but you can specify this
# if you have a `src` folder or `bin` folder or some other folder
# you want to upload.
#
# @return [String]
attr_accessor :dir
# Lists of files to include/exclude in what is uploaded. Exclude is
# always the last run filter, so if a file is matched in both include
# and exclude, it will be excluded.
#
# The value of the array elements should be a simple file glob relative
# to the directory being packaged.
#
# @return [Array<String>]
attr_accessor :include
attr_accessor :exclude
# If set to true, Vagrant will automatically use VCS data to determine
# the files to upload. As a caveat: uncommitted changes will not be
# deployed.
#
# @return [Boolean]
attr_accessor :vcs
def initialize
@app = UNSET_VALUE
@dir = UNSET_VALUE
@vcs = UNSET_VALUE
@include = []
@exclude = []
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
end
end
def finalize!
@app = nil if @app == UNSET_VALUE
@dir = "." if @dir == UNSET_VALUE
@vcs = true if @vcs == UNSET_VALUE
end
def validate(machine)
errors = _detected_errors
if @app == nil || @app == ""
errors << I18n.t("push_harmony.errors.config.app_required")
end
{ "Harmony push" => errors }
end
end
end
end

View File

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

View File

@ -0,0 +1,9 @@
module VagrantPlugins
module HarmonyPush
class Push < Vagrant.plugin("2", :push)
def push
puts "pushed"
end
end
end
end

View File

@ -0,0 +1,84 @@
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(: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 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