This repository was archived by the owner on Jan 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathaws_ops_works_deployment_test.rb
More file actions
148 lines (125 loc) · 4.55 KB
/
aws_ops_works_deployment_test.rb
File metadata and controls
148 lines (125 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
require File.expand_path('../helper', __FILE__)
class AwsOpsWorksDeploymentTest < Service::TestCase
include Service::HttpTestMethods
def setup
super
AWS.stub!
end
def test_stack_id_sent
response = aws_service.receive_event
assert_equal sample_data['stack_id'], response.request_options[:stack_id]
end
def test_environmental_stack_id_sent
svc = Service::AwsOpsWorks.new(:deployment, sample_data, environmental_payload)
response = svc.receive_event
stack_id = opsworks_deployment_environments['staging']['stack_id']
assert_equal stack_id, response.request_options[:stack_id]
end
def test_stack_id_missing
svc = aws_service(sample_data.except('stack_id'))
assert_raises Service::ConfigurationError do
svc.receive_event
end
end
def test_app_id_sent
response = aws_service.receive_event
assert_equal sample_data['app_id'], response.request_options[:app_id]
end
def test_environmental_app_id_sent
svc = Service::AwsOpsWorks.new(:deployment, sample_data, environmental_payload)
response = svc.receive_event
app_id = opsworks_deployment_environments['staging']['app_id']
assert_equal app_id, response.request_options[:app_id]
end
def test_app_id_missing
svc = aws_service(sample_data.except('app_id'))
assert_raises Service::ConfigurationError do
svc.receive_event
end
end
def test_aws_access_key_id_configured
config = aws_service.ops_works_client.config
assert_equal sample_data['aws_access_key_id'], config.access_key_id
end
def test_aws_access_key_id_missing
svc = aws_service(sample_data.except('aws_access_key_id'))
assert_raises Service::ConfigurationError do
svc.receive_event
end
end
def test_aws_secret_access_key_configured
config = aws_service.ops_works_client.config
assert_equal sample_data['aws_secret_access_key'], config.secret_access_key
end
def test_aws_secret_access_key_missing
svc = aws_service(sample_data.except('aws_secret_access_key'))
assert_raises Service::ConfigurationError do
svc.receive_event
end
end
def test_github_deployment_status_callbacks
github_post_body = {
"state" => "success",
"target_url" => "https://console.aws.amazon.com/opsworks/home?#/stack/12345678-1234-1234-1234-123456789012/deployments",
"description" => "Deployment 721 Accepted by Amazon. (github-services@#{Service.current_sha[0..7]})"
}
github_deployment_path = "/repos/atmos/my-robot/deployments/721/statuses"
@stubs.post github_deployment_path do |env|
assert_equal 'api.github.com', env[:url].host
assert_equal 'https', env[:url].scheme
assert_equal github_post_body, JSON.parse(env[:body])
[200, {}, '']
end
custom_sample_data = sample_data.merge('github_token' => 'secret')
svc = service(:deployment, custom_sample_data, environmental_payload)
response = svc.receive_event
app_id = opsworks_deployment_environments['staging']['app_id']
assert_equal app_id, response.request_options[:app_id]
@stubs.verify_stubbed_calls
end
def aws_service(data = sample_data, payload = sample_payload)
Service::AwsOpsWorks.new(:deployment, data, payload)
end
def service_class
Service::AwsOpsWorks
end
def sample_data
{
'aws_access_key_id' => 'AKIA1234567890123456',
'aws_secret_access_key' => '0123456789+0123456789+0123456789+0123456',
'stack_id' => '12345678-1234-1234-1234-123456789012',
'app_id' => '01234567-0123-0123-0123-012345678901',
'branch_name' => 'default-branch'
}
end
def opsworks_deployment_environments
{
'staging' => {
'app_id' => '01234567-0123-0123-0123-012345678901',
'stack_id' => '12345678-1234-1234-1234-123456789012',
},
'production' => {
'app_id' => '01234567-0123-0123-0123-012345678902',
'stack_id' => '12345678-1234-1234-1234-123456789013',
},
'qa' => {
'app_id' => '01234567-0123-0123-0123-012345678903',
'stack_id' => '12345678-1234-1234-1234-123456789012',
}
}
end
def environmental_payload
custom_payload = {
'environment' => 'staging',
'payload' => {
'config' => {
'opsworks' => opsworks_deployment_environments
}
}
}
Service::DeploymentHelpers.sample_deployment_payload.merge(custom_payload)
end
def sample_payload(branch_name = 'default-branch')
Service::DeploymentHelpers.sample_deployment_payload.merge('ref' => "refs/heads/#{branch_name}")
end
end