|
14 | 14 | package utils
|
15 | 15 |
|
16 | 16 | import (
|
17 |
| - "fmt" |
18 | 17 | "io/ioutil"
|
19 | 18 | "os"
|
20 | 19 | "reflect"
|
@@ -205,7 +204,6 @@ func TestConvertToTaskDefinition(t *testing.T) {
|
205 | 204 |
|
206 | 205 | // convert
|
207 | 206 | taskDefinition := convertToTaskDefinitionInTest(t, nil, testContainerConfig, taskRoleArn, "")
|
208 |
| - fmt.Printf("TASK DEF: %+v\n\n", taskDefinition) |
209 | 207 | containerDef := *taskDefinition.ContainerDefinitions[0]
|
210 | 208 |
|
211 | 209 | // verify task def fields
|
@@ -629,6 +627,77 @@ task_definition:
|
629 | 627 | assert.Error(t, err, "Expected error if no containers are marked essential")
|
630 | 628 | }
|
631 | 629 |
|
| 630 | +func TestConvertToTaskDefinitionWithECSParams_EssentialDefaultsToTrueWhenNoServicesSpecified(t *testing.T) { |
| 631 | + // We expect essential to be set to be true in the converter |
| 632 | + containerConfigs := testContainerConfigs([]string{"mysql", "wordpress"}) |
| 633 | + ecsParamsString := `version: 1 |
| 634 | +task_definition: |
| 635 | + ecs_network_mode: host` |
| 636 | + |
| 637 | + content := []byte(ecsParamsString) |
| 638 | + |
| 639 | + tmpfile, err := ioutil.TempFile("", "ecs-params") |
| 640 | + assert.NoError(t, err, "Could not create ecs fields tempfile") |
| 641 | + |
| 642 | + defer os.Remove(tmpfile.Name()) |
| 643 | + |
| 644 | + _, err = tmpfile.Write(content) |
| 645 | + assert.NoError(t, err, "Could not write data to ecs fields tempfile") |
| 646 | + |
| 647 | + err = tmpfile.Close() |
| 648 | + assert.NoError(t, err, "Could not close tempfile") |
| 649 | + |
| 650 | + ecsParamsFileName := tmpfile.Name() |
| 651 | + ecsParams, err := ReadECSParams(ecsParamsFileName) |
| 652 | + assert.NoError(t, err, "Could not read ECS Params file") |
| 653 | + |
| 654 | + taskDefinition, err := convertToTaskDefWithEcsParamsInTest(t, nil, containerConfigs, "", ecsParams) |
| 655 | + assert.NoError(t, err, "Unexpected error when no containers are marked essential") |
| 656 | + |
| 657 | + mysql := findContainerByName("mysql", taskDefinition.ContainerDefinitions) |
| 658 | + assert.True(t, *mysql.Essential, "Expected mysql to be essential") |
| 659 | + wordpress := findContainerByName("wordpress", taskDefinition.ContainerDefinitions) |
| 660 | + assert.True(t, *wordpress.Essential, "Expected wordpressto be essential") |
| 661 | +} |
| 662 | + |
| 663 | +func TestConvertToTaskDefinitionWithECSParams_EssentialDefaultsToTrueWhenNotSpecified(t *testing.T) { |
| 664 | + // We expect essential to be set to be true in the unmarshaller |
| 665 | + containerConfigs := testContainerConfigs([]string{"mysql", "wordpress"}) |
| 666 | + ecsParamsString := `version: 1 |
| 667 | +task_definition: |
| 668 | + ecs_network_mode: host |
| 669 | + services: |
| 670 | + wordpress: |
| 671 | + mem_limit: 1000000 |
| 672 | + mysql: |
| 673 | + mem_limit: 1000000` |
| 674 | + |
| 675 | + content := []byte(ecsParamsString) |
| 676 | + |
| 677 | + tmpfile, err := ioutil.TempFile("", "ecs-params") |
| 678 | + assert.NoError(t, err, "Could not create ecs fields tempfile") |
| 679 | + |
| 680 | + defer os.Remove(tmpfile.Name()) |
| 681 | + |
| 682 | + _, err = tmpfile.Write(content) |
| 683 | + assert.NoError(t, err, "Could not write data to ecs fields tempfile") |
| 684 | + |
| 685 | + err = tmpfile.Close() |
| 686 | + assert.NoError(t, err, "Could not close tempfile") |
| 687 | + |
| 688 | + ecsParamsFileName := tmpfile.Name() |
| 689 | + ecsParams, err := ReadECSParams(ecsParamsFileName) |
| 690 | + assert.NoError(t, err, "Could not read ECS Params file") |
| 691 | + |
| 692 | + taskDefinition, err := convertToTaskDefWithEcsParamsInTest(t, nil, containerConfigs, "", ecsParams) |
| 693 | + |
| 694 | + assert.NoError(t, err, "Unexpected error when no containers are marked essential") |
| 695 | + mysql := findContainerByName("mysql", taskDefinition.ContainerDefinitions) |
| 696 | + assert.True(t, *mysql.Essential, "Expected mysql to be essential") |
| 697 | + wordpress := findContainerByName("wordpress", taskDefinition.ContainerDefinitions) |
| 698 | + assert.True(t, *wordpress.Essential, "Expected wordpressto be essential") |
| 699 | +} |
| 700 | + |
632 | 701 | func TestConvertToTaskDefinitionWithECSParamsAndTaskRoleArnFlag(t *testing.T) {
|
633 | 702 | containerConfigs := testContainerConfigs([]string{"mysql", "wordpress"})
|
634 | 703 | ecsParamsString := `version: 1
|
|
0 commit comments