diff --git a/pkg/app/app.go b/pkg/app/app.go index 57dd175f..72a1b123 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -140,11 +140,22 @@ func RealMain(opts types.Options, d types.Deployer, tester types.Tester) (result } test.SetEnv(envsForTester...) + + var testErr error if !opts.SkipTestJUnitReport() { - return writer.WrapStep("Test", test.Run) + testErr = writer.WrapStep("Test", test.Run) + } else { + testErr = test.Run() } - return test.Run() - } + if dWithPostTester, ok := d.(types.DeployerWithPostTester); ok { + if err := dWithPostTester.PostTest(testErr); err != nil { + return err + } + } + if testErr != nil { + return testErr + } + } return nil } diff --git a/pkg/types/types.go b/pkg/types/types.go index 6f919205..526a5666 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -103,6 +103,16 @@ type DeployerWithProvider interface { Provider() string } +// DeployerWithPostTester adds the ability to define after-test behavior +// based on the results of the test. +type DeployerWithPostTester interface { + Deployer + + // PostTest runs after the tester completes. + // testErr is the error returned from the tester's Run() + PostTest(testErr error) error +} + // Tester defines the "interface" between kubetest2 and a tester // The tester is executed as a separate binary during the Test() phase type Tester struct {