|
34 | 34 | "AfterAllowTraffic"=>["AfterAllowTraffic"]} |
35 | 35 | DEPLOYMENT_GROUP_ID = 'deployment-group-id' |
36 | 36 | NON_DEFAULT_FILE_EXISTS_BEHAVIOR = 'OVERWRITE' |
| 37 | + SAMPLE_APPLICATION_NAME = 'myapp' |
| 38 | + SAMPLE_DEPLOYMENT_GROUP_NAME = 'mydeploymentgroup' |
| 39 | + |
37 | 40 | let(:test_working_directory) { Dir.mktmpdir } |
38 | 41 |
|
39 | 42 | before do |
@@ -441,16 +444,136 @@ def create_config_file(working_directory, log_dir = nil) |
441 | 444 | end |
442 | 445 | end |
443 | 446 |
|
444 | | - def deployment_spec(location, revision_type, bundle_type, all_possible_lifecycle_events, s3revision_includes_version=false, s3revision_includes_etag=false, deployment_group_id=DEPLOYMENT_GROUP_ID, file_exists_behavior=InstanceAgent::Plugins::CodeDeployPlugin::DeploymentSpecification::DEFAULT_FILE_EXISTS_BEHAVIOR) |
| 447 | + context 'build_spec' do |
| 448 | + context 'when application-name is not in the args' do |
| 449 | + let(:args) do |
| 450 | + {"deploy"=>true, |
| 451 | + '--file-exists-behavior'=>InstanceAgent::Plugins::CodeDeployPlugin::DeploymentSpecification::DEFAULT_FILE_EXISTS_BEHAVIOR, |
| 452 | + "--location"=>true, |
| 453 | + "--bundle-location"=>SAMPLE_FILE_BUNDLE, |
| 454 | + "--type"=>'tgz', |
| 455 | + '--deployment-group'=>DEPLOYMENT_GROUP_ID, |
| 456 | + "--help"=>false, |
| 457 | + "--version"=>false} |
| 458 | + end |
| 459 | + it 'defaults to LocalFleet' do |
| 460 | + allow(File).to receive(:exists?).with(SAMPLE_FILE_BUNDLE).and_return(true) |
| 461 | + executor = double(InstanceAgent::Plugins::CodeDeployPlugin::CommandExecutor) |
| 462 | + |
| 463 | + expect(InstanceAgent::Plugins::CodeDeployPlugin::CommandExecutor).to receive(:new). |
| 464 | + with(:hook_mapping => EXPECTED_HOOK_MAPPING). |
| 465 | + and_return(executor) |
| 466 | + |
| 467 | + AWS::CodeDeploy::Local::Deployer::DEFAULT_ORDERED_LIFECYCLE_EVENTS.each do |name| |
| 468 | + expect(executor).to receive(:execute_command).with( |
| 469 | + OpenStruct.new(:command_name => name), |
| 470 | + deployment_spec(SAMPLE_FILE_BUNDLE, 'Local File', 'tgz', |
| 471 | + AWS::CodeDeploy::Local::Deployer::DEFAULT_ORDERED_LIFECYCLE_EVENTS)).once.ordered |
| 472 | + end |
| 473 | + AWS::CodeDeploy::Local::Deployer.new(@config_file_location).execute_events(args) |
| 474 | + end |
| 475 | + end |
| 476 | + |
| 477 | + context 'when deployment-group-name is not in the args' do |
| 478 | + let(:args) do |
| 479 | + {"deploy"=>true, |
| 480 | + '--file-exists-behavior'=>InstanceAgent::Plugins::CodeDeployPlugin::DeploymentSpecification::DEFAULT_FILE_EXISTS_BEHAVIOR, |
| 481 | + "--location"=>true, |
| 482 | + "--bundle-location"=>SAMPLE_FILE_BUNDLE, |
| 483 | + "--type"=>'tgz', |
| 484 | + '--deployment-group'=>DEPLOYMENT_GROUP_ID, |
| 485 | + "--help"=>false, |
| 486 | + "--version"=>false} |
| 487 | + end |
| 488 | + it 'defaults to the bundle-location' do |
| 489 | + allow(File).to receive(:exists?).with(SAMPLE_FILE_BUNDLE).and_return(true) |
| 490 | + executor = double(InstanceAgent::Plugins::CodeDeployPlugin::CommandExecutor) |
| 491 | + |
| 492 | + expect(InstanceAgent::Plugins::CodeDeployPlugin::CommandExecutor).to receive(:new). |
| 493 | + with(:hook_mapping => EXPECTED_HOOK_MAPPING). |
| 494 | + and_return(executor) |
| 495 | + |
| 496 | + AWS::CodeDeploy::Local::Deployer::DEFAULT_ORDERED_LIFECYCLE_EVENTS.each do |name| |
| 497 | + expect(executor).to receive(:execute_command).with( |
| 498 | + OpenStruct.new(:command_name => name), |
| 499 | + deployment_spec(SAMPLE_FILE_BUNDLE, 'Local File', 'tgz', |
| 500 | + AWS::CodeDeploy::Local::Deployer::DEFAULT_ORDERED_LIFECYCLE_EVENTS)).once.ordered |
| 501 | + end |
| 502 | + AWS::CodeDeploy::Local::Deployer.new(@config_file_location).execute_events(args) |
| 503 | + end |
| 504 | + end |
| 505 | + |
| 506 | + context 'when application-name is in the args' do |
| 507 | + let(:args) do |
| 508 | + {"deploy"=>true, |
| 509 | + '--file-exists-behavior'=>InstanceAgent::Plugins::CodeDeployPlugin::DeploymentSpecification::DEFAULT_FILE_EXISTS_BEHAVIOR, |
| 510 | + "--location"=>true, |
| 511 | + "--bundle-location"=>SAMPLE_FILE_BUNDLE, |
| 512 | + "--type"=>'tgz', |
| 513 | + '--deployment-group'=>DEPLOYMENT_GROUP_ID, |
| 514 | + '--application-name'=> SAMPLE_APPLICATION_NAME, |
| 515 | + "--help"=>false, |
| 516 | + "--version"=>false} |
| 517 | + end |
| 518 | + it 'generates a spec with the provided value' do |
| 519 | + allow(File).to receive(:exists?).with(SAMPLE_FILE_BUNDLE).and_return(true) |
| 520 | + executor = double(InstanceAgent::Plugins::CodeDeployPlugin::CommandExecutor) |
| 521 | + |
| 522 | + expect(InstanceAgent::Plugins::CodeDeployPlugin::CommandExecutor).to receive(:new). |
| 523 | + with(:hook_mapping => EXPECTED_HOOK_MAPPING). |
| 524 | + and_return(executor) |
| 525 | + |
| 526 | + AWS::CodeDeploy::Local::Deployer::DEFAULT_ORDERED_LIFECYCLE_EVENTS.each do |name| |
| 527 | + expect(executor).to receive(:execute_command).with( |
| 528 | + OpenStruct.new(:command_name => name), |
| 529 | + deployment_spec(SAMPLE_FILE_BUNDLE, 'Local File', 'tgz', |
| 530 | + AWS::CodeDeploy::Local::Deployer::DEFAULT_ORDERED_LIFECYCLE_EVENTS, deployment_group_name:nil, application_name:SAMPLE_APPLICATION_NAME)).once.ordered |
| 531 | + end |
| 532 | + AWS::CodeDeploy::Local::Deployer.new(@config_file_location).execute_events(args) |
| 533 | + end |
| 534 | + end |
| 535 | + |
| 536 | + context 'when deployment-group-name is in the args' do |
| 537 | + let(:args) do |
| 538 | + {"deploy"=>true, |
| 539 | + '--file-exists-behavior'=>InstanceAgent::Plugins::CodeDeployPlugin::DeploymentSpecification::DEFAULT_FILE_EXISTS_BEHAVIOR, |
| 540 | + "--location"=>true, |
| 541 | + "--bundle-location"=>SAMPLE_FILE_BUNDLE, |
| 542 | + "--type"=>'tgz', |
| 543 | + '--deployment-group'=>DEPLOYMENT_GROUP_ID, |
| 544 | + '--deployment-group-name'=>SAMPLE_DEPLOYMENT_GROUP_NAME, |
| 545 | + "--help"=>false, |
| 546 | + "--version"=>false} |
| 547 | + end |
| 548 | + it 'generates a spec with the provided value' do |
| 549 | + allow(File).to receive(:exists?).with(SAMPLE_FILE_BUNDLE).and_return(true) |
| 550 | + executor = double(InstanceAgent::Plugins::CodeDeployPlugin::CommandExecutor) |
| 551 | + |
| 552 | + expect(InstanceAgent::Plugins::CodeDeployPlugin::CommandExecutor).to receive(:new). |
| 553 | + with(:hook_mapping => EXPECTED_HOOK_MAPPING). |
| 554 | + and_return(executor) |
| 555 | + |
| 556 | + AWS::CodeDeploy::Local::Deployer::DEFAULT_ORDERED_LIFECYCLE_EVENTS.each do |name| |
| 557 | + expect(executor).to receive(:execute_command).with( |
| 558 | + OpenStruct.new(:command_name => name), |
| 559 | + deployment_spec(SAMPLE_FILE_BUNDLE, 'Local File', 'tgz', |
| 560 | + AWS::CodeDeploy::Local::Deployer::DEFAULT_ORDERED_LIFECYCLE_EVENTS, deployment_group_name:SAMPLE_DEPLOYMENT_GROUP_NAME, application_name: nil)).once.ordered |
| 561 | + end |
| 562 | + AWS::CodeDeploy::Local::Deployer.new(@config_file_location).execute_events(args) |
| 563 | + end |
| 564 | + end |
| 565 | + end |
| 566 | + |
| 567 | + def deployment_spec(location, revision_type, bundle_type, all_possible_lifecycle_events, s3revision_includes_version=false, s3revision_includes_etag=false, deployment_group_id=DEPLOYMENT_GROUP_ID, file_exists_behavior=InstanceAgent::Plugins::CodeDeployPlugin::DeploymentSpecification::DEFAULT_FILE_EXISTS_BEHAVIOR, deployment_group_name:nil, application_name:nil) |
445 | 568 | revision_data_key = revision_data(revision_type, location, bundle_type, s3revision_includes_version, s3revision_includes_etag).keys.first |
446 | 569 | revision_data_value = revision_data(revision_type, location, bundle_type, s3revision_includes_version, s3revision_includes_etag).values.first |
447 | 570 | OpenStruct.new({ |
448 | 571 | :format => "TEXT/JSON", |
449 | 572 | :payload => { |
450 | 573 | "ApplicationId" => location, |
451 | | - "ApplicationName" => location, |
| 574 | + "ApplicationName" => application_name || location, |
452 | 575 | "DeploymentGroupId" => deployment_group_id, |
453 | | - "DeploymentGroupName" => "LocalFleet", |
| 576 | + "DeploymentGroupName" => deployment_group_name || "LocalFleet", |
454 | 577 | "DeploymentId" => TEST_DEPLOYMENT_ID, |
455 | 578 | "AgentActionOverrides" => {"AgentOverrides" => {"FileExistsBehavior" => file_exists_behavior}}, |
456 | 579 | "Revision" => {"RevisionType" => revision_type, |
|
0 commit comments