Skip to content

Commit

Permalink
Add DeployerWithPostTester interface
Browse files Browse the repository at this point in the history
This allows the deployer to define after-test behavior based on the results of the test.

Unfortunately PostTest can't be wrapped in writer.WrapStep because PostTest has an error parameter but WrapStep expects `func() error`
  • Loading branch information
rifelpet committed Mar 9, 2021
1 parent 4459c89 commit 4d3506b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
17 changes: 14 additions & 3 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
10 changes: 10 additions & 0 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4d3506b

Please sign in to comment.