simple_deploy 0.7.2 → 0.7.3

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.
Files changed (89) hide show
  1. data/.gitignore +3 -0
  2. data/CHANGELOG.md +6 -0
  3. data/lib/simple_deploy/aws/cloud_formation/error.rb +32 -0
  4. data/lib/simple_deploy/aws/cloud_formation.rb +76 -0
  5. data/lib/simple_deploy/aws/instance_reader.rb +59 -0
  6. data/lib/simple_deploy/aws/simpledb.rb +52 -0
  7. data/lib/simple_deploy/aws.rb +4 -0
  8. data/lib/simple_deploy/cli/attributes.rb +7 -18
  9. data/lib/simple_deploy/cli/clone.rb +9 -19
  10. data/lib/simple_deploy/cli/create.rb +5 -14
  11. data/lib/simple_deploy/cli/deploy.rb +8 -11
  12. data/lib/simple_deploy/cli/destroy.rb +4 -10
  13. data/lib/simple_deploy/cli/environments.rb +1 -1
  14. data/lib/simple_deploy/cli/events.rb +5 -11
  15. data/lib/simple_deploy/cli/execute.rb +6 -9
  16. data/lib/simple_deploy/cli/instances.rb +4 -9
  17. data/lib/simple_deploy/cli/list.rb +5 -10
  18. data/lib/simple_deploy/cli/outputs.rb +5 -11
  19. data/lib/simple_deploy/cli/parameters.rb +5 -11
  20. data/lib/simple_deploy/cli/protect.rb +5 -10
  21. data/lib/simple_deploy/cli/resources.rb +5 -11
  22. data/lib/simple_deploy/cli/shared.rb +6 -6
  23. data/lib/simple_deploy/cli/status.rb +5 -11
  24. data/lib/simple_deploy/cli/template.rb +8 -13
  25. data/lib/simple_deploy/cli/update.rb +6 -10
  26. data/lib/simple_deploy/configuration.rb +102 -0
  27. data/lib/simple_deploy/entry.rb +71 -0
  28. data/lib/simple_deploy/entry_lister.rb +30 -0
  29. data/lib/simple_deploy/exceptions.rb +8 -0
  30. data/lib/simple_deploy/misc/attribute_merger.rb +2 -5
  31. data/lib/simple_deploy/notifier/campfire.rb +15 -12
  32. data/lib/simple_deploy/notifier.rb +6 -11
  33. data/lib/simple_deploy/stack/deployment/status.rb +5 -3
  34. data/lib/simple_deploy/stack/deployment.rb +8 -10
  35. data/lib/simple_deploy/stack/execute.rb +2 -3
  36. data/lib/simple_deploy/stack/output_mapper.rb +1 -4
  37. data/lib/simple_deploy/stack/ssh.rb +4 -4
  38. data/lib/simple_deploy/stack/{stack_attribute_formater.rb → stack_attribute_formatter.rb} +4 -6
  39. data/lib/simple_deploy/stack/stack_creator.rb +46 -0
  40. data/lib/simple_deploy/stack/stack_destroyer.rb +19 -0
  41. data/lib/simple_deploy/stack/stack_formatter.rb +25 -0
  42. data/lib/simple_deploy/stack/stack_lister.rb +18 -0
  43. data/lib/simple_deploy/stack/stack_reader.rb +56 -0
  44. data/lib/simple_deploy/stack/stack_updater.rb +67 -0
  45. data/lib/simple_deploy/stack/status.rb +53 -0
  46. data/lib/simple_deploy/stack.rb +89 -37
  47. data/lib/simple_deploy/version.rb +1 -1
  48. data/lib/simple_deploy.rb +31 -1
  49. data/simple_deploy.gemspec +6 -3
  50. data/spec/aws/cloud_formation/error_spec.rb +50 -0
  51. data/spec/aws/cloud_formation_spec.rb +207 -0
  52. data/spec/aws/instance_reader_spec.rb +96 -0
  53. data/spec/aws/simpledb_spec.rb +89 -0
  54. data/spec/cli/attributes_spec.rb +5 -15
  55. data/spec/cli/clone_spec.rb +14 -27
  56. data/spec/cli/create_spec.rb +11 -18
  57. data/spec/cli/deploy_spec.rb +24 -63
  58. data/spec/cli/destroy_spec.rb +7 -25
  59. data/spec/cli/outputs_spec.rb +12 -17
  60. data/spec/cli/protect_spec.rb +68 -106
  61. data/spec/cli/shared_spec.rb +12 -15
  62. data/spec/cli/update_spec.rb +9 -27
  63. data/spec/config_spec.rb +47 -14
  64. data/spec/contexts/config_contexts.rb +28 -0
  65. data/spec/contexts/logger_contexts.rb +9 -0
  66. data/spec/contexts/stack_contexts.rb +40 -0
  67. data/spec/entry_lister_spec.rb +31 -0
  68. data/spec/entry_spec.rb +86 -0
  69. data/spec/misc/attribute_merger_spec.rb +3 -8
  70. data/spec/notifier/campfire_spec.rb +21 -61
  71. data/spec/notifier_spec.rb +18 -40
  72. data/spec/spec_helper.rb +10 -0
  73. data/spec/stack/deployment/status_spec.rb +13 -13
  74. data/spec/stack/deployment_spec.rb +26 -21
  75. data/spec/stack/execute_spec.rb +7 -3
  76. data/spec/stack/output_mapper_spec.rb +3 -15
  77. data/spec/stack/ssh_spec.rb +14 -13
  78. data/spec/stack/{stack_attribute_formater_spec.rb → stack_attribute_formatter_spec.rb} +19 -16
  79. data/spec/stack/stack_creator_spec.rb +46 -0
  80. data/spec/stack/stack_destroyer_spec.rb +18 -0
  81. data/spec/stack/stack_formatter_spec.rb +37 -0
  82. data/spec/stack/stack_lister_spec.rb +17 -0
  83. data/spec/stack/stack_reader_spec.rb +81 -0
  84. data/spec/stack/stack_updater_spec.rb +79 -0
  85. data/spec/stack/status_spec.rb +106 -0
  86. data/spec/stack_spec.rb +160 -133
  87. metadata +112 -19
  88. data/.rvmrc +0 -1
  89. data/lib/simple_deploy/config.rb +0 -87
@@ -1,9 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SimpleDeploy::Stack::OutputMapper do
4
+ include_context 'double stubbed logger'
5
+
4
6
  before do
5
7
  @config_mock = mock 'config'
6
- @logger_stub = stub 'logger', :debug => true, :info => true
7
8
 
8
9
  stack1_outputs = [ { 'OutputKey' => 'Test1', 'OutputValue' => 'val1' },
9
10
  { 'OutputKey' => 'Nother', 'OutputValue' => 'another' } ]
@@ -23,8 +24,7 @@ describe SimpleDeploy::Stack::OutputMapper do
23
24
  @template_stub = stub 'template', :parameters => ["Test1", "Test2", "Tests"]
24
25
 
25
26
  @mapper = SimpleDeploy::Stack::OutputMapper.new :config => @config_mock,
26
- :environment => 'default',
27
- :logger => @logger_stub
27
+ :environment => 'default'
28
28
  end
29
29
 
30
30
  context "when provided stacks" do
@@ -37,8 +37,6 @@ describe SimpleDeploy::Stack::OutputMapper do
37
37
  it "should return the outputs which match parameters" do
38
38
  SimpleDeploy::Stack.should_receive(:new).
39
39
  with(:environment => 'default',
40
- :config => @config_mock,
41
- :logger => @logger_stub,
42
40
  :name => 'stack1').
43
41
  and_return @stack1_stub
44
42
  @mapper.should_receive(:sleep)
@@ -50,8 +48,6 @@ describe SimpleDeploy::Stack::OutputMapper do
50
48
  it "should return the outputs which match pluralized parameters" do
51
49
  SimpleDeploy::Stack.should_receive(:new).
52
50
  with(:environment => 'default',
53
- :config => @config_mock,
54
- :logger => @logger_stub,
55
51
  :name => 'stack4').
56
52
  and_return @stack4_stub
57
53
  @mapper.should_receive(:sleep)
@@ -63,14 +59,10 @@ describe SimpleDeploy::Stack::OutputMapper do
63
59
  it "should return the outputs which match parameters from multiple stacks" do
64
60
  SimpleDeploy::Stack.should_receive(:new).
65
61
  with(:environment => 'default',
66
- :config => @config_mock,
67
- :logger => @logger_stub,
68
62
  :name => 'stack1').
69
63
  and_return @stack1_stub
70
64
  SimpleDeploy::Stack.should_receive(:new).
71
65
  with(:environment => 'default',
72
- :config => @config_mock,
73
- :logger => @logger_stub,
74
66
  :name => 'stack2').
75
67
  and_return @stack2_stub
76
68
  @mapper.should_receive(:sleep).exactly(3).times
@@ -82,14 +74,10 @@ describe SimpleDeploy::Stack::OutputMapper do
82
74
  it "should concatenate multiple outputs of same name into CSV" do
83
75
  SimpleDeploy::Stack.should_receive(:new).
84
76
  with(:environment => 'default',
85
- :config => @config_mock,
86
- :logger => @logger_stub,
87
77
  :name => 'stack1').
88
78
  and_return @stack1_stub
89
79
  SimpleDeploy::Stack.should_receive(:new).
90
80
  with(:environment => 'default',
91
- :config => @config_mock,
92
- :logger => @logger_stub,
93
81
  :name => 'stack3').
94
82
  and_return @stack3_stub
95
83
  @mapper.should_receive(:sleep).exactly(3).times
@@ -1,24 +1,21 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SimpleDeploy::Stack::SSH do
4
+ include_context 'stubbed config'
5
+ include_context 'double stubbed logger'
6
+ include_context 'double stubbed stack', :name => 'my_stack',
7
+ :environment => 'my_env'
8
+
4
9
  before do
5
- @stack_mock = mock 'stack'
6
10
  @task_mock = mock 'task'
7
- @config_mock = mock 'config'
8
- @logger_stub = stub 'logger', :debug => true,
9
- :info => true,
10
- :error => true
11
- @config_mock.stub :logger => @logger_stub
12
- @config_mock.should_receive(:region).
13
- with('test-env').
14
- and_return 'test-us-west-1'
15
- @stack_mock.stub :attributes => { :ssh_gateway => false }
16
- @options = { :config => @config_mock,
17
- :instances => ['1.2.3.4', '4.3.2.1'],
11
+ @config_mock.should_receive(:region).and_return 'test-us-west-1'
12
+
13
+ @stack_stub.stub(:attributes).and_return({ :ssh_gateway => false })
14
+ @options = { :instances => ['1.2.3.4', '4.3.2.1'],
18
15
  :environment => 'test-env',
19
16
  :ssh_user => 'user',
20
17
  :ssh_key => 'key',
21
- :stack => @stack_mock,
18
+ :stack => @stack_stub,
22
19
  :name => 'test-stack' }
23
20
  @task_logger_mock = mock 'task_logger'
24
21
  @ssh_options = Hash.new
@@ -26,6 +23,10 @@ describe SimpleDeploy::Stack::SSH do
26
23
  :variables => @ssh_options
27
24
  end
28
25
 
26
+ after do
27
+ SimpleDeploy.release_config
28
+ end
29
+
29
30
  context "when unsuccessful" do
30
31
  it "should return false when no running instances running" do
31
32
  @ssh = SimpleDeploy::Stack::SSH.new @options.merge({ :instances => [] })
@@ -1,26 +1,31 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe SimpleDeploy do
3
+ describe SimpleDeploy::StackAttributeFormatter do
4
+ include_context 'stubbed config'
5
+ include_context 'double stubbed logger'
6
+
4
7
  before do
5
- @logger_mock = mock 'logger mock', :info => 'true'
6
- @config_mock = mock 'config mock', :logger => @logger_mock, :region => 'us-west-1'
8
+ @config_mock.stub(:region).and_return('us-west-1')
7
9
  @config_mock.stub(:artifact_cloud_formation_url).and_return('ChefRepoURL')
8
10
  @config_mock.stub(:artifacts).and_return(['chef_repo', 'cookbooks', 'app'])
9
11
  end
10
12
 
13
+ after do
14
+ SimpleDeploy.release_config
15
+ end
16
+
11
17
  context "when chef_repo unencrypted" do
12
18
  before do
13
- options = { :config => @config_mock,
14
- :environment => 'preprod',
19
+ options = { :environment => 'preprod',
15
20
  :main_attributes => {
16
21
  'chef_repo_bucket_prefix' => 'test-prefix',
17
22
  'chef_repo_domain' => 'test-domain' }
18
23
  }
19
- @formater = SimpleDeploy::StackAttributeFormater.new options
24
+ @formatter = SimpleDeploy::StackAttributeFormatter.new options
20
25
  end
21
26
 
22
27
  it 'should return updated attributes including the un encrypted cloud formation url' do
23
- updates = @formater.updated_attributes([ { 'chef_repo' => 'test123' } ])
28
+ updates = @formatter.updated_attributes([ { 'chef_repo' => 'test123' } ])
24
29
  updates.should == [{ 'chef_repo' => 'test123' },
25
30
  { 'ChefRepoURL' => 's3://test-prefix-us-west-1/test-domain/test123.tar.gz' }]
26
31
  end
@@ -28,18 +33,17 @@ describe SimpleDeploy do
28
33
 
29
34
  context "when main_attributes set chef_repo encrypted" do
30
35
  before do
31
- options = { :config => @config_mock,
32
- :environment => 'preprod',
36
+ options = { :environment => 'preprod',
33
37
  :main_attributes => {
34
38
  'chef_repo_bucket_prefix' => 'test-prefix',
35
39
  'chef_repo_encrypted' => 'true',
36
40
  'chef_repo_domain' => 'test-domain' }
37
41
  }
38
- @formater = SimpleDeploy::StackAttributeFormater.new options
42
+ @formatter = SimpleDeploy::StackAttributeFormatter.new options
39
43
  end
40
44
 
41
45
  it 'should return updated attributes including the encrypted cloud formation url ' do
42
- updates = @formater.updated_attributes([ { 'chef_repo' => 'test123' } ])
46
+ updates = @formatter.updated_attributes([ { 'chef_repo' => 'test123' } ])
43
47
  updates.should == [{ 'chef_repo' => 'test123' },
44
48
  { 'ChefRepoURL' => 's3://test-prefix-us-west-1/test-domain/test123.tar.gz.gpg' }]
45
49
  end
@@ -47,18 +51,17 @@ describe SimpleDeploy do
47
51
 
48
52
  context "when provided attributes set chef_repo encrypted" do
49
53
  before do
50
- options = { :config => @config_mock,
51
- :environment => 'preprod',
54
+ options = { :environment => 'preprod',
52
55
  :main_attributes => {
53
56
  'chef_repo_bucket_prefix' => 'test-prefix',
54
57
  'chef_repo_domain' => 'test-domain' }
55
58
  }
56
- @formater = SimpleDeploy::StackAttributeFormater.new options
59
+ @formatter = SimpleDeploy::StackAttributeFormatter.new options
57
60
  end
58
61
 
59
62
  it 'should return updated attributes including the encrypted cloud formation url ' do
60
- updates = @formater.updated_attributes([ { 'chef_repo' => 'test123' },
61
- { 'chef_repo_encrypted' => 'true' } ])
63
+ updates = @formatter.updated_attributes([ { 'chef_repo' => 'test123' },
64
+ { 'chef_repo_encrypted' => 'true' } ])
62
65
  updates.should == [{ 'chef_repo' => 'test123' },
63
66
  { 'chef_repo_encrypted' => 'true' },
64
67
  { 'ChefRepoURL' => 's3://test-prefix-us-west-1/test-domain/test123.tar.gz.gpg' }]
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+
4
+ describe SimpleDeploy::StackCreator do
5
+ include_context 'stubbed config'
6
+ include_context 'double stubbed logger'
7
+
8
+ before do
9
+ @attributes = { "param1" => "value1", "param3" => "value3" }
10
+ @template_json = '{ "Parameters":
11
+ {
12
+ "param1" :
13
+ {
14
+ "Description" : "param-1"
15
+ },
16
+ "param2" :
17
+ {
18
+ "Description" : "param-2"
19
+ }
20
+ }
21
+ }'
22
+ end
23
+
24
+ it "should map the attributes to a template's parameters and create a stack " do
25
+ entry_mock = mock 'entry mock'
26
+ file_mock = mock 'file mock'
27
+ cloud_formation_mock = mock 'cloud formation mock'
28
+
29
+ SimpleDeploy::AWS::CloudFormation.should_receive(:new).
30
+ and_return cloud_formation_mock
31
+ File.should_receive(:open).with('path_to_file').
32
+ and_return file_mock
33
+ file_mock.should_receive(:read).and_return @template_json
34
+ entry_mock.should_receive(:attributes).and_return @attributes
35
+ cloud_formation_mock.should_receive(:create).
36
+ with(:name => 'test-stack',
37
+ :parameters => { 'param1' => 'value1' },
38
+ :template => @template_json)
39
+ stack_creator = SimpleDeploy::StackCreator.new :name => 'test-stack',
40
+ :template_file => 'path_to_file',
41
+ :entry => entry_mock
42
+
43
+ stack_creator.create
44
+ end
45
+
46
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe SimpleDeploy::StackDestroyer do
4
+ include_context 'stubbed config'
5
+ include_context 'double stubbed logger'
6
+
7
+ it "should destroy the stack" do
8
+ cloud_formation_mock = mock 'cloud formation mock'
9
+
10
+ SimpleDeploy::AWS::CloudFormation.should_receive(:new).
11
+ and_return cloud_formation_mock
12
+ cloud_formation_mock.should_receive(:destroy).with 'test-stack'
13
+
14
+ stack_destroyer = SimpleDeploy::StackDestroyer.new :name => 'test-stack'
15
+ stack_destroyer.destroy
16
+ end
17
+
18
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe ::SimpleDeploy::StackFormatter do
4
+ include_context 'double stubbed config', :access_key => 'key',
5
+ :secret_key => 'XXX',
6
+ :region => 'us-west-1'
7
+
8
+ before do
9
+ @logger_stub = stub 'logger stub', :info => 'true', :warn => 'true'
10
+
11
+ @stack_reader_mock = mock 'StackReader'
12
+ SimpleDeploy::StackReader.stub(:new).and_return(@stack_reader_mock)
13
+ @stack_reader_mock.stub(:attributes).and_return(:chef_repo_bucket_prefix => 'chef_repo_bp')
14
+ @stack_reader_mock.stub(:outputs).and_return([{'key' => 'value'}])
15
+ @stack_reader_mock.stub(:status).and_return('green')
16
+ @stack_reader_mock.stub(:events).and_return(['event1', 'event2', 'event3'])
17
+ @stack_reader_mock.stub(:resources).and_return([{'StackName' => 'my_stack'}])
18
+
19
+ @stack_formatter = SimpleDeploy::StackFormatter.new(:name => 'my_stack')
20
+ end
21
+
22
+ after do
23
+ SimpleDeploy.release_config
24
+ end
25
+
26
+ describe 'display' do
27
+ it 'should return formatted information for the stack' do
28
+ @stack_formatter.display.should == {
29
+ 'attributes' => { :chef_repo_bucket_prefix => 'chef_repo_bp' },
30
+ 'status' => 'green',
31
+ 'outputs' => [{'key' => 'value'}],
32
+ 'events' => ['event1', 'event2', 'event3'],
33
+ 'resources' => [{'StackName' => 'my_stack'}]
34
+ }
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe SimpleDeploy::StackLister do
4
+ include_context 'stubbed config'
5
+
6
+ it "should list the stack entries" do
7
+ entry_lister_mock = mock 'entry lister mock'
8
+
9
+ SimpleDeploy::EntryLister.should_receive(:new).
10
+ and_return entry_lister_mock
11
+ entry_lister_mock.should_receive(:all)
12
+
13
+ stack_lister = SimpleDeploy::StackLister.new
14
+ stack_lister.all
15
+ end
16
+
17
+ end
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+
3
+ describe SimpleDeploy::StackReader do
4
+ include_context 'double stubbed config', :access_key => 'key',
5
+ :secret_key => 'XXX',
6
+ :region => 'us-west-1'
7
+
8
+ before do
9
+ @logger_stub = stub 'logger stub', :info => 'true', :warn => 'true'
10
+
11
+ @entry_mock = mock 'Entry'
12
+ @entry_mock.stub(:attributes).and_return(:chef_repo_bucket_prefix => 'chef_repo_bp')
13
+ SimpleDeploy::Entry.stub(:new).and_return(@entry_mock)
14
+
15
+ @cf_mock = mock 'CloudFormation'
16
+ SimpleDeploy::AWS::CloudFormation.stub(:new).and_return(@cf_mock)
17
+ @cf_mock.stub(:stack_outputs).and_return([{'key' => 'value'}])
18
+ @cf_mock.stub(:stack_status).and_return('green')
19
+ @cf_mock.stub(:stack_events).and_return(['event1', 'event2'])
20
+ @cf_mock.stub(:stack_resources).and_return([{'StackName' => 'my_stack'}])
21
+ @cf_mock.stub(:template).and_return('{"Parameters": {"EIP": "string"}}')
22
+
23
+ @instance_reader_mock = mock 'InstanceReader'
24
+ SimpleDeploy::AWS::InstanceReader.stub(:new).and_return(@instance_reader_mock)
25
+ @instance_reader_mock.stub(:list_stack_instances).and_return(['instance1', 'instance2'])
26
+
27
+ @stack_reader = SimpleDeploy::StackReader.new(:name => 'my_stack', :logger => @logger_stub)
28
+ end
29
+
30
+ after do
31
+ SimpleDeploy.release_config
32
+ end
33
+
34
+ describe 'attributes' do
35
+ it 'should return the stack attributes' do
36
+ @stack_reader.attributes.should == { :chef_repo_bucket_prefix => 'chef_repo_bp' }
37
+ end
38
+ end
39
+
40
+ describe 'outputs' do
41
+ it 'should return the stack outputs' do
42
+ @stack_reader.outputs.should == [{'key' => 'value'}]
43
+ end
44
+ end
45
+
46
+ describe 'status' do
47
+ it 'should return the stack status' do
48
+ @stack_reader.status.should == 'green'
49
+ end
50
+ end
51
+
52
+ describe 'events' do
53
+ it 'should return the stack events' do
54
+ @stack_reader.events(2).should == ['event1', 'event2']
55
+ end
56
+ end
57
+
58
+ describe 'resources' do
59
+ it 'should return the stack resources' do
60
+ @stack_reader.resources.should == [{'StackName' => 'my_stack'}]
61
+ end
62
+ end
63
+
64
+ describe 'template' do
65
+ it 'should return the stack template' do
66
+ @stack_reader.template.should == '{"Parameters": {"EIP": "string"}}'
67
+ end
68
+ end
69
+
70
+ describe 'parameters' do
71
+ it 'should return the stack parameters' do
72
+ @stack_reader.parameters.should == ['EIP']
73
+ end
74
+ end
75
+
76
+ describe 'instances' do
77
+ it 'should return the stack instances' do
78
+ @stack_reader.instances.should == ['instance1', 'instance2']
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+
4
+ describe SimpleDeploy::StackUpdater do
5
+ include_context 'stubbed config'
6
+ include_context 'double stubbed logger'
7
+
8
+ before do
9
+ @template_body = '{ "Parameters":
10
+ {
11
+ "param1" :
12
+ {
13
+ "Description" : "param-1"
14
+ },
15
+ "param2" :
16
+ {
17
+ "Description" : "param-2"
18
+ }
19
+ }
20
+ }'
21
+ end
22
+
23
+ it "should update the stack when parameters change and stack is stable" do
24
+ attributes = { "param1" => "value1", "param3" => "value3" }
25
+ entry_mock = mock 'entry mock'
26
+ status_mock = mock 'status mock'
27
+ cloud_formation_mock = mock 'cloud formation mock'
28
+ SimpleDeploy::AWS::CloudFormation.should_receive(:new).
29
+ and_return cloud_formation_mock
30
+ entry_mock.should_receive(:attributes).and_return attributes
31
+ cloud_formation_mock.should_receive(:update).
32
+ with(:name => 'test-stack',
33
+ :parameters => { 'param1' => 'value1' },
34
+ :template => @template_body).
35
+ and_return true
36
+ SimpleDeploy::Status.should_receive(:new).
37
+ with(:name => 'test-stack').
38
+ and_return status_mock
39
+ status_mock.should_receive(:wait_for_stable).and_return true
40
+ stack_updater = SimpleDeploy::StackUpdater.new :name => 'test-stack',
41
+ :template_body => @template_body,
42
+ :entry => entry_mock
43
+
44
+ stack_updater.update_stack_if_parameters_changed( [ { 'param1' => 'new-value' } ] ).
45
+ should == true
46
+ end
47
+
48
+ it "should raise an error when parameters change and stack is not stable" do
49
+ attributes = { "param1" => "value1", "param3" => "value3" }
50
+ entry_mock = mock 'entry mock'
51
+ status_mock = mock 'status mock'
52
+ cloud_formation_mock = mock 'cloud formation mock'
53
+ SimpleDeploy::AWS::CloudFormation.should_receive(:new).
54
+ exactly(0).times
55
+ SimpleDeploy::Status.should_receive(:new).
56
+ with(:name => 'test-stack').
57
+ and_return status_mock
58
+ status_mock.should_receive(:wait_for_stable).and_return false
59
+ stack_updater = SimpleDeploy::StackUpdater.new :name => 'test-stack',
60
+ :template_body => @template_body,
61
+ :entry => entry_mock
62
+
63
+ lambda {stack_updater.update_stack_if_parameters_changed( [ { 'param1' => 'new-value' } ] ) }.
64
+ should raise_error
65
+ end
66
+
67
+ it "should not update the stack when parameters don't change" do
68
+ attributes = { "param3" => "value3" }
69
+ entry_mock = mock 'entry mock'
70
+ SimpleDeploy::AWS::CloudFormation.should_receive(:new).exactly(0).times
71
+ stack_updater = SimpleDeploy::StackUpdater.new :name => 'test-stack',
72
+ :template_body => @template_body,
73
+ :entry => entry_mock
74
+
75
+ stack_updater.update_stack_if_parameters_changed( [ { 'another-param' => 'new-value' } ] ).
76
+ should == false
77
+ end
78
+
79
+ end