diff --git a/test/integration/buildruns_to_taskruns_test.go b/test/integration/buildruns_to_taskruns_test.go index 1fbe39be0a..286d7cd211 100644 --- a/test/integration/buildruns_to_taskruns_test.go +++ b/test/integration/buildruns_to_taskruns_test.go @@ -250,18 +250,21 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() { _, err = tb.GetBRTillStartTime(buildRunObject.Name) Expect(err).To(BeNil()) - actualReason, err := tb.GetTRTillDesiredReason(buildRunObject.Name, "Pending") - Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", "Pending", actualReason)) + expectedReason := "Pending" + actualReason, err := tb.GetTRTillDesiredReason(buildRunObject.Name, expectedReason) + Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason)) - err = tb.GetBRTillDesiredReason(buildRunObject.Name, "Pending") - Expect(err).To(BeNil()) - - actualReason, err = tb.GetTRTillDesiredReason(buildRunObject.Name, "Running") - Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", "Running", actualReason)) + expectedReason = "Pending" + actualReason, err = tb.GetBRTillDesiredReason(buildRunObject.Name, expectedReason) + Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason)) - err = tb.GetBRTillDesiredReason(buildRunObject.Name, "Running") - Expect(err).To(BeNil()) + expectedReason = "Running" + actualReason, err = tb.GetTRTillDesiredReason(buildRunObject.Name, expectedReason) + Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason)) + expectedReason = "Running" + actualReason, err = tb.GetBRTillDesiredReason(buildRunObject.Name, expectedReason) + Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason)) }) }) @@ -281,19 +284,20 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() { _, err = tb.GetBRTillCompletion(buildRunObject.Name) Expect(err).To(BeNil()) - actualReason, err := tb.GetTRTillDesiredReason(buildRunObject.Name, "TaskRunTimeout") - Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", "TaskRunTimeout", actualReason)) + expectedReason := "TaskRunTimeout" + actualReason, err := tb.GetTRTillDesiredReason(buildRunObject.Name, expectedReason) + Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason)) tr, err := tb.GetTaskRunFromBuildRun(buildRunObject.Name) Expect(err).To(BeNil()) - err = tb.GetBRTillDesiredReason(buildRunObject.Name, fmt.Sprintf("TaskRun \"%s\" failed to finish within \"5s\"", tr.Name)) - Expect(err).To(BeNil()) + expectedReason = fmt.Sprintf("TaskRun \"%s\" failed to finish within \"5s\"", tr.Name) + actualReason, err = tb.GetBRTillDesiredReason(buildRunObject.Name, expectedReason) + Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason)) tr, err = tb.GetTaskRunFromBuildRun(buildRunObject.Name) Expect(err).To(BeNil()) Expect(tr.Status.CompletionTime).ToNot(BeNil()) - }) }) @@ -352,12 +356,13 @@ var _ = Describe("Integration tests BuildRuns and TaskRuns", func() { tr, err = tb.UpdateTaskRun(tr) Expect(err).To(BeNil()) - err = tb.GetBRTillDesiredReason(buildRunObject.Name, fmt.Sprintf("TaskRun \"%s\" was cancelled", tr.Name)) - Expect(err).To(BeNil()) - - actualReason, err := tb.GetTRTillDesiredReason(buildRunObject.Name, "TaskRunCancelled") - Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", "TaskRunCancelled", actualReason)) + expectedReason := fmt.Sprintf("TaskRun \"%s\" was cancelled", tr.Name) + actualReason, err := tb.GetBRTillDesiredReason(buildRunObject.Name, expectedReason) + Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason)) + expectedReason = "TaskRunCancelled" + actualReason, err = tb.GetTRTillDesiredReason(buildRunObject.Name, expectedReason) + Expect(err).To(BeNil(), fmt.Sprintf("failed to get desired reason; expected %s, got %s", expectedReason, actualReason)) }) }) }) diff --git a/test/integration/utils/buildruns.go b/test/integration/utils/buildruns.go index a8ee1b1e68..df0595a199 100644 --- a/test/integration/utils/buildruns.go +++ b/test/integration/utils/buildruns.go @@ -123,30 +123,21 @@ func (t *TestBuild) GetBRTillStartTime(name string) (*v1alpha1.BuildRun, error) } // GetBRTillDesiredReason polls until a BuildRun gets a particular Reason -// it exit if an error happens or the timeout is reach -func (t *TestBuild) GetBRTillDesiredReason(buildRunname string, reason string) error { - - var ( - pollBRTillCompletion = func() (bool, error) { - - currentReason, err := t.GetBRReason(buildRunname) - if err != nil { - return false, err - } - if currentReason == reason { - return true, nil - } - - return false, nil +// it exit if an error happens or the timeout is reached +func (t *TestBuild) GetBRTillDesiredReason(buildRunname string, reason string) (currentReason string, err error) { + err = wait.PollImmediate(t.Interval, t.TimeOut, func() (bool, error) { + currentReason, err = t.GetBRReason(buildRunname) + if err != nil { + return false, err + } + if currentReason == reason { + return true, nil } - ) - err := wait.PollImmediate(t.Interval, t.TimeOut, pollBRTillCompletion) - if err != nil { - return err - } + return false, nil + }) - return nil + return } // GetBRTillDeletion polls until a BuildRun is not found, it returns diff --git a/test/integration/utils/taskruns.go b/test/integration/utils/taskruns.go index 67bb02f8e9..5d3bb79fb0 100644 --- a/test/integration/utils/taskruns.go +++ b/test/integration/utils/taskruns.go @@ -63,30 +63,19 @@ func (t *TestBuild) GetTRReason(buildRunName string) (string, error) { // GetTRTillDesiredReason polls until a TaskRun matches a desired Reason // or it exits if an error happen or a timeout is reach. -func (t *TestBuild) GetTRTillDesiredReason(buildRunName string, reason string) (string, error) { - var trReason string - var err error - - var ( - pollTRTillCompletion = func() (bool, error) { - - trReason, err = t.GetTRReason(buildRunName) - if err != nil { - return false, err - } - - if trReason == reason { - return true, nil - } +func (t *TestBuild) GetTRTillDesiredReason(buildRunName string, reason string) (trReason string, err error) { + err = wait.PollImmediate(t.Interval, t.TimeOut, func() (bool, error) { + trReason, err = t.GetTRReason(buildRunName) + if err != nil { + return false, err + } - return false, nil + if trReason == reason { + return true, nil } - ) - pollError := wait.PollImmediate(t.Interval, t.TimeOut, pollTRTillCompletion) - if pollError != nil { - return trReason, pollError - } + return false, nil + }) - return trReason, nil + return }