Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add aws.StringValue wrapper to prevent crash on missing environment name #10074

Merged
merged 2 commits into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aws/ecs_task_definition_equivalency.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (cd containerDefinitions) Reduce(isAWSVPC bool) error {

// Deal with fields which may be re-ordered in the API
sort.Slice(def.Environment, func(i, j int) bool {
return *def.Environment[i].Name < *def.Environment[j].Name
return aws.StringValue(def.Environment[i].Name) < aws.StringValue(def.Environment[j].Name)
})

// Create a mutable copy
Expand Down
87 changes: 87 additions & 0 deletions aws/ecs_task_definition_equivalency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,3 +474,90 @@ func TestAwsEcsContainerDefinitionsAreEquivalent_negative(t *testing.T) {
t.Fatal("Expected definitions to differ.")
}
}

func TestAwsEcsContainerDefinitionsAreEquivalent_missingEnvironmentName(t *testing.T) {
cfgRepresention := `
[
{
"name": "wordpress",
"links": [
"mysql"
],
"image": "wordpress",
"essential": true,
"portMappings": [
{
"containerPort": 80,
"hostPort": 80
}
],
"memory": 500,
"cpu": 10
},
{
"environment": [
{
"value": "password"
},
{
"value": "password2"
}
],
"name": "mysql",
"image": "mysql",
"cpu": 10,
"memory": 500,
"essential": true
}
]`

apiRepresentation := `
[
{
"name": "wordpress",
"image": "wordpress",
"cpu": 10,
"memory": 500,
"links": [
"mysql"
],
"portMappings": [
{
"containerPort": 80,
"hostPort": 80,
"protocol": "tcp"
}
],
"essential": true,
"environment": [],
"mountPoints": [],
"volumesFrom": []
},
{
"name": "mysql",
"image": "mysql",
"cpu": 10,
"memory": 500,
"portMappings": [],
"essential": true,
"environment": [
{
"value": "password"
},
{
"value": "password2"
}
],
"mountPoints": [],
"volumesFrom": []
}
]`

equal, err := EcsContainerDefinitionsAreEquivalent(cfgRepresention, apiRepresentation, false)
if err != nil {
t.Fatal(err)
}
if !equal {
t.Fatal("Expected definitions to be equal.")
}
}