Skip to content

Commit

Permalink
Update Supervisor test to skip output from retry
Browse files Browse the repository at this point in the history
  • Loading branch information
dilyar85 authored and Timothee Christin committed Nov 15, 2023
1 parent 37c72e2 commit 5b1c078
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
5 changes: 1 addition & 4 deletions builder/vsphere/supervisor/step_watch_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,7 @@ func (s *StepWatchSource) getVMIngressIP(ctx context.Context, logger *PackerLogg
return 5 * time.Second
},
ShouldRetry: func(err error) bool {
if errors.Is(err, context.DeadlineExceeded) {
return false
}
return true
return !errors.Is(err, context.DeadlineExceeded)
},
}.Run(ctx, func(ctx context.Context) error {

Expand Down
21 changes: 15 additions & 6 deletions builder/vsphere/supervisor/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,26 @@ func newBasicTestState(writer *bytes.Buffer) *multistep.BasicStateBag {

func checkOutputLines(t *testing.T, writer *bytes.Buffer, expectedLines []string) {
for _, expected := range expectedLines {
actual, err := writer.ReadString('\n')
actual = strings.TrimSpace(actual)
if err != nil {
t.Fatalf("Failed to read line from writer, err: %s", err.Error())
}
if actual != expected {
if actual := readLine(t, writer); actual != expected {
t.Fatalf("Expected output %q but got %q", expected, actual)
}
}
}

func readLine(t *testing.T, writer *bytes.Buffer) string {
actual, err := writer.ReadString('\n')
if err != nil {
t.Fatalf("Failed to read line from writer, err: %s", err.Error())
}

// Skip "continue checking" line as it can be printed from the retry.
if strings.Contains(actual, "continue checking") {
readLine(t, writer)
}

return strings.TrimSpace(actual)
}

func getTestKubeconfigFile(t *testing.T, namespace string) *os.File {
fakeKubeconfigDataFmt := `
apiVersion: v1
Expand Down

0 comments on commit 5b1c078

Please sign in to comment.