Skip to content

Commit

Permalink
fix: nil error when container doesn't have exit code (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
keroxp authored Nov 5, 2020
1 parent 75272fd commit 16759af
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cli/cage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func main() {
app := cli.NewApp()
app.Name = "canarycage"
app.Version = "3.4.0"
app.Version = "3.4.1"
app.Description = "A gradual roll-out deployment tool for AWS ECS"
ctx := context.Background()
cmds := commands.NewCageCommands(ctx)
Expand Down
7 changes: 5 additions & 2 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (c *cage) Run(ctx context.Context, input *RunInput) (*RunResult, error) {
return nil, err
}
if !containerExistsInDefinition(td, input.Container) {
return nil, fmt.Errorf("'%s' not found in container definitions", *input.Container)
return nil, fmt.Errorf("🚫 '%s' not found in container definitions", *input.Container)
}
o, err := c.ecs.RunTaskWithContext(ctx, &ecs.RunTaskInput{
Cluster: &c.env.Cluster,
Expand Down Expand Up @@ -69,11 +69,14 @@ func (c *cage) Run(ctx context.Context, input *RunInput) (*RunResult, error) {
}
for _, container := range task.Containers {
if *container.Name == *input.Container {
if container.ExitCode == nil {
return nil, fmt.Errorf("🚫 container '%s' hasn't exit", *input.Container)
}
exitCode = *container.ExitCode
goto next
}
}
return nil, fmt.Errorf("container '%s' not found in results", *input.Container)
return nil, fmt.Errorf("🚫 container '%s' not found in results", *input.Container)
}
return nil, fmt.Errorf("🚫 max attempts exceeded")
next:
Expand Down
33 changes: 32 additions & 1 deletion run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,37 @@ func TestCage_Run(t *testing.T) {
assert.Nil(t, result)
assert.EqualError(t, err, "🚫 task exited with 1")
})
t.Run("should error if exit code is nil", func(t *testing.T) {
env := DefaultEnvars()
ctrl := gomock.NewController(t)
defer ctrl.Finish()
overrides := &ecs.TaskOverride{}
container := "container"
ctx := context.Background()
ecsMock := setupForBasic(ctx, ctrl, []*ecs.DescribeTasksOutput{
{Tasks: []*ecs.Task{
{LastStatus: aws.String("STOPPED"),
Containers: []*ecs.Container{{
Name: &container,
ExitCode: nil,
}}},
}},
})
cagecli := NewCage(&Input{
Env: env,
ECS: ecsMock,
ALB: nil,
EC2: nil,
})
newTimer = fakeTimer
defer recoverTimer()
result, err := cagecli.Run(ctx, &RunInput{
Container: &container,
Overrides: overrides,
})
assert.Nil(t, result)
assert.EqualError(t, err, "🚫 container 'container' hasn't exit")
})
t.Run("should error if container doesn't exist in definition", func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
Expand Down Expand Up @@ -166,6 +197,6 @@ func TestCage_Run(t *testing.T) {
Overrides: overrides,
})
assert.Nil(t, result)
assert.EqualError(t, err, "'foo' not found in container definitions")
assert.EqualError(t, err, "🚫 'foo' not found in container definitions")
})
}

0 comments on commit 16759af

Please sign in to comment.