simple_deploy 0.9.2 → 0.10.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/simple_deploy/aws/cloud_formation.rb +5 -5
- data/lib/simple_deploy/aws/helpers.rb +20 -0
- data/lib/simple_deploy/aws/instance_reader.rb +10 -13
- data/lib/simple_deploy/aws/simpledb.rb +5 -5
- data/lib/simple_deploy/aws.rb +1 -0
- data/lib/simple_deploy/cli/attributes.rb +4 -2
- data/lib/simple_deploy/cli/clone.rb +8 -3
- data/lib/simple_deploy/cli/create.rb +4 -2
- data/lib/simple_deploy/cli/deploy.rb +4 -2
- data/lib/simple_deploy/cli/destroy.rb +4 -2
- data/lib/simple_deploy/cli/events.rb +4 -2
- data/lib/simple_deploy/cli/execute.rb +4 -2
- data/lib/simple_deploy/cli/instances.rb +4 -2
- data/lib/simple_deploy/cli/list.rb +5 -2
- data/lib/simple_deploy/cli/outputs.rb +4 -2
- data/lib/simple_deploy/cli/parameters.rb +4 -2
- data/lib/simple_deploy/cli/protect.rb +4 -2
- data/lib/simple_deploy/cli/resources.rb +4 -2
- data/lib/simple_deploy/cli/shared.rb +34 -2
- data/lib/simple_deploy/cli/status.rb +4 -2
- data/lib/simple_deploy/cli/template.rb +4 -2
- data/lib/simple_deploy/cli/update.rb +4 -2
- data/lib/simple_deploy/configuration.rb +39 -4
- data/lib/simple_deploy/version.rb +1 -1
- data/spec/aws/cloud_formation_spec.rb +162 -135
- data/spec/aws/helpers_spec.rb +51 -0
- data/spec/aws/instance_reader_spec.rb +181 -167
- data/spec/aws/simpledb_spec.rb +78 -50
- data/spec/cli/attributes_spec.rb +22 -2
- data/spec/cli/clone_spec.rb +7 -8
- data/spec/cli/deploy_spec.rb +7 -10
- data/spec/cli/destroy_spec.rb +3 -4
- data/spec/cli/protect_spec.rb +7 -11
- data/spec/cli/shared_spec.rb +107 -17
- data/spec/cli/update_spec.rb +4 -7
- data/spec/config_spec.rb +50 -3
- metadata +7 -4
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class TestObj
|
4
|
+
include SimpleDeploy::AWS::Helpers
|
5
|
+
attr_accessor :config
|
6
|
+
end
|
7
|
+
|
8
|
+
describe SimpleDeploy::AWS::Helpers do
|
9
|
+
|
10
|
+
describe 'connection_args' do
|
11
|
+
before do
|
12
|
+
@config = stub 'config',
|
13
|
+
access_key: 'key',
|
14
|
+
secret_key: 'XXX',
|
15
|
+
region: 'us-west-1'
|
16
|
+
@obj = TestObj.new
|
17
|
+
|
18
|
+
@args = {
|
19
|
+
aws_access_key_id: 'key',
|
20
|
+
aws_secret_access_key: 'XXX',
|
21
|
+
region: 'us-west-1'
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'with long lived credentials' do
|
26
|
+
before do
|
27
|
+
@config.stub temporary_credentials?: false
|
28
|
+
@obj.config = @config
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'does not include security token' do
|
32
|
+
@obj.connection_args.should eq @args
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'with temporary credentials' do
|
37
|
+
before do
|
38
|
+
@config.stub security_token: 'token'
|
39
|
+
@config.stub temporary_credentials?: true
|
40
|
+
@obj.config = @config
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'includes security security token' do
|
44
|
+
args = @args.merge({aws_session_token: 'token'})
|
45
|
+
@obj.connection_args.should eq args
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -2,207 +2,221 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe SimpleDeploy::AWS::InstanceReader do
|
4
4
|
include_context 'double stubbed logger'
|
5
|
-
include_context 'double stubbed config', :access_key => 'key',
|
6
|
-
:secret_key => 'XXX',
|
7
|
-
:region => 'us-west-1'
|
8
5
|
|
9
|
-
describe
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
@describe_response = stub 'Excon::Response', :body => {
|
24
|
-
'reservationSet' => [{
|
25
|
-
'instanceSet' => [{'instanceState' => {'name' => 'running'}},
|
26
|
-
{'ipAddress' => '54.10.10.1'},
|
27
|
-
{'instanceId' => 'i-123456'},
|
28
|
-
{'privateIpAddress' => '192.168.1.1'}]}]
|
6
|
+
describe 'temporary credentials' do
|
7
|
+
include_context 'double stubbed config', :access_key => 'key',
|
8
|
+
:secret_key => 'XXX',
|
9
|
+
:security_token => 'the token',
|
10
|
+
:temporary_credentials? => true,
|
11
|
+
:region => 'us-west-1'
|
12
|
+
|
13
|
+
it 'creates a connection with the temporary credentials' do
|
14
|
+
args = {
|
15
|
+
aws_access_key_id: 'key',
|
16
|
+
aws_secret_access_key: 'XXX',
|
17
|
+
aws_session_token: 'the token',
|
18
|
+
region: 'us-west-1'
|
29
19
|
}
|
30
|
-
|
31
|
-
|
32
|
-
|
20
|
+
Fog::AWS::AutoScaling.should_receive(:new).with(args)
|
21
|
+
Fog::Compute::AWS.should_receive(:new).with(args)
|
22
|
+
SimpleDeploy::AWS::InstanceReader.new
|
33
23
|
end
|
34
24
|
|
35
|
-
|
36
|
-
before do
|
37
|
-
@cloud_formation_mock.should_receive(:stack_resources).
|
38
|
-
exactly(3).times.
|
39
|
-
with('stack').
|
40
|
-
and_return []
|
41
|
-
end
|
25
|
+
end
|
42
26
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
27
|
+
describe 'with long lived credentials' do
|
28
|
+
include_context 'double stubbed config', :access_key => 'key',
|
29
|
+
:secret_key => 'XXX',
|
30
|
+
:security_token => nil,
|
31
|
+
:temporary_credentials? => false,
|
32
|
+
:region => 'us-west-1'
|
33
|
+
|
34
|
+
before do
|
35
|
+
@auto_scaling_groups_mock = mock 'auto scaling'
|
36
|
+
@cloud_formation_mock = mock 'cloud formation'
|
37
|
+
@ec2_mock = mock 'ec2'
|
38
|
+
Fog::AWS::AutoScaling.stub(:new).and_return @auto_scaling_groups_mock
|
39
|
+
Fog::Compute::AWS.stub(:new).and_return @ec2_mock
|
40
|
+
SimpleDeploy::AWS::CloudFormation.stub(:new).
|
41
|
+
and_return @cloud_formation_mock
|
47
42
|
end
|
48
43
|
|
49
|
-
|
44
|
+
describe "list_stack_instances" do
|
50
45
|
before do
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
'PhysicalResourceId' => asg }
|
56
|
-
end
|
46
|
+
instances = ['first',{ 'Instances' => [{ 'InstanceId' => 'i-000001' },
|
47
|
+
{ 'InstanceId' => 'i-000002' }] }]
|
48
|
+
body = { 'DescribeAutoScalingGroupsResult' => { 'AutoScalingGroups' => instances } }
|
49
|
+
@list_response = stub 'Fog::Response', :body => body, :any? => true
|
57
50
|
|
58
|
-
|
59
|
-
|
60
|
-
with('stack').
|
61
|
-
and_return stack_resource_results
|
51
|
+
empty_body = { 'DescribeAutoScalingGroupsResult' => { 'AutoScalingGroups' => [] } }
|
52
|
+
@empty_response = stub 'Fog::Response', :body => empty_body
|
62
53
|
|
63
|
-
|
64
|
-
|
54
|
+
@describe_response = stub 'Excon::Response', :body => {
|
55
|
+
'reservationSet' => [{
|
56
|
+
'instanceSet' => [{'instanceState' => {'name' => 'running'}},
|
57
|
+
{'ipAddress' => '54.10.10.1'},
|
58
|
+
{'instanceId' => 'i-123456'},
|
59
|
+
{'privateIpAddress' => '192.168.1.1'}]}]
|
60
|
+
}
|
65
61
|
end
|
66
62
|
|
67
|
-
context "with no
|
68
|
-
|
69
|
-
@
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
63
|
+
context "with no ASGs" do
|
64
|
+
before do
|
65
|
+
@cloud_formation_mock.should_receive(:stack_resources).
|
66
|
+
exactly(3).times.
|
67
|
+
with('stack').
|
68
|
+
and_return []
|
69
|
+
end
|
74
70
|
|
71
|
+
it "should return an empty array" do
|
75
72
|
instance_reader = SimpleDeploy::AWS::InstanceReader.new
|
76
73
|
instance_reader.list_stack_instances('stack').should == []
|
77
74
|
end
|
78
75
|
end
|
79
76
|
|
80
|
-
context "with
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
Fog::Compute::AWS.stub(:new).
|
90
|
-
and_return @ec2_mock
|
91
|
-
@ec2_mock.should_receive(:describe_instances).
|
92
|
-
with('instance-state-name' => 'running',
|
93
|
-
'instance-id' => ['i-000001', 'i-000002']).
|
94
|
-
and_return @describe_response
|
77
|
+
context "with an ASGs" do
|
78
|
+
before do
|
79
|
+
stack_resource_results = []
|
80
|
+
@asgs = ['asg1', 'asg2'].each do |asg|
|
81
|
+
stack_resource_results << { 'StackName' => 'stack',
|
82
|
+
'ResourceType' => 'AWS::AutoScaling::AutoScalingGroup',
|
83
|
+
'PhysicalResourceId' => asg }
|
84
|
+
end
|
95
85
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
{'instanceId' => 'i-123456'},
|
101
|
-
{'privateIpAddress' => '192.168.1.1'}]}]
|
86
|
+
@cloud_formation_mock.should_receive(:stack_resources).
|
87
|
+
exactly(3).times.
|
88
|
+
with('stack').
|
89
|
+
and_return stack_resource_results
|
102
90
|
end
|
103
|
-
end
|
104
|
-
end
|
105
91
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
stack_resource_results << { 'StackName' => 'stack',
|
114
|
-
'ResourceType' => 'AWS::CloudFormation::Stack',
|
115
|
-
'PhysicalResourceId' => nested_stack }
|
116
|
-
end
|
117
|
-
@asgs = ['asg1', 'asg2'].each do |asg|
|
118
|
-
stack_resource_results << { 'StackName' => 'stack',
|
119
|
-
'ResourceType' => 'AWS::AutoScaling::AutoScalingGroup',
|
120
|
-
'PhysicalResourceId' => asg }
|
121
|
-
end
|
92
|
+
context "with no running instances" do
|
93
|
+
it "should return empty array" do
|
94
|
+
@asgs.each do |asg|
|
95
|
+
@auto_scaling_groups_mock.should_receive(:describe_auto_scaling_groups).
|
96
|
+
with('AutoScalingGroupNames' => [asg]).
|
97
|
+
and_return(@empty_response)
|
98
|
+
end
|
122
99
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
'PhysicalResourceId' => instance }
|
100
|
+
instance_reader = SimpleDeploy::AWS::InstanceReader.new
|
101
|
+
instance_reader.list_stack_instances('stack').should == []
|
102
|
+
end
|
127
103
|
end
|
128
104
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
105
|
+
context "with running instances" do
|
106
|
+
it "should return the reservation set for each running instance" do
|
107
|
+
@auto_scaling_groups_mock.should_receive(:describe_auto_scaling_groups).
|
108
|
+
with('AutoScalingGroupNames' => ['asg1']).
|
109
|
+
and_return(@list_response)
|
110
|
+
@auto_scaling_groups_mock.should_receive(:describe_auto_scaling_groups).
|
111
|
+
with('AutoScalingGroupNames' => ['asg2']).
|
112
|
+
and_return(@empty_response)
|
113
|
+
@ec2_mock.should_receive(:describe_instances).
|
114
|
+
with('instance-state-name' => 'running',
|
115
|
+
'instance-id' => ['i-000001', 'i-000002']).
|
116
|
+
and_return @describe_response
|
117
|
+
|
118
|
+
instance_reader = SimpleDeploy::AWS::InstanceReader.new
|
119
|
+
instance_reader.list_stack_instances('stack').should == [{
|
120
|
+
'instanceSet' => [{'instanceState' => {'name' => 'running'}},
|
121
|
+
{'ipAddress' => '54.10.10.1'},
|
122
|
+
{'instanceId' => 'i-123456'},
|
123
|
+
{'privateIpAddress' => '192.168.1.1'}]}]
|
124
|
+
end
|
125
|
+
end
|
136
126
|
end
|
137
127
|
|
138
|
-
context "with
|
139
|
-
|
140
|
-
|
128
|
+
context "with nested stacks and ASGs and EC2 instances" do
|
129
|
+
before do
|
130
|
+
stack_resource_results = []
|
131
|
+
@nested_stacks = ['nested_stack1', 'nested_stack2'].each do |nested_stack|
|
132
|
+
@cloud_formation_mock.should_receive(:stack_status).
|
133
|
+
with(nested_stack).
|
134
|
+
and_return 'CREATE_COMPLETE'
|
135
|
+
stack_resource_results << { 'StackName' => 'stack',
|
136
|
+
'ResourceType' => 'AWS::CloudFormation::Stack',
|
137
|
+
'PhysicalResourceId' => nested_stack }
|
138
|
+
end
|
139
|
+
@asgs = ['asg1', 'asg2'].each do |asg|
|
140
|
+
stack_resource_results << { 'StackName' => 'stack',
|
141
|
+
'ResourceType' => 'AWS::AutoScaling::AutoScalingGroup',
|
142
|
+
'PhysicalResourceId' => asg }
|
143
|
+
end
|
141
144
|
|
142
|
-
@
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
nested_stack2_resource_results = []
|
148
|
-
@asgs = ['nested_stack2_asg1', 'nested_stack2_asg2'].each do |nested_stack2_resource_asg|
|
149
|
-
nested_stack2_resource_results << { 'StackName' => 'nested_stack2',
|
150
|
-
'ResourceType' => 'AWS::AutoScaling::AutoScalingGroup',
|
151
|
-
'PhysicalResourceId' => nested_stack2_resource_asg }
|
145
|
+
@instances = ['i-instance1', 'i-instance2'].each do |instance|
|
146
|
+
stack_resource_results << { 'StackName' => 'stack',
|
147
|
+
'ResourceType' => 'AWS::EC2::Instance',
|
148
|
+
'PhysicalResourceId' => instance }
|
152
149
|
end
|
153
150
|
|
154
151
|
@cloud_formation_mock.should_receive(:stack_resources).
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
152
|
+
exactly(3).times.
|
153
|
+
with('stack').
|
154
|
+
and_return stack_resource_results
|
155
|
+
end
|
156
|
+
|
157
|
+
context "with running instances in nested stack and ASG and EC2 instances" do
|
158
|
+
it "should return the reservation set for each running instance" do
|
159
|
+
@cloud_formation_mock.should_receive(:stack_resources).
|
160
|
+
exactly(3).times.
|
161
|
+
with('nested_stack1').
|
162
|
+
and_return []
|
163
|
+
|
164
|
+
nested_stack2_resource_results = []
|
165
|
+
@asgs = ['nested_stack2_asg1', 'nested_stack2_asg2'].each do |nested_stack2_resource_asg|
|
166
|
+
nested_stack2_resource_results << { 'StackName' => 'nested_stack2',
|
167
|
+
'ResourceType' => 'AWS::AutoScaling::AutoScalingGroup',
|
168
|
+
'PhysicalResourceId' => nested_stack2_resource_asg }
|
169
|
+
end
|
170
|
+
|
171
|
+
@cloud_formation_mock.should_receive(:stack_resources).
|
172
|
+
exactly(3).times.
|
173
|
+
with('nested_stack2').
|
174
|
+
and_return nested_stack2_resource_results
|
175
|
+
nested_list_response = stub 'Fog::Response', :body => { 'DescribeAutoScalingGroupsResult' =>
|
159
176
|
{ 'AutoScalingGroups' => ['first',
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
@auto_scaling_groups_mock.should_receive(:describe_auto_scaling_groups).
|
168
|
-
with('AutoScalingGroupNames' => ['nested_stack2_asg2']).
|
169
|
-
and_return(@empty_response)
|
170
|
-
|
171
|
-
|
172
|
-
@auto_scaling_groups_mock.should_receive(:describe_auto_scaling_groups).
|
173
|
-
with('AutoScalingGroupNames' => ['asg1']).
|
174
|
-
and_return(@list_response)
|
175
|
-
@auto_scaling_groups_mock.should_receive(:describe_auto_scaling_groups).
|
176
|
-
with('AutoScalingGroupNames' => ['asg2']).
|
177
|
-
and_return(@empty_response)
|
178
|
-
|
179
|
-
Fog::Compute::AWS.stub(:new).
|
180
|
-
and_return @ec2_mock
|
181
|
-
|
182
|
-
@ec2_mock.should_receive(:describe_instances).
|
183
|
-
with('instance-state-name' => 'running',
|
184
|
-
'instance-id' => ['i-stack001', 'i-stack002']).
|
185
|
-
and_return @describe_response
|
186
|
-
|
187
|
-
@ec2_mock.should_receive(:describe_instances).
|
188
|
-
with('instance-state-name' => 'running',
|
189
|
-
'instance-id' => ['i-000001', 'i-000002','i-instance1', 'i-instance2'] ).
|
190
|
-
and_return @describe_response
|
177
|
+
{ 'Instances' => [{ 'InstanceId' => 'i-stack001' },
|
178
|
+
{ 'InstanceId' => 'i-stack002' }] }] } },
|
179
|
+
:any? => true
|
180
|
+
@auto_scaling_groups_mock.should_receive(:describe_auto_scaling_groups).
|
181
|
+
with('AutoScalingGroupNames' => ['nested_stack2_asg1']).
|
182
|
+
and_return(nested_list_response)
|
191
183
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
184
|
+
@auto_scaling_groups_mock.should_receive(:describe_auto_scaling_groups).
|
185
|
+
with('AutoScalingGroupNames' => ['nested_stack2_asg2']).
|
186
|
+
and_return(@empty_response)
|
187
|
+
|
188
|
+
|
189
|
+
@auto_scaling_groups_mock.should_receive(:describe_auto_scaling_groups).
|
190
|
+
with('AutoScalingGroupNames' => ['asg1']).
|
191
|
+
and_return(@list_response)
|
192
|
+
@auto_scaling_groups_mock.should_receive(:describe_auto_scaling_groups).
|
193
|
+
with('AutoScalingGroupNames' => ['asg2']).
|
194
|
+
and_return(@empty_response)
|
195
|
+
|
196
|
+
@ec2_mock.should_receive(:describe_instances).
|
197
|
+
with('instance-state-name' => 'running',
|
198
|
+
'instance-id' => ['i-stack001', 'i-stack002']).
|
199
|
+
and_return @describe_response
|
200
|
+
|
201
|
+
@ec2_mock.should_receive(:describe_instances).
|
202
|
+
with('instance-state-name' => 'running',
|
203
|
+
'instance-id' => ['i-000001', 'i-000002','i-instance1', 'i-instance2'] ).
|
204
|
+
and_return @describe_response
|
205
|
+
|
206
|
+
instance_reader = SimpleDeploy::AWS::InstanceReader.new
|
207
|
+
instance_reader.list_stack_instances('stack').should == [{
|
208
|
+
'instanceSet' => [{'instanceState' => {'name' => 'running'}},
|
209
|
+
{'ipAddress' => '54.10.10.1'},
|
210
|
+
{'instanceId' => 'i-123456'},
|
211
|
+
{'privateIpAddress' => '192.168.1.1'}]}, {
|
212
|
+
'instanceSet' => [{'instanceState' => {'name' => 'running'}},
|
213
|
+
{'ipAddress' => '54.10.10.1'},
|
214
|
+
{'instanceId' => 'i-123456'},
|
215
|
+
{'privateIpAddress' => '192.168.1.1'}]}]
|
216
|
+
end
|
203
217
|
end
|
204
218
|
end
|
205
|
-
end
|
206
219
|
|
220
|
+
end
|
207
221
|
end
|
208
222
|
end
|
data/spec/aws/simpledb_spec.rb
CHANGED
@@ -6,92 +6,120 @@ describe SimpleDeploy::AWS::SimpleDB do
|
|
6
6
|
:region => 'us-west-1'
|
7
7
|
|
8
8
|
before do
|
9
|
-
@response_stub = stub 'Excon::Response', :body => {
|
9
|
+
@response_stub = stub 'Excon::Response', :body => {
|
10
10
|
'RequestId' => 'rid',
|
11
11
|
'Domains' => ['domain1', 'domain2'],
|
12
12
|
'Items' => { 'item1' => { 'key' => ['value'] } },
|
13
13
|
'NextToken' => nil
|
14
14
|
}
|
15
|
-
@multi_response_stub = stub 'Excon::Response', :body => {
|
15
|
+
@multi_response_stub = stub 'Excon::Response', :body => {
|
16
16
|
'RequestId' => 'rid',
|
17
17
|
'Domains' => ['domain1', 'domain2'],
|
18
18
|
'Items' => { 'item1-2' => { 'key' => ['value'] } },
|
19
19
|
'NextToken' => 'Chunk2'
|
20
20
|
}
|
21
|
-
|
22
|
-
@db_mock = mock 'SimpleDB'
|
23
|
-
Fog::AWS::SimpleDB.stub(:new).and_return(@db_mock)
|
24
|
-
@db_mock.stub(:list_domains).and_return(@response_stub)
|
25
|
-
|
26
|
-
@db = SimpleDeploy::AWS::SimpleDB.new
|
27
21
|
end
|
28
22
|
|
29
|
-
describe '
|
30
|
-
|
31
|
-
|
23
|
+
describe 'temporary credentials' do
|
24
|
+
include_context 'double stubbed config', :access_key => 'key',
|
25
|
+
:secret_key => 'XXX',
|
26
|
+
:security_token => 'the token',
|
27
|
+
:temporary_credentials? => true,
|
28
|
+
:region => 'us-west-1'
|
29
|
+
|
30
|
+
it 'creates a connection with the temporary credentials' do
|
31
|
+
args = {
|
32
|
+
aws_access_key_id: 'key',
|
33
|
+
aws_secret_access_key: 'XXX',
|
34
|
+
aws_session_token: 'the token',
|
35
|
+
region: 'us-west-1'
|
36
|
+
}
|
37
|
+
Fog::AWS::SimpleDB.should_receive(:new).with(args)
|
38
|
+
SimpleDeploy::AWS::SimpleDB.new
|
32
39
|
end
|
33
40
|
end
|
34
41
|
|
35
|
-
describe '
|
36
|
-
|
37
|
-
|
42
|
+
describe 'with long lived credentials' do
|
43
|
+
include_context 'double stubbed config', :access_key => 'key',
|
44
|
+
:secret_key => 'XXX',
|
45
|
+
:security_token => nil,
|
46
|
+
:temporary_credentials? => false,
|
47
|
+
:region => 'us-west-1'
|
48
|
+
before do
|
49
|
+
@db_mock = mock 'SimpleDB'
|
50
|
+
Fog::AWS::SimpleDB.stub(:new).and_return(@db_mock)
|
51
|
+
@db_mock.stub(:list_domains).and_return(@response_stub)
|
52
|
+
|
53
|
+
@db = SimpleDeploy::AWS::SimpleDB.new
|
38
54
|
end
|
39
55
|
|
40
|
-
|
41
|
-
|
56
|
+
describe 'domains' do
|
57
|
+
it 'should return a list of domains' do
|
58
|
+
@db.domains.should == ['domain1', 'domain2']
|
59
|
+
end
|
42
60
|
end
|
43
|
-
end
|
44
61
|
|
45
|
-
|
46
|
-
|
47
|
-
|
62
|
+
describe 'domain_exists?' do
|
63
|
+
it 'should return true for existing domains' do
|
64
|
+
@db.domain_exists?('domain1').should be_true
|
65
|
+
end
|
48
66
|
|
49
|
-
|
67
|
+
it 'should return false for non-existent domains' do
|
68
|
+
@db.domain_exists?('baddomain1').should_not be_true
|
69
|
+
end
|
50
70
|
end
|
51
71
|
|
52
|
-
|
53
|
-
|
72
|
+
describe 'create_domain' do
|
73
|
+
it 'should create a new domain' do
|
74
|
+
@db_mock.should_receive(:create_domain).with('newdomain').and_return(@response_stub)
|
54
75
|
|
55
|
-
|
56
|
-
|
57
|
-
end
|
76
|
+
@db.create_domain('newdomain').body['RequestId'].should == 'rid'
|
77
|
+
end
|
58
78
|
|
59
|
-
|
60
|
-
|
61
|
-
@db_mock.should_receive(:put_attributes).with('domain1', 'item1', { 'key' => 'value' }, {}).and_return(@response_stub)
|
79
|
+
it 'should not create a duplicate domain' do
|
80
|
+
@db_mock.should_not_receive(:create_domain)
|
62
81
|
|
63
|
-
|
82
|
+
@db.create_domain('domain1').should be_nil
|
83
|
+
end
|
64
84
|
end
|
65
|
-
end
|
66
85
|
|
67
|
-
|
68
|
-
|
69
|
-
|
86
|
+
describe 'put_attributes' do
|
87
|
+
it 'should update the specified domain' do
|
88
|
+
@db_mock.should_receive(:put_attributes).with('domain1', 'item1', { 'key' => 'value' }, {}).and_return(@response_stub)
|
70
89
|
|
71
|
-
|
90
|
+
@db.put_attributes('domain1', 'item1', { 'key' => 'value' }, {}).body['RequestId'].should == 'rid'
|
91
|
+
end
|
72
92
|
end
|
73
93
|
|
74
|
-
|
75
|
-
|
76
|
-
|
94
|
+
describe 'select' do
|
95
|
+
it 'should return query items' do
|
96
|
+
@db_mock.should_receive(:select).with('item1', { "ConsistentRead" => true, "NextToken" => nil } ).and_return(@response_stub)
|
97
|
+
|
98
|
+
@db.select('item1').should == { 'item1' => { 'key' => ['value'] } }
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should return multiple chunks of query items' do
|
102
|
+
@db_mock.should_receive(:select).with('item1', { "ConsistentRead" => true, "NextToken" => nil } ).and_return(@multi_response_stub)
|
103
|
+
@db_mock.should_receive(:select).with('item1', { "ConsistentRead" => true, "NextToken" => 'Chunk2' } ).and_return(@response_stub)
|
77
104
|
|
78
|
-
|
105
|
+
@db.select('item1').should == { 'item1' => { 'key' => ['value'] }, 'item1-2' => { 'key' => ['value'] } }
|
106
|
+
end
|
79
107
|
end
|
80
|
-
end
|
81
108
|
|
82
|
-
|
83
|
-
|
84
|
-
|
109
|
+
describe 'delete' do
|
110
|
+
it 'should delete the attributes identified by domain and key' do
|
111
|
+
@db_mock.should_receive(:delete_attributes).with('domain1', 'item1').and_return(@response_stub)
|
85
112
|
|
86
|
-
|
113
|
+
@db.delete('domain1', 'item1').body['RequestId'].should == 'rid'
|
114
|
+
end
|
87
115
|
end
|
88
|
-
end
|
89
|
-
|
90
|
-
describe 'delete_items' do
|
91
|
-
it 'should delete the specific attributes passed associated with domain and key' do
|
92
|
-
@db_mock.should_receive(:delete_attributes).with('domain1', 'item1', {'value'=>nil}).and_return(@response_stub)
|
93
116
|
|
94
|
-
|
117
|
+
describe 'delete_items' do
|
118
|
+
it 'should delete the specific attributes passed associated with domain and key' do
|
119
|
+
@db_mock.should_receive(:delete_attributes).with('domain1', 'item1', {'value'=>nil}).and_return(@response_stub)
|
120
|
+
|
121
|
+
@db.delete_items('domain1', 'item1', {'value'=>nil}).body['RequestId'].should == 'rid'
|
122
|
+
end
|
95
123
|
end
|
96
124
|
end
|
97
125
|
end
|