@@ -25,6 +25,12 @@ def s3_env_vars()
25
25
}
26
26
end
27
27
28
+ def github_env_vars ( )
29
+ return {
30
+ "BUNDLE_COMMIT" => @githubRevision [ "CommitId" ]
31
+ }
32
+ end
33
+
28
34
context 'The CodeDeploy Plugin Command Executor' do
29
35
setup do
30
36
@test_hook_mapping = { "BeforeBlockTraffic" => [ "BeforeBlockTraffic" ] ,
@@ -69,6 +75,11 @@ def s3_env_vars()
69
75
"Key" => "mykey" ,
70
76
"BundleType" => "tar"
71
77
}
78
+ @githubRevision = {
79
+ 'Account' => 'account' ,
80
+ 'Repository' => 'repository' ,
81
+ 'CommitId' => 'commitid' ,
82
+ }
72
83
@file_exists_behavior = "RETAIN"
73
84
@agent_actions_overrides_map = { "FileExistsBehavior" => @file_exists_behavior }
74
85
@agent_actions_overrides = { "AgentOverrides" => @agent_actions_overrides_map }
@@ -126,10 +137,15 @@ def s3_env_vars()
126
137
end
127
138
end
128
139
129
- context "when executing a valid command" do
140
+ context "when executing a valid non-hardcoded command" do
130
141
setup do
131
- @command . command_name = "Install"
132
- @command_executor . stubs ( :install )
142
+ @command . command_name = "ValidateService"
143
+ @command_executor . stubs ( :validate_service )
144
+
145
+ @app_spec = mock ( "parsed application specification" )
146
+ File . stubs ( :exist? ) . with ( "#@archive_root_dir /appspec.yml" ) . returns ( true )
147
+ File . stubs ( :read ) . with ( "#@archive_root_dir /appspec.yml" ) . returns ( "APP SPEC" )
148
+ ApplicationSpecification ::ApplicationSpecification . stubs ( :parse ) . with ( "APP SPEC" ) . returns ( @app_spec )
133
149
end
134
150
135
151
should "create the deployment root directory" do
@@ -138,8 +154,45 @@ def s3_env_vars()
138
154
@command_executor . execute_command ( @command , @deployment_spec )
139
155
end
140
156
141
- should "not be a noop command" do
142
- assert_false @command_executor . is_command_noop? ( @command . command_name , @deployment_spec )
157
+ context "when the bundle is from github" do
158
+ setup do
159
+ @deployment_spec = generate_signed_message_for ( {
160
+ "DeploymentId" => @deployment_id . to_s ,
161
+ "DeploymentGroupId" => @deployment_group_id . to_s ,
162
+ "ApplicationName" => @application_name ,
163
+ "DeploymentCreator" => @deployment_creator ,
164
+ "DeploymentGroupName" => @deployment_group_name ,
165
+ "Revision" => {
166
+ "RevisionType" => "GitHub" ,
167
+ "GitHubRevision" => @githubRevision
168
+ }
169
+ } )
170
+
171
+ @hook_executor_constructor_hash = {
172
+ :lifecycle_event => @command . command_name ,
173
+ :application_name => @application_name ,
174
+ :deployment_id => @deployment_id ,
175
+ :deployment_group_name => @deployment_group_name ,
176
+ :deployment_group_id => @deployment_group_id ,
177
+ :deployment_creator => @deployment_creator ,
178
+ :deployment_type => @deployment_type ,
179
+ :deployment_root_dir => @deployment_root_dir ,
180
+ :last_successful_deployment_dir => nil ,
181
+ :most_recent_deployment_dir => nil ,
182
+ :app_spec_path => 'appspec.yml' ,
183
+ :revision_envs => github_env_vars ( ) }
184
+ @mock_hook_executor = mock
185
+ @command_executor . unstub ( :validate_service )
186
+ @command_executor . stubs ( :last_successful_deployment_dir ) . returns ( nil )
187
+ @command_executor . stubs ( :most_recent_deployment_dir ) . returns ( nil )
188
+ end
189
+
190
+ should "create a hook executor with the commit hash as an environment variable" do
191
+ HookExecutor . expects ( :new ) . with ( @hook_executor_constructor_hash ) . returns ( @mock_hook_executor )
192
+ @mock_hook_executor . expects ( :execute )
193
+
194
+ @command_executor . execute_command ( @command , @deployment_spec )
195
+ end
143
196
end
144
197
145
198
context "when failed to create root directory" do
0 commit comments