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
19 changes: 6 additions & 13 deletions pkg/test/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,19 @@ func (ctx *TestCtx) GetID() string {
}

func (ctx *TestCtx) Cleanup() {
for i := len(ctx.cleanupFns) - 1; i >= 0; i-- {
err := ctx.cleanupFns[i]()
if err != nil {
ctx.t.Errorf("A cleanup function failed with error: (%v)\n", err)
}
}
}

// cleanupNoT is a modified version of Cleanup; does not use t for logging, instead uses log
// intended for use by MainEntry, which does not have a testing.T
func (ctx *TestCtx) cleanupNoT() {
failed := false
for i := len(ctx.cleanupFns) - 1; i >= 0; i-- {
err := ctx.cleanupFns[i]()
if err != nil {
failed = true
log.Errorf("A cleanup function failed with error: (%v)", err)
if ctx.t != nil {
ctx.t.Errorf("A cleanup function failed with error: (%v)\n", err)
} else {
log.Errorf("A cleanup function failed with error: (%v)", err)
}
}
}
if failed {
if ctx.t == nil && failed {
log.Fatal("A cleanup function failed")
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/main_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func MainEntry(m *testing.M) {
log.Infof("Local operator stdout: %s", string(localCmdOutBuf.Bytes()))
log.Infof("Local operator stderr: %s", string(localCmdErrBuf.Bytes()))
}
ctx.cleanupNoT()
ctx.Cleanup()
os.Exit(exitCode)
}()
// create crd
Expand Down