@@ -25,6 +25,12 @@ def s3_env_vars()
2525 }
2626 end
2727
28+ def github_env_vars ( )
29+ return {
30+ "BUNDLE_COMMIT" => @githubRevision [ "CommitId" ]
31+ }
32+ end
33+
2834 context 'The CodeDeploy Plugin Command Executor' do
2935 setup do
3036 @test_hook_mapping = { "BeforeBlockTraffic" => [ "BeforeBlockTraffic" ] ,
@@ -69,6 +75,11 @@ def s3_env_vars()
6975 "Key" => "mykey" ,
7076 "BundleType" => "tar"
7177 }
78+ @githubRevision = {
79+ 'Account' => 'account' ,
80+ 'Repository' => 'repository' ,
81+ 'CommitId' => 'commitid' ,
82+ }
7283 @file_exists_behavior = "RETAIN"
7384 @agent_actions_overrides_map = { "FileExistsBehavior" => @file_exists_behavior }
7485 @agent_actions_overrides = { "AgentOverrides" => @agent_actions_overrides_map }
@@ -126,10 +137,15 @@ def s3_env_vars()
126137 end
127138 end
128139
129- context "when executing a valid command" do
140+ context "when executing a valid non-hardcoded command" do
130141 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 )
133149 end
134150
135151 should "create the deployment root directory" do
@@ -138,8 +154,45 @@ def s3_env_vars()
138154 @command_executor . execute_command ( @command , @deployment_spec )
139155 end
140156
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
143196 end
144197
145198 context "when failed to create root directory" do
0 commit comments