heirloom 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/CHANGELOG +7 -0
  2. data/README.md +1 -1
  3. data/Rakefile +6 -0
  4. data/lib/heirloom/archive/builder.rb +29 -29
  5. data/lib/heirloom/archive/destroyer.rb +27 -18
  6. data/lib/heirloom/archive/downloader.rb +12 -14
  7. data/lib/heirloom/archive/lister.rb +2 -1
  8. data/lib/heirloom/archive/reader.rb +22 -15
  9. data/lib/heirloom/archive/updater.rb +2 -1
  10. data/lib/heirloom/archive.rb +5 -2
  11. data/lib/heirloom/aws/simpledb.rb +15 -2
  12. data/lib/heirloom/cli/authorize.rb +12 -7
  13. data/lib/heirloom/cli/build.rb +29 -20
  14. data/lib/heirloom/cli/destroy.rb +11 -4
  15. data/lib/heirloom/cli/download.rb +11 -4
  16. data/lib/heirloom/cli/list.rb +15 -6
  17. data/lib/heirloom/cli/shared.rb +10 -1
  18. data/lib/heirloom/cli/show.rb +14 -5
  19. data/lib/heirloom/cli/update.rb +14 -6
  20. data/lib/heirloom/cli.rb +1 -2
  21. data/lib/heirloom/directory/directory.rb +16 -18
  22. data/lib/heirloom/directory/git_directory.rb +1 -1
  23. data/lib/heirloom/uploader/s3.rb +4 -3
  24. data/lib/heirloom/version.rb +1 -1
  25. data/spec/archive/builder_spec.rb +60 -58
  26. data/spec/archive/destroyer_spec.rb +9 -10
  27. data/spec/archive/downloader_spec.rb +2 -2
  28. data/spec/archive/lister_spec.rb +1 -1
  29. data/spec/archive/reader_spec.rb +92 -81
  30. data/spec/archive/updater_spec.rb +1 -1
  31. data/spec/archive_spec.rb +15 -6
  32. data/spec/aws/simpledb_spec.rb +35 -0
  33. data/spec/cli/authorize_spec.rb +34 -0
  34. data/spec/cli/build_spec.rb +57 -0
  35. data/spec/cli/destroy_spec.rb +33 -0
  36. data/spec/cli/download_spec.rb +37 -0
  37. data/spec/cli/list_spec.rb +34 -0
  38. data/spec/cli/shared_spec.rb +68 -34
  39. data/spec/cli/show_spec.rb +34 -0
  40. data/spec/cli/update_spec.rb +37 -0
  41. data/spec/directory/directory_spec.rb +13 -20
  42. data/spec/directory/git_directory_spec.rb +23 -22
  43. metadata +28 -14
@@ -5,102 +5,113 @@ describe Heirloom do
5
5
  before do
6
6
  @sdb_mock = mock 'sdb'
7
7
  @config_mock = double 'config'
8
- @logger_mock = double 'logger'
9
- @config_mock.should_receive(:logger).and_return @logger_mock
8
+ @logger_stub = stub :debug => true
9
+ @config_mock.should_receive(:logger).and_return @logger_stub
10
10
  Heirloom::AWS::SimpleDB.should_receive(:new).and_return @sdb_mock
11
11
  @reader = Heirloom::Reader.new :config => @config_mock,
12
12
  :name => 'tim',
13
13
  :id => '123'
14
14
  end
15
15
 
16
- it "should show the item record" do
17
- @sdb_mock.should_receive(:select).
18
- with("select * from tim where itemName() = '123'").
19
- and_return( { '123' => { 'value' => [ 'details' ] } } )
20
- @reader.show.should == { 'value' => 'details' }
21
- end
16
+ context "domain does exist" do
17
+ before do
18
+ @sdb_mock.stub :domain_exists? => true
19
+ end
22
20
 
23
- it "should return an empty hash if item does not exist" do
24
- @sdb_mock.should_receive(:select).
25
- with("select * from tim where itemName() = '123'").
26
- and_return({})
27
- @reader.show.should == {}
28
- end
21
+ it "should show the item record" do
22
+ @sdb_mock.should_receive(:select).
23
+ with("select * from heirloom_tim where itemName() = '123'").
24
+ and_return( { '123' => { 'value' => [ 'details' ] } } )
25
+ @reader.show.should == { 'value' => 'details' }
26
+ end
29
27
 
30
- it "should return true if the record exists" do
31
- @sdb_mock.should_receive(:select).
32
- with("select * from tim where itemName() = '123'").
33
- and_return( { '123' => { 'value' => [ 'details' ] } } )
34
- @logger_mock.should_receive(:debug).exactly(1).times
35
- @reader.exists?.should == true
36
- end
28
+ it "should return an empty hash if item does not exist" do
29
+ @sdb_mock.should_receive(:select).
30
+ with("select * from heirloom_tim where itemName() = '123'").
31
+ and_return({})
32
+ @reader.show.should == {}
33
+ end
37
34
 
38
- it "should return false if the recrod does not exist" do
39
- @sdb_mock.should_receive(:select).
40
- with("select * from tim where itemName() = '123'").
41
- and_return({})
42
- @logger_mock.should_receive(:debug).exactly(1).times
43
- @reader.exists?.should == false
44
- end
35
+ it "should return true if the record exists" do
36
+ @sdb_mock.should_receive(:select).
37
+ with("select * from heirloom_tim where itemName() = '123'").
38
+ and_return( { '123' => { 'value' => [ 'details' ] } } )
39
+ @reader.exists?.should == true
40
+ end
45
41
 
46
- it "should return the bucket if it exists" do
47
- @logger_mock.should_receive(:debug).exactly(5).times
48
- @sdb_mock.should_receive(:select).
49
- exactly(3).times.
50
- with("select * from tim where itemName() = '123'").
51
- and_return( { '123' =>
52
- { 'us-west-1-s3-url' =>
53
- [ 's3://the-bucket/the-buck/the-key' ]
54
- }
55
- } )
56
- @reader.get_bucket(:region => 'us-west-1').should == 'the-bucket'
57
- end
42
+ it "should return false if the record does not exist" do
43
+ @sdb_mock.should_receive(:select).
44
+ with("select * from heirloom_tim where itemName() = '123'").
45
+ and_return({})
46
+ @reader.exists?.should == false
47
+ end
58
48
 
59
- it "should return nil if the bucket does not exist" do
60
- @logger_mock.should_receive(:debug).exactly(3).times
61
- @sdb_mock.should_receive(:select).
62
- exactly(1).times.
63
- with("select * from tim where itemName() = '123'").
64
- and_return( { } )
65
- @reader.get_bucket(:region => 'us-west-1').should == nil
66
- end
49
+ it "should return the bucket if it exists" do
50
+ @sdb_mock.should_receive(:select).
51
+ exactly(3).times.
52
+ with("select * from heirloom_tim where itemName() = '123'").
53
+ and_return( { '123' =>
54
+ { 'us-west-1-s3-url' =>
55
+ [ 's3://the-bucket/the-buck/the-key' ]
56
+ }
57
+ } )
58
+ @reader.get_bucket(:region => 'us-west-1').should == 'the-bucket'
59
+ end
67
60
 
68
- it "should return the key if it exists" do
69
- @logger_mock.should_receive(:debug).exactly(8).times
70
- @sdb_mock.should_receive(:select).
71
- exactly(6).times.
72
- with("select * from tim where itemName() = '123'").
73
- and_return( { '123' =>
74
- { 'us-west-1-s3-url' =>
75
- ['s3://the-url/the-bucket/the-key']
76
- }
77
- } )
78
- @reader.get_key(:region => 'us-west-1').should == 'the-bucket/the-key'
79
- end
61
+ it "should return nil if the key does not exist" do
62
+ @sdb_mock.should_receive(:select).
63
+ exactly(1).times.
64
+ with("select * from heirloom_tim where itemName() = '123'").
65
+ and_return( { } )
66
+ @reader.get_key(:region => 'us-west-1').should == nil
67
+ end
68
+
69
+ it "should return nil if the bucket does not exist" do
70
+ @sdb_mock.should_receive(:select).
71
+ exactly(1).times.
72
+ with("select * from heirloom_tim where itemName() = '123'").
73
+ and_return( { } )
74
+ @reader.get_bucket(:region => 'us-west-1').should == nil
75
+ end
76
+
77
+ it "should return the key if it exists" do
78
+ @sdb_mock.should_receive(:select).
79
+ exactly(6).times.
80
+ with("select * from heirloom_tim where itemName() = '123'").
81
+ and_return( { '123' =>
82
+ { 'us-west-1-s3-url' =>
83
+ ['s3://the-url/the-bucket/the-key']
84
+ }
85
+ } )
86
+ @reader.get_key(:region => 'us-west-1').should == 'the-bucket/the-key'
87
+ end
88
+
89
+ it "should return the regions the archive has been uploaded to" do
90
+ @sdb_mock.should_receive(:select).
91
+ exactly(1).times.
92
+ with("select * from heirloom_tim where itemName() = '123'").
93
+ and_return( { '123' =>
94
+ { 'us-west-1-s3-url' =>
95
+ ['s3://the-url-us-west-1/the-bucket/the-key'],
96
+ 'build_by' =>
97
+ ['user'],
98
+ 'us-east-1-s3-url' =>
99
+ ['s3://the-url-us-east-1/the-bucket/the-key']
100
+ }
101
+ } )
102
+ @reader.regions.should == ['us-west-1', 'us-east-1']
103
+ end
80
104
 
81
- it "should return nil if the key does not exist" do
82
- @logger_mock.should_receive(:debug).exactly(1).times
83
- @sdb_mock.should_receive(:select).
84
- exactly(1).times.
85
- with("select * from tim where itemName() = '123'").
86
- and_return( { } )
87
- @reader.get_key(:region => 'us-west-1').should == nil
88
105
  end
89
106
 
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']
107
+ context "domain does not exist" do
108
+ before do
109
+ @sdb_mock.stub :domain_exists? => false
110
+ end
111
+
112
+ it "should return false if the simpledb domain does not exist" do
113
+ @reader.exists?.should == false
114
+ end
104
115
  end
105
116
 
106
117
  end
@@ -18,7 +18,7 @@ describe Heirloom do
18
18
  with(:config => @config_mock).
19
19
  and_return sdb_mock
20
20
  sdb_mock.should_receive(:put_attributes).
21
- with('tim', '123', { 'attr' => 'val' }, { :replace => 'attr' })
21
+ with('heirloom_tim', '123', { 'attr' => 'val' }, { :replace => 'attr' })
22
22
  @updater.update :attribute => 'attr',
23
23
  :value => 'val'
24
24
  end
data/spec/archive_spec.rb CHANGED
@@ -3,12 +3,10 @@ require 'spec_helper'
3
3
  describe Heirloom do
4
4
 
5
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'
6
+ @config_mock = mock 'config'
7
+ @archive = Heirloom::Archive.new :config => @config_mock,
8
+ :name => 'chef',
9
+ :id => '123'
12
10
  end
13
11
 
14
12
 
@@ -191,5 +189,16 @@ describe Heirloom do
191
189
  mock.should_receive(:regions)
192
190
  @archive.regions
193
191
  end
192
+
193
+ it "should call the count method for an archive" do
194
+ mock = double('Mock')
195
+ Heirloom::Reader.should_receive(:new).
196
+ with(:config => @config_mock,
197
+ :name => 'chef',
198
+ :id => '123').
199
+ and_return mock
200
+ mock.should_receive(:count)
201
+ @archive.count
202
+ end
194
203
  end
195
204
  end
@@ -30,6 +30,11 @@ describe Heirloom do
30
30
  @sdb.create_domain('new_domain')
31
31
  end
32
32
 
33
+ it "should destroy the specified domain" do
34
+ @fog_mock.should_receive(:delete_domain).with('new_domain')
35
+ @sdb.delete_domain('new_domain')
36
+ end
37
+
33
38
  it "should not create a new domain when already exists" do
34
39
  @sdb.should_receive(:domains).and_return(['new_domain'])
35
40
  @fog_mock.should_receive(:create_domain).exactly(0).times
@@ -47,4 +52,34 @@ describe Heirloom do
47
52
  @sdb.delete('domain', 'key')
48
53
  end
49
54
 
55
+ it "should count the number of entries in the domain" do
56
+ body_mock = mock 'return body'
57
+ data = { 'Items' => { 'Domain' => { 'Count' => ['1'] } } }
58
+ @fog_mock.should_receive(:select).
59
+ with('SELECT count(*) FROM heirloom_domain').
60
+ and_return body_mock
61
+ body_mock.should_receive(:body).and_return data
62
+ @sdb.count('heirloom_domain').should == 1
63
+ end
64
+
65
+ it "should return true if no entries for the domain" do
66
+ body_mock = mock 'return body'
67
+ data = { 'Items' => { 'Domain' => { 'Count' => ['0'] } } }
68
+ @fog_mock.should_receive(:select).
69
+ with('SELECT count(*) FROM heirloom_domain').
70
+ and_return body_mock
71
+ body_mock.should_receive(:body).and_return data
72
+ @sdb.domain_empty?('heirloom_domain').should be_true
73
+ end
74
+
75
+ it "should return false if entries exist for the domain" do
76
+ body_mock = mock 'return body'
77
+ data = { 'Items' => { 'Domain' => { 'Count' => ['50'] } } }
78
+ @fog_mock.should_receive(:select).
79
+ with('SELECT count(*) FROM heirloom_domain').
80
+ and_return body_mock
81
+ body_mock.should_receive(:body).and_return data
82
+ @sdb.domain_empty?('heirloom_domain').should be_false
83
+ end
84
+
50
85
  end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+ require 'heirloom/cli'
3
+
4
+ describe Heirloom do
5
+
6
+ before do
7
+ options = { :level => 'info',
8
+ :accounts => ['test@test.com'],
9
+ :name => 'archive_name',
10
+ :id => '1.0.0' }
11
+ @logger_mock = mock 'logger'
12
+ @config_mock = mock 'config'
13
+ @archive_mock = mock 'archive'
14
+ Trollop.stub(:options).and_return options
15
+ Heirloom::HeirloomLogger.should_receive(:new).with(:log_level => 'info').
16
+ and_return @logger_mock
17
+ Heirloom::CLI::Authorize.any_instance.should_receive(:load_config).
18
+ with(:logger => @logger_mock,
19
+ :opts => options).
20
+ and_return @config_mock
21
+ Heirloom::Archive.should_receive(:new).
22
+ with(:id => '1.0.0',
23
+ :name => 'archive_name',
24
+ :config => @config_mock).
25
+ and_return @archive_mock
26
+ @cli_authorize = Heirloom::CLI::Authorize.new
27
+ end
28
+
29
+ it "should authorize an account" do
30
+ @archive_mock.should_receive(:authorize).with ['test@test.com']
31
+ @cli_authorize.authorize
32
+ end
33
+
34
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+ require 'heirloom/cli'
3
+
4
+ describe Heirloom do
5
+
6
+ before do
7
+ options = { :level => 'info',
8
+ :base_prefix => 'base',
9
+ :git => false,
10
+ :exclude => ['exclude1', 'exclude2'],
11
+ :region => ['us-west-1', 'us-west-2'],
12
+ :directory => '/buildme',
13
+ :public => false,
14
+ :name => 'archive_name',
15
+ :id => '1.0.0' }
16
+
17
+ @logger_stub = stub :error => true, :info => true
18
+ @config_mock = mock 'config'
19
+ @archive_mock = mock 'archive'
20
+ Trollop.stub(:options).and_return options
21
+ Heirloom::HeirloomLogger.should_receive(:new).with(:log_level => 'info').
22
+ and_return @logger_stub
23
+ Heirloom::CLI::Build.any_instance.should_receive(:load_config).
24
+ with(:logger => @logger_stub,
25
+ :opts => options).
26
+ and_return @config_mock
27
+ Heirloom::Archive.should_receive(:new).
28
+ with(:id => '1.0.0',
29
+ :name => 'archive_name',
30
+ :config => @config_mock).
31
+ and_return @archive_mock
32
+ @build = Heirloom::CLI::Build.new
33
+ end
34
+
35
+ it "should build an account" do
36
+ @archive_mock.should_receive(:buckets_exist?).
37
+ with(:bucket_prefix => 'base',
38
+ :regions => ["us-west-1", "us-west-2"]).
39
+ and_return true
40
+ @archive_mock.stub :exists? => false
41
+ @archive_mock.should_receive(:build).
42
+ with(:bucket_prefix => 'base',
43
+ :directory => '/buildme',
44
+ :exclude => ["exclude1", "exclude2"],
45
+ :git => false).
46
+ and_return '/tmp/build123.tar.gz'
47
+ @archive_mock.should_receive(:upload).
48
+ with(:bucket_prefix => 'base',
49
+ :regions => ['us-west-1', 'us-west-2'],
50
+ :public_readable => false,
51
+ :file => '/tmp/build123.tar.gz')
52
+ @archive_mock.should_receive(:cleanup)
53
+
54
+ @build.build
55
+ end
56
+
57
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+ require 'heirloom/cli'
3
+
4
+ describe Heirloom do
5
+
6
+ before do
7
+ options = { :name => 'archive_name',
8
+ :id => '1.0.0',
9
+ :level => 'info' }
10
+ @logger_mock = mock 'logger'
11
+ @config_mock = mock 'config'
12
+ @archive_mock = mock 'archive'
13
+ Trollop.stub(:options).and_return options
14
+ Heirloom::HeirloomLogger.should_receive(:new).with(:log_level => 'info').
15
+ and_return @logger_mock
16
+ Heirloom::CLI::Destroy.any_instance.should_receive(:load_config).
17
+ with(:logger => @logger_mock,
18
+ :opts => options).
19
+ and_return @config_mock
20
+ Heirloom::Archive.should_receive(:new).
21
+ with(:id => '1.0.0',
22
+ :name => 'archive_name',
23
+ :config => @config_mock).
24
+ and_return @archive_mock
25
+ @cli_destroy = Heirloom::CLI::Destroy.new
26
+ end
27
+
28
+ it "should destroy an archive" do
29
+ @archive_mock.should_receive(:destroy)
30
+ @cli_destroy.destroy
31
+ end
32
+
33
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+ require 'heirloom/cli'
3
+
4
+ describe Heirloom do
5
+
6
+ before do
7
+ options = { :name => 'archive_name',
8
+ :id => '1.0.0',
9
+ :level => 'info',
10
+ :output => '/tmp/test123',
11
+ :region => 'us-east-1' }
12
+ @logger_mock = mock 'logger'
13
+ @config_mock = mock 'config'
14
+ @archive_mock = mock 'archive'
15
+ Trollop.stub(:options).and_return options
16
+ Heirloom::HeirloomLogger.should_receive(:new).
17
+ with(:log_level => 'info').
18
+ and_return @logger_mock
19
+ Heirloom::CLI::Download.any_instance.should_receive(:load_config).
20
+ with(:logger => @logger_mock,
21
+ :opts => options).
22
+ and_return @config_mock
23
+ Heirloom::Archive.should_receive(:new).
24
+ with(:id => '1.0.0',
25
+ :name => 'archive_name',
26
+ :config => @config_mock).
27
+ and_return @archive_mock
28
+ @cli_download = Heirloom::CLI::Download.new
29
+ end
30
+
31
+ it "should download an archive" do
32
+ @archive_mock.should_receive(:download).with :output => '/tmp/test123',
33
+ :region => 'us-east-1'
34
+ @cli_download.download
35
+ end
36
+
37
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+ require 'heirloom/cli'
3
+
4
+ describe Heirloom do
5
+
6
+ before do
7
+ options = { :name => 'archive_name',
8
+ :level => 'info',
9
+ :count => 100 }
10
+ @logger_stub = stub :debug => true
11
+ @config_mock = mock 'config'
12
+ @archive_mock = mock 'archive'
13
+ Trollop.stub(:options).and_return options
14
+ Heirloom::HeirloomLogger.should_receive(:new).with(:log_level => 'info').
15
+ and_return @logger_stub
16
+ Heirloom::CLI::List.any_instance.should_receive(:load_config).
17
+ with(:logger => @logger_stub,
18
+ :opts => options).
19
+ and_return @config_mock
20
+ Heirloom::Archive.should_receive(:new).
21
+ with(:name => 'archive_name',
22
+ :config => @config_mock).
23
+ and_return @archive_mock
24
+ @archive_mock.should_receive(:count)
25
+ @cli_list = Heirloom::CLI::List.new
26
+ end
27
+
28
+ it "should list ids for given archive" do
29
+ @archive_mock.should_receive(:list).with(100).and_return(['1','2'])
30
+ @cli_list.should_receive(:jj).with ['1','2']
31
+ @cli_list.list
32
+ end
33
+
34
+ end
@@ -1,45 +1,79 @@
1
1
  require 'spec_helper'
2
2
 
3
- require 'heirloom/cli/shared'
3
+ require 'heirloom/cli'
4
4
 
5
5
  describe Heirloom do
6
- before do
7
- @logger_mock = mock 'logger'
8
- end
9
6
 
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
7
+ context "testing valid_options?" do
18
8
 
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
9
+ before do
10
+ @logger_mock = mock 'logger'
11
+ @object = Object.new
12
+ @object.extend Heirloom::CLI::Shared
13
+ end
14
+
15
+ it "should return false if a required array is emtpy" do
16
+ @logger_mock.should_receive(:error)
17
+ @object.valid_options?(:provided => { :array => [],
18
+ :string => 'present' },
19
+ :required => [:array, :string],
20
+ :logger => @logger_mock).should be_false
21
+ end
22
+
23
+ it "should return false if a required string is nil" do
24
+ @logger_mock.should_receive(:error)
25
+ @object.valid_options?(:provided => { :array => ['present'],
26
+ :string => nil },
27
+ :required => [:array, :string],
28
+ :logger => @logger_mock).should be_false
29
+ end
30
+
31
+ it "should return false if a require string is nil & array is empty" do
32
+ @logger_mock.should_receive(:error).exactly(2).times
33
+ @object.valid_options?(:provided => { :array => [],
34
+ :string => nil },
35
+ :required => [:array, :string],
36
+ :logger => @logger_mock).should be_false
37
+ end
27
38
 
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
39
+ it "should return true if all options are present" do
40
+ @logger_mock.should_receive(:error).exactly(0).times
41
+ @object.valid_options?(:provided => { :array => ['present'],
42
+ :string => 'present' },
43
+ :required => [:array, :string],
44
+ :logger => @logger_mock).should be_true
45
+ end
35
46
  end
36
47
 
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
48
+ context "testing load_config" do
49
+
50
+ before do
51
+ @config_mock = mock 'config'
52
+ @logger_mock = mock 'logger'
53
+ @object = Object.new
54
+ @object.extend Heirloom::CLI::Shared
55
+ Heirloom::Config.should_receive(:new).with(:logger => @logger_mock).
56
+ and_return @config_mock
57
+ end
58
+
59
+ it "should return the configuration" do
60
+ @object.load_config(:logger => @logger_mock,
61
+ :opts => {}).should == @config_mock
62
+ end
63
+
64
+ it "should set the access key if specified" do
65
+ opts = { :key => 'the_key',
66
+ :key_given => true }
67
+ @config_mock.should_receive(:access_key=).with 'the_key'
68
+ @object.load_config :logger => @logger_mock, :opts => opts
69
+ end
70
+
71
+ it "should set the secret key if specified" do
72
+ opts = { :secret => 'the_secret',
73
+ :secret_given => true }
74
+ @config_mock.should_receive(:secret_key=).with 'the_secret'
75
+ @object.load_config :logger => @logger_mock, :opts => opts
76
+ end
44
77
  end
78
+
45
79
  end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+ require 'heirloom/cli'
3
+
4
+ describe Heirloom do
5
+
6
+ before do
7
+ options = { :name => 'archive_name',
8
+ :id => '1.0.0',
9
+ :level => 'info' }
10
+ @logger_stub = stub :debug => true
11
+ @config_mock = mock 'config'
12
+ @archive_mock = mock 'archive'
13
+ Trollop.stub(:options).and_return options
14
+ Heirloom::HeirloomLogger.should_receive(:new).with(:log_level => 'info').
15
+ and_return @logger_stub
16
+ Heirloom::CLI::Show.any_instance.should_receive(:load_config).
17
+ with(:logger => @logger_stub,
18
+ :opts => options).
19
+ and_return @config_mock
20
+ Heirloom::Archive.should_receive(:new).
21
+ with(:name => 'archive_name',
22
+ :id => '1.0.0',
23
+ :config => @config_mock).
24
+ and_return @archive_mock
25
+ @cli_show = Heirloom::CLI::Show.new
26
+ end
27
+
28
+ it "should show a given id" do
29
+ @archive_mock.should_receive(:show).and_return( { 'id' => '1.0.0' } )
30
+ @cli_show.should_receive(:jj).with 'id' => '1.0.0'
31
+ @cli_show.show
32
+ end
33
+
34
+ end