heirloom 0.2.0 → 0.3.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +10 -0
- data/README.md +17 -15
- data/lib/heirloom/acl/s3.rb +3 -2
- data/lib/heirloom/archive/authorizer.rb +8 -4
- data/lib/heirloom/archive/builder.rb +8 -8
- data/lib/heirloom/archive/destroyer.rb +4 -2
- data/lib/heirloom/archive/reader.rb +15 -3
- data/lib/heirloom/archive/uploader.rb +2 -1
- data/lib/heirloom/archive/verifier.rb +2 -1
- data/lib/heirloom/archive.rb +18 -13
- data/lib/heirloom/cli/authorize.rb +52 -0
- data/lib/heirloom/cli/build.rb +25 -17
- data/lib/heirloom/cli/destroy.rb +6 -3
- data/lib/heirloom/cli/download.rb +8 -4
- data/lib/heirloom/cli/list.rb +6 -3
- data/lib/heirloom/cli/shared.rb +31 -0
- data/lib/heirloom/cli/show.rb +10 -7
- data/lib/heirloom/cli/update.rb +12 -7
- data/lib/heirloom/cli.rb +9 -2
- data/lib/heirloom/config.rb +4 -10
- data/lib/heirloom/directory/git_directory.rb +2 -2
- data/lib/heirloom/logger.rb +18 -30
- data/lib/heirloom/version.rb +1 -1
- data/script/ci_setup +4 -4
- data/spec/acl/s3_spec.rb +2 -3
- data/spec/{heirloom → archive}/authorizer_spec.rb +5 -5
- data/spec/{heirloom → archive}/builder_spec.rb +0 -0
- data/spec/{heirloom → archive}/destroyer_spec.rb +1 -2
- data/spec/{heirloom → archive}/downloader_spec.rb +0 -0
- data/spec/{heirloom → archive}/lister_spec.rb +0 -0
- data/spec/{heirloom → archive}/reader_spec.rb +20 -4
- data/spec/archive/updater_spec.rb +26 -0
- data/spec/archive/uploader_spec.rb +40 -0
- data/spec/{heirloom → archive}/verifier_spec.rb +6 -6
- data/spec/archive_spec.rb +195 -0
- data/spec/cli/shared_spec.rb +45 -0
- data/spec/config_spec.rb +11 -22
- data/spec/logger_spec.rb +3 -9
- metadata +42 -41
- data/spec/heirloom/updater_spec.rb +0 -16
- data/spec/heirloom/uploader_spec.rb +0 -16
- data/spec/heirloom_spec.rb +0 -74
data/lib/heirloom/cli.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'trollop'
|
2
2
|
|
3
|
+
require 'heirloom/cli/authorize'
|
3
4
|
require 'heirloom/cli/build'
|
4
5
|
require 'heirloom/cli/list'
|
5
6
|
require 'heirloom/cli/show'
|
@@ -7,6 +8,8 @@ require 'heirloom/cli/update'
|
|
7
8
|
require 'heirloom/cli/download'
|
8
9
|
require 'heirloom/cli/destroy'
|
9
10
|
|
11
|
+
require 'heirloom/cli/shared'
|
12
|
+
|
10
13
|
module Heirloom
|
11
14
|
module CLI
|
12
15
|
def self.start
|
@@ -19,15 +22,19 @@ module Heirloom
|
|
19
22
|
CLI::Show.new.show
|
20
23
|
when 'build'
|
21
24
|
CLI::Build.new.build
|
25
|
+
when 'authorize'
|
26
|
+
CLI::Authorize.new.authorize
|
22
27
|
when 'update'
|
23
28
|
CLI::Update.new.update
|
24
29
|
when 'download'
|
25
30
|
CLI::Download.new.download
|
26
31
|
when 'destroy', 'delete'
|
27
32
|
CLI::Destroy.new.destroy
|
33
|
+
when '-v'
|
34
|
+
puts Heirloom::VERSION
|
28
35
|
else
|
29
|
-
puts "Unkown command: '#{cmd}'."
|
30
|
-
puts "heirloom [list|show|build|update|download|destroy] OPTIONS"
|
36
|
+
puts "Unkown command: '#{cmd}'." unless cmd == '-h'
|
37
|
+
puts "heirloom [list|show|build|authorize|update|download|destroy] OPTIONS"
|
31
38
|
puts "Append -h for help on specific command."
|
32
39
|
end
|
33
40
|
end
|
data/lib/heirloom/config.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
module Heirloom
|
2
2
|
class Config
|
3
3
|
|
4
|
-
attr_accessor :access_key, :secret_key, :
|
5
|
-
:primary_region, :bucket_prefix, :authorized_aws_accounts,
|
6
|
-
:logger, :simpledb
|
4
|
+
attr_accessor :access_key, :secret_key, :primary_region, :logger
|
7
5
|
|
8
6
|
def initialize(args = {})
|
9
7
|
@config = args[:config]
|
@@ -13,17 +11,13 @@ module Heirloom
|
|
13
11
|
|
14
12
|
def load_config_file
|
15
13
|
config_file = "#{ENV['HOME']}/.heirloom.yml"
|
16
|
-
|
14
|
+
config = @config ? @config : YAML::load(File.open(config_file))
|
17
15
|
|
18
|
-
aws =
|
16
|
+
aws = config['aws']
|
19
17
|
|
20
18
|
self.access_key = aws['access_key']
|
21
19
|
self.secret_key = aws['secret_key']
|
22
|
-
self.
|
23
|
-
self.bucket_prefix = aws['bucket_prefix']
|
24
|
-
self.authorized_aws_accounts = aws['authorized_aws_accounts']
|
25
|
-
self.simpledb = aws['simpledb'] ||= true
|
26
|
-
self.primary_region = regions ? regions.first : 'us-west-1'
|
20
|
+
self.primary_region = aws['primary_region'] ||= 'us-west-1'
|
27
21
|
end
|
28
22
|
|
29
23
|
end
|
data/lib/heirloom/logger.rb
CHANGED
@@ -1,44 +1,32 @@
|
|
1
1
|
module Heirloom
|
2
2
|
class HeirloomLogger
|
3
3
|
|
4
|
-
|
5
|
-
@logger = args[:logger] ||= Logger.new(STDOUT)
|
6
|
-
@log_level = args[:log_level] ||= 'info'
|
4
|
+
require 'forwardable'
|
7
5
|
|
8
|
-
|
9
|
-
@logger.datetime_format = "%Y-%m-%d %H:%M:%S"
|
10
|
-
@logger.formatter = proc do |severity, datetime, progname, msg|
|
11
|
-
"#{datetime}: #{msg}\n"
|
12
|
-
end
|
13
|
-
end
|
6
|
+
extend Forwardable
|
14
7
|
|
15
|
-
|
16
|
-
when 'info'
|
17
|
-
@logger.level = Logger::INFO
|
18
|
-
when 'debug'
|
19
|
-
@logger.level = Logger::DEBUG
|
20
|
-
when 'warn'
|
21
|
-
@logger.level = Logger::WARN
|
22
|
-
when 'error'
|
23
|
-
@logger.level = Logger::ERROR
|
24
|
-
end
|
25
|
-
@logger
|
26
|
-
end
|
8
|
+
def_delegators :@logger, :debug, :error, :info, :warn
|
27
9
|
|
28
|
-
def
|
29
|
-
@
|
10
|
+
def initialize(args = {})
|
11
|
+
@log_level = args[:log_level] ||= 'info'
|
12
|
+
@logger = args[:logger] ||= new_logger(args)
|
30
13
|
end
|
31
14
|
|
32
|
-
|
33
|
-
@logger.info msg
|
34
|
-
end
|
15
|
+
private
|
35
16
|
|
36
|
-
def
|
37
|
-
|
17
|
+
def new_logger(args)
|
18
|
+
Logger.new(STDOUT).tap do |l|
|
19
|
+
l.datetime_format = '%Y-%m-%dT%H:%M:%S%z'
|
20
|
+
l.formatter = proc do |severity, datetime, progname, msg|
|
21
|
+
"#{datetime} #{severity} : #{msg}\n"
|
22
|
+
end
|
23
|
+
l.level = logger_level
|
24
|
+
end
|
38
25
|
end
|
39
26
|
|
40
|
-
def
|
41
|
-
@
|
27
|
+
def logger_level
|
28
|
+
Logger.const_get @log_level.upcase
|
42
29
|
end
|
30
|
+
|
43
31
|
end
|
44
32
|
end
|
data/lib/heirloom/version.rb
CHANGED
data/script/ci_setup
CHANGED
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
# Source RVM profile and set ruby / gemset
|
4
4
|
. /etc/profile
|
5
|
-
|
5
|
+
|
6
|
+
# Exit with error if any command returns non zero
|
7
|
+
set -e
|
6
8
|
|
7
9
|
# Bundle gems
|
10
|
+
rvm use "1.9.3-p125@heirloom" --create
|
8
11
|
bundle
|
9
12
|
|
10
|
-
# Create blank deployment config
|
11
|
-
touch $HOME/.heirloom.yml
|
12
|
-
|
13
13
|
# Run spec tests
|
14
14
|
rspec spec
|
data/spec/acl/s3_spec.rb
CHANGED
@@ -5,8 +5,6 @@ describe Heirloom do
|
|
5
5
|
@config_mock = double 'config'
|
6
6
|
@logger_mock = double 'logger'
|
7
7
|
@config_mock.should_receive(:logger).and_return(@logger_mock)
|
8
|
-
@config_mock.should_receive(:authorized_aws_accounts).
|
9
|
-
and_return ['acct1@test.com', 'acct2@test.com']
|
10
8
|
|
11
9
|
@s3 = Heirloom::ACL::S3.new :config => @config_mock,
|
12
10
|
:region => 'us-west-1'
|
@@ -37,7 +35,8 @@ describe Heirloom do
|
|
37
35
|
|
38
36
|
@s3.allow_read_access_from_accounts :bucket => 'bucket',
|
39
37
|
:key_name => 'key',
|
40
|
-
:key_folder => 'key-folder'
|
38
|
+
:key_folder => 'key-folder',
|
39
|
+
:accounts => ['acct1@test.com', 'acct2@test.com']
|
41
40
|
end
|
42
41
|
|
43
42
|
end
|
@@ -11,12 +11,10 @@ describe Heirloom do
|
|
11
11
|
:id => '123'
|
12
12
|
end
|
13
13
|
|
14
|
-
it "should authorize access to an
|
14
|
+
it "should authorize access to an archive in all regions" do
|
15
15
|
reader = double
|
16
16
|
s3_acl = double
|
17
17
|
@logger_mock.should_receive(:info).exactly(2).times
|
18
|
-
@config_mock.should_receive(:regions).
|
19
|
-
and_return(['us-west-1', 'us-west-2'])
|
20
18
|
@authorizer.should_receive(:reader).exactly(2).times.
|
21
19
|
and_return(reader)
|
22
20
|
reader.should_receive(:get_bucket).exactly(2).times.
|
@@ -27,8 +25,10 @@ describe Heirloom do
|
|
27
25
|
exactly(2).times.
|
28
26
|
with(:key_name => '123',
|
29
27
|
:key_folder => 'tim',
|
30
|
-
:bucket => 'the-bucket'
|
31
|
-
|
28
|
+
:bucket => 'the-bucket',
|
29
|
+
:accounts => ["acct1", "acct2"])
|
30
|
+
@authorizer.authorize :accounts => ['acct1', 'acct2'],
|
31
|
+
:regions => ['us-west-1', 'us-west-2']
|
32
32
|
end
|
33
33
|
|
34
34
|
end
|
File without changes
|
@@ -14,7 +14,6 @@ describe Heirloom do
|
|
14
14
|
it "should destroy the given archive" do
|
15
15
|
@logger_mock.should_receive(:info).
|
16
16
|
with "Destroying tim - 123"
|
17
|
-
@config_mock.should_receive(:regions).and_return ['us-west-1']
|
18
17
|
reader_mock = mock 'archive reader'
|
19
18
|
@destroyer.should_receive(:reader).and_return reader_mock
|
20
19
|
bucket_mock = mock 'bucket'
|
@@ -39,7 +38,7 @@ describe Heirloom do
|
|
39
38
|
sdb_mock.should_receive(:delete).with 'tim', '123'
|
40
39
|
@logger_mock.should_receive(:info).
|
41
40
|
with "Destroy complete."
|
42
|
-
@destroyer.destroy
|
41
|
+
@destroyer.destroy :regions => ['us-west-1']
|
43
42
|
end
|
44
43
|
|
45
44
|
end
|
File without changes
|
File without changes
|
@@ -16,7 +16,7 @@ describe Heirloom do
|
|
16
16
|
it "should show the item record" do
|
17
17
|
@sdb_mock.should_receive(:select).
|
18
18
|
with("select * from tim where itemName() = '123'").
|
19
|
-
and_return( { '123' => { 'value' => 'details' } } )
|
19
|
+
and_return( { '123' => { 'value' => [ 'details' ] } } )
|
20
20
|
@reader.show.should == { 'value' => 'details' }
|
21
21
|
end
|
22
22
|
|
@@ -30,7 +30,7 @@ describe Heirloom do
|
|
30
30
|
it "should return true if the record exists" do
|
31
31
|
@sdb_mock.should_receive(:select).
|
32
32
|
with("select * from tim where itemName() = '123'").
|
33
|
-
and_return( { '123' => { 'value' => 'details' } } )
|
33
|
+
and_return( { '123' => { 'value' => [ 'details' ] } } )
|
34
34
|
@logger_mock.should_receive(:debug).exactly(1).times
|
35
35
|
@reader.exists?.should == true
|
36
36
|
end
|
@@ -50,10 +50,10 @@ describe Heirloom do
|
|
50
50
|
with("select * from tim where itemName() = '123'").
|
51
51
|
and_return( { '123' =>
|
52
52
|
{ 'us-west-1-s3-url' =>
|
53
|
-
['s3://the-
|
53
|
+
[ 's3://the-bucket/the-buck/the-key' ]
|
54
54
|
}
|
55
55
|
} )
|
56
|
-
@reader.get_bucket(:region => 'us-west-1').should == 'the-
|
56
|
+
@reader.get_bucket(:region => 'us-west-1').should == 'the-bucket'
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should return nil if the bucket does not exist" do
|
@@ -87,4 +87,20 @@ describe Heirloom do
|
|
87
87
|
@reader.get_key(:region => 'us-west-1').should == nil
|
88
88
|
end
|
89
89
|
|
90
|
+
it "should return the regions the archive has been uploaded to" do
|
91
|
+
@sdb_mock.should_receive(:select).
|
92
|
+
exactly(1).times.
|
93
|
+
with("select * from tim where itemName() = '123'").
|
94
|
+
and_return( { '123' =>
|
95
|
+
{ 'us-west-1-s3-url' =>
|
96
|
+
['s3://the-url-us-west-1/the-bucket/the-key'],
|
97
|
+
'build_by' =>
|
98
|
+
['user'],
|
99
|
+
'us-east-1-s3-url' =>
|
100
|
+
['s3://the-url-us-east-1/the-bucket/the-key']
|
101
|
+
}
|
102
|
+
} )
|
103
|
+
@reader.regions.should == ['us-west-1', 'us-east-1']
|
104
|
+
end
|
105
|
+
|
90
106
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Heirloom do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@config_mock = double 'config'
|
7
|
+
@logger_mock = double 'logger'
|
8
|
+
@config_mock.should_receive(:logger).and_return(@logger_mock)
|
9
|
+
@updater = Heirloom::Updater.new :config => @config_mock,
|
10
|
+
:name => 'tim',
|
11
|
+
:id => '123'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should test an attribute is updated" do
|
15
|
+
sdb_mock = mock 'sdb mock'
|
16
|
+
@logger_mock.should_receive(:info)
|
17
|
+
Heirloom::AWS::SimpleDB.should_receive(:new).
|
18
|
+
with(:config => @config_mock).
|
19
|
+
and_return sdb_mock
|
20
|
+
sdb_mock.should_receive(:put_attributes).
|
21
|
+
with('tim', '123', { 'attr' => 'val' }, { :replace => 'attr' })
|
22
|
+
@updater.update :attribute => 'attr',
|
23
|
+
:value => 'val'
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Heirloom do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@config_mock = double 'config'
|
7
|
+
@logger_mock = double 'logger'
|
8
|
+
@config_mock.should_receive(:logger).and_return(@logger_mock)
|
9
|
+
@uploader = Heirloom::Uploader.new :config => @config_mock,
|
10
|
+
:name => 'tim',
|
11
|
+
:id => '123'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should upload a new archive" do
|
15
|
+
s3_mock = mock 's3'
|
16
|
+
Heirloom::Uploader::S3.should_receive(:new).
|
17
|
+
with(:config => @config_mock,
|
18
|
+
:logger => @logger_mock,
|
19
|
+
:region => 'us-west-1').
|
20
|
+
and_return s3_mock
|
21
|
+
s3_mock.should_receive(:upload_file).
|
22
|
+
with(:bucket => 'prefix-us-west-1',
|
23
|
+
:file => '/tmp/file',
|
24
|
+
:id => '123',
|
25
|
+
:key_folder => 'tim',
|
26
|
+
:key_name => "123.tar.gz",
|
27
|
+
:name => 'tim',
|
28
|
+
:public_readable => true)
|
29
|
+
s3_mock.should_receive(:add_endpoint_attributes).
|
30
|
+
with(:bucket => 'prefix-us-west-1',
|
31
|
+
:id => '123',
|
32
|
+
:name => 'tim')
|
33
|
+
@logger_mock.should_receive(:info)
|
34
|
+
@uploader.upload :file => '/tmp/file',
|
35
|
+
:bucket_prefix => 'prefix',
|
36
|
+
:regions => ['us-west-1'],
|
37
|
+
:public_readable => true
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -12,7 +12,6 @@ describe Heirloom do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should return false if a bucket does not exist" do
|
15
|
-
@config_mock.should_receive(:regions).and_return ['us-west-1']
|
16
15
|
Heirloom::AWS::S3.should_receive(:new).
|
17
16
|
with(:config => @config_mock,
|
18
17
|
:region => 'us-west-1').
|
@@ -20,19 +19,20 @@ describe Heirloom do
|
|
20
19
|
@s3_mock.should_receive(:get_bucket).with('bucket123-us-west-1').
|
21
20
|
and_return nil
|
22
21
|
@logger_mock.should_receive(:debug)
|
23
|
-
@verifier.buckets_exist?(:bucket_prefix => 'bucket123'
|
22
|
+
@verifier.buckets_exist?(:bucket_prefix => 'bucket123',
|
23
|
+
:regions => ['us-west-1']).should be_false
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should true if all buckets exist" do
|
27
|
-
@config_mock.should_receive(:regions).and_return ['us-west-2']
|
28
27
|
Heirloom::AWS::S3.should_receive(:new).
|
29
28
|
with(:config => @config_mock,
|
30
|
-
:region => 'us-west-
|
29
|
+
:region => 'us-west-1').
|
31
30
|
and_return @s3_mock
|
32
|
-
@s3_mock.should_receive(:get_bucket).with('bucket123-us-west-
|
31
|
+
@s3_mock.should_receive(:get_bucket).with('bucket123-us-west-1').
|
33
32
|
and_return 'an s3 bucket'
|
34
33
|
@logger_mock.should_receive(:debug)
|
35
|
-
@verifier.buckets_exist?(:bucket_prefix => 'bucket123'
|
34
|
+
@verifier.buckets_exist?(:bucket_prefix => 'bucket123',
|
35
|
+
:regions => ['us-west-1']).should be_true
|
36
36
|
end
|
37
37
|
|
38
38
|
end
|
@@ -0,0 +1,195 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Heirloom do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@config_mock = mock 'config'
|
7
|
+
@logger_mock = mock 'logger'
|
8
|
+
Heirloom::Config.should_receive(:new).and_return @config_mock
|
9
|
+
@archive = Heirloom::Archive.new :logger => @logger_mock,
|
10
|
+
:name => 'chef',
|
11
|
+
:id => '123'
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
context "test public methods" do
|
16
|
+
|
17
|
+
it "should call build with given args" do
|
18
|
+
mock = double('Mock')
|
19
|
+
Heirloom::Builder.should_receive(:new).
|
20
|
+
with(:config => @config_mock,
|
21
|
+
:name => 'chef',
|
22
|
+
:id => '123').
|
23
|
+
and_return mock
|
24
|
+
mock.should_receive(:build).with('args')
|
25
|
+
@archive.build('args')
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should call download method with given args" do
|
29
|
+
mock = double('Mock')
|
30
|
+
Heirloom::Downloader.should_receive(:new).
|
31
|
+
with(:config => @config_mock,
|
32
|
+
:name => 'chef',
|
33
|
+
:id => '123').
|
34
|
+
and_return mock
|
35
|
+
mock.should_receive(:download).with('args')
|
36
|
+
@archive.download('args')
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should call update archive method with given args" do
|
40
|
+
mock = double('Mock')
|
41
|
+
Heirloom::Updater.should_receive(:new).
|
42
|
+
with(:config => @config_mock,
|
43
|
+
:name => 'chef',
|
44
|
+
:id => '123').
|
45
|
+
and_return mock
|
46
|
+
mock.should_receive(:update).with('args')
|
47
|
+
@archive.update('args')
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should call upload archive method with given args" do
|
51
|
+
mock = double('Mock')
|
52
|
+
reader_mock = double('reader mock')
|
53
|
+
Heirloom::Reader.should_receive(:new).
|
54
|
+
with(:config => @config_mock,
|
55
|
+
:name => 'chef',
|
56
|
+
:id => '123').
|
57
|
+
and_return reader_mock
|
58
|
+
reader_mock.should_receive(:regions).and_return ['us-west-1', 'us-west-2']
|
59
|
+
Heirloom::Uploader.should_receive(:new).
|
60
|
+
with(:config => @config_mock,
|
61
|
+
:name => 'chef',
|
62
|
+
:id => '123').
|
63
|
+
and_return mock
|
64
|
+
mock.should_receive(:upload).with('arg' => 'val', :regions => ['us-west-1', 'us-west-2'])
|
65
|
+
@archive.upload('arg' => 'val')
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should call authorize method" do
|
69
|
+
mock = double('Mock')
|
70
|
+
reader_mock = double('reader mock')
|
71
|
+
Heirloom::Reader.should_receive(:new).
|
72
|
+
with(:config => @config_mock,
|
73
|
+
:name => 'chef',
|
74
|
+
:id => '123').
|
75
|
+
and_return reader_mock
|
76
|
+
reader_mock.should_receive(:regions).and_return ['us-west-1', 'us-west-2']
|
77
|
+
Heirloom::Authorizer.should_receive(:new).
|
78
|
+
with(:config => @config_mock,
|
79
|
+
:name => 'chef',
|
80
|
+
:id => '123').
|
81
|
+
and_return mock
|
82
|
+
mock.should_receive(:authorize).with :regions => ['us-west-1', 'us-west-2'],
|
83
|
+
:accounts => ['acct1', 'acct2']
|
84
|
+
@archive.authorize ['acct1', 'acct2']
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should call archive exists method and return true if archive exists" do
|
88
|
+
mock = double('Mock')
|
89
|
+
Heirloom::Reader.should_receive(:new).
|
90
|
+
with(:config => @config_mock,
|
91
|
+
:name => 'chef',
|
92
|
+
:id => '123').
|
93
|
+
and_return mock
|
94
|
+
mock.should_receive(:exists?).and_return true
|
95
|
+
@archive.exists?.should be_true
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should call archive exists method and return fasle if archive doesnt exists" do
|
99
|
+
mock = double('Mock')
|
100
|
+
Heirloom::Reader.should_receive(:new).
|
101
|
+
with(:config => @config_mock,
|
102
|
+
:name => 'chef',
|
103
|
+
:id => '123').
|
104
|
+
and_return mock
|
105
|
+
mock.should_receive(:exists?).and_return false
|
106
|
+
@archive.exists?.should be_false
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should call show method" do
|
110
|
+
mock = double('Mock')
|
111
|
+
Heirloom::Reader.should_receive(:new).
|
112
|
+
with(:config => @config_mock,
|
113
|
+
:name => 'chef',
|
114
|
+
:id => '123').
|
115
|
+
and_return mock
|
116
|
+
mock.should_receive(:show)
|
117
|
+
@archive.show
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should call list method" do
|
121
|
+
mock = double('Mock')
|
122
|
+
Heirloom::Lister.should_receive(:new).
|
123
|
+
with(:config => @config_mock,
|
124
|
+
:name => 'chef').
|
125
|
+
and_return mock
|
126
|
+
mock.should_receive(:list)
|
127
|
+
@archive.list
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should call cleanup method" do
|
131
|
+
mock = double('Mock')
|
132
|
+
Heirloom::Builder.should_receive(:new).
|
133
|
+
with(:config => @config_mock,
|
134
|
+
:name => 'chef',
|
135
|
+
:id => '123').
|
136
|
+
and_return mock
|
137
|
+
mock.should_receive(:cleanup)
|
138
|
+
@archive.cleanup
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should return true if the required buckets exist" do
|
142
|
+
mock = double('Mock')
|
143
|
+
Heirloom::Verifier.should_receive(:new).
|
144
|
+
with(:config => @config_mock,
|
145
|
+
:name => 'chef').
|
146
|
+
and_return mock
|
147
|
+
mock.should_receive(:buckets_exist?).
|
148
|
+
with(:bucket_prefix => 'test-123').and_return true
|
149
|
+
@archive.buckets_exist?(:bucket_prefix => 'test-123').
|
150
|
+
should be_true
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should return false if the required buckets don't exist" do
|
154
|
+
mock = double('Mock')
|
155
|
+
Heirloom::Verifier.should_receive(:new).
|
156
|
+
with(:config => @config_mock,
|
157
|
+
:name => 'chef').
|
158
|
+
and_return mock
|
159
|
+
mock.should_receive(:buckets_exist?).
|
160
|
+
with(:bucket_prefix => 'test-123').and_return false
|
161
|
+
@archive.buckets_exist?(:bucket_prefix => 'test-123').
|
162
|
+
should be_false
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should call the destroy method" do
|
166
|
+
destroyer_mock = double('destroyer mock')
|
167
|
+
reader_mock = double('reader mock')
|
168
|
+
Heirloom::Reader.should_receive(:new).
|
169
|
+
with(:config => @config_mock,
|
170
|
+
:name => 'chef',
|
171
|
+
:id => '123').
|
172
|
+
and_return reader_mock
|
173
|
+
reader_mock.should_receive(:regions).and_return ['us-west-1', 'us-west-2']
|
174
|
+
Heirloom::Destroyer.should_receive(:new).
|
175
|
+
with(:config => @config_mock,
|
176
|
+
:name => 'chef',
|
177
|
+
:id => '123').
|
178
|
+
and_return destroyer_mock
|
179
|
+
destroyer_mock.should_receive(:destroy).
|
180
|
+
with(:regions => ['us-west-1', 'us-west-2'])
|
181
|
+
@archive.destroy
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should call the regions method for an archive" do
|
185
|
+
mock = double('Mock')
|
186
|
+
Heirloom::Reader.should_receive(:new).
|
187
|
+
with(:config => @config_mock,
|
188
|
+
:name => 'chef',
|
189
|
+
:id => '123').
|
190
|
+
and_return mock
|
191
|
+
mock.should_receive(:regions)
|
192
|
+
@archive.regions
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'heirloom/cli/shared'
|
4
|
+
|
5
|
+
describe Heirloom do
|
6
|
+
before do
|
7
|
+
@logger_mock = mock 'logger'
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should return false if a required array is emtpy" do
|
11
|
+
@logger_mock.should_receive(:error)
|
12
|
+
Heirloom::CLI::Shared.valid_options?(:provided => { :array => [],
|
13
|
+
:string => 'present' },
|
14
|
+
:required => [:array, :string],
|
15
|
+
:logger => @logger_mock).
|
16
|
+
should be_false
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return false if a required string is nil" do
|
20
|
+
@logger_mock.should_receive(:error)
|
21
|
+
Heirloom::CLI::Shared.valid_options?(:provided => { :array => ['present'],
|
22
|
+
:string => nil },
|
23
|
+
:required => [:array, :string],
|
24
|
+
:logger => @logger_mock).
|
25
|
+
should be_false
|
26
|
+
end
|
27
|
+
|
28
|
+
it "shoudl return false if a require string is nil & array is empty" do
|
29
|
+
@logger_mock.should_receive(:error).exactly(2).times
|
30
|
+
Heirloom::CLI::Shared.valid_options?(:provided => { :array => [],
|
31
|
+
:string => nil },
|
32
|
+
:required => [:array, :string],
|
33
|
+
:logger => @logger_mock).
|
34
|
+
should be_false
|
35
|
+
end
|
36
|
+
|
37
|
+
it "shoudl return true if all options are present" do
|
38
|
+
@logger_mock.should_receive(:error).exactly(0).times
|
39
|
+
Heirloom::CLI::Shared.valid_options?(:provided => { :array => ['present'],
|
40
|
+
:string => 'present' },
|
41
|
+
:required => [:array, :string],
|
42
|
+
:logger => @logger_mock).
|
43
|
+
should be_true
|
44
|
+
end
|
45
|
+
end
|