Skip to content
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
14 changes: 14 additions & 0 deletions pkg/cmd/task/wait/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,21 @@ func WaitRun(out io.Writer, taskIDs []string, getServerTasksCallback ServerTasks
}

pendingTaskIDs := make([]string, 0)
failedTaskIDs := make([]string, 0)
for _, t := range tasks {
if t.IsCompleted == nil || !*t.IsCompleted {
pendingTaskIDs = append(pendingTaskIDs, t.ID)
}
if t.FinishedSuccessfully != nil && !*t.FinishedSuccessfully {
failedTaskIDs = append(failedTaskIDs, t.ID)
}
fmt.Fprintf(out, "%s: %s\n", t.Description, t.State)
}

if len(pendingTaskIDs) == 0 {
if len(failedTaskIDs) != 0 {
return fmt.Errorf("One or more deployment tasks failed.")
}
return nil
}

Expand All @@ -99,11 +106,18 @@ func WaitRun(out io.Writer, taskIDs []string, getServerTasksCallback ServerTasks
}
for _, t := range tasks {
if t.IsCompleted != nil && *t.IsCompleted {
if t.FinishedSuccessfully != nil && !*t.FinishedSuccessfully {
failedTaskIDs = append(failedTaskIDs, t.ID)
}
fmt.Fprintf(out, "%s: %s\n", t.Description, t.State)
pendingTaskIDs = removeTaskID(pendingTaskIDs, t.ID)
}
}
}
if len(failedTaskIDs) != 0 {
gotError <- fmt.Errorf("One or more deployment tasks failed.")
return
}
done <- true
}()

Expand Down
77 changes: 76 additions & 1 deletion pkg/cmd/task/wait/wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestWait(t *testing.T) {
tasks.NewTask(),
}

// bool vars as bool contsants can't be used as pointers for IsCompleted
// bool vars as bool constants can't be used as pointers for IsCompleted
boolFalse := false
boolTrue := true

Expand Down Expand Up @@ -73,3 +73,78 @@ func TestWait(t *testing.T) {
`)
assert.Equal(t, expectedOutput, out.String())
}

func TestWait_FailedTask(t *testing.T) {
out := bytes.Buffer{}
defaultTaskIDs := []string{
"TaskID1",
}

taskList := []*tasks.Task{
tasks.NewTask(),
}

// bool vars as bool constants can't be used as pointers for IsCompleted
boolFalse := false
boolTrue := true

taskList[0].ID = defaultTaskIDs[0]
taskList[0].IsCompleted = &boolTrue
taskList[0].FinishedSuccessfully = &boolFalse
taskList[0].Description = "Deploy Bar 1 release 0.0.2 to Foo"
taskList[0].State = "Failed"

getServerTaskCallback := func(taskIDs []string) ([]*tasks.Task, error) {
return taskList, nil
}
err := taskWaitCreate.WaitRun(&out, defaultTaskIDs, getServerTaskCallback, taskWaitCreate.DefaultTimeout)
assert.EqualError(t, err, "One or more deployment tasks failed.")
expectedOutput := heredoc.Doc(`
Deploy Bar 1 release 0.0.2 to Foo: Failed
`)
assert.Equal(t, expectedOutput, out.String())
}

func TestWait_FailedPendingTask(t *testing.T) {
out := bytes.Buffer{}
defaultTaskIDs := []string{
"TaskID1",
}

taskList := []*tasks.Task{
tasks.NewTask(),
}

// bool vars as bool constants can't be used as pointers for IsCompleted
boolFalse := false
boolTrue := true

taskList[0].ID = defaultTaskIDs[0]
taskList[0].IsCompleted = &boolFalse
taskList[0].Description = "Deploy Bar 1 release 0.0.2 to Foo"
taskList[0].State = "Executing"

timesCalled := 0

getServerTaskCallback := func(taskIDs []string) ([]*tasks.Task, error) {
timesCalled += 1
switch timesCalled {
case 1:
return taskList, nil
case 2:
taskList[0].IsCompleted = &boolTrue
taskList[0].FinishedSuccessfully = &boolFalse
taskList[0].State = "Failed"
return taskList, nil
}
return nil, fmt.Errorf("getServerTaskCallback was called more then the expected amount of times")
}
err := taskWaitCreate.WaitRun(&out, defaultTaskIDs, getServerTaskCallback, taskWaitCreate.DefaultTimeout)
assert.EqualError(t, err, "One or more deployment tasks failed.")
assert.Equal(t, 2, timesCalled)
expectedOutput := heredoc.Doc(`
Deploy Bar 1 release 0.0.2 to Foo: Executing
Deploy Bar 1 release 0.0.2 to Foo: Failed
`)
assert.Equal(t, expectedOutput, out.String())
}