Skip to content

Commit

Permalink
e2e: Run tests as sub-tests
Browse files Browse the repository at this point in the history
Currently, the tests e2e are being from a single `TestSuite` which
iterates through the test definitions calling their respective
functions.

However, if one of these definitions were to fail, the error is reported
towards the upper `TestSuite` test.

This uses testify's `Suite` object ability to run sub-tests (similar to
what `testing.T` provides) and instead uses that.

This way, any errors coming from a sub-test will be reported for that
sub-test and it'll be easier to debug.

One thing to note is that given our usage of testify's `Suite`, we
aren't able to do parallel testing in our e2e tests. In order to enable
this, we'd need to move away from the `Suite` object or use a different
framework.

Signed-off-by: Juan Antonio Osorio Robles <[email protected]>
  • Loading branch information
JAORMX committed Jan 28, 2021
1 parent c665391 commit cd64c5b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 8 additions & 4 deletions test/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ func (e *e2e) TestSecurityProfilesOperator() {
},
}
for _, testCase := range testCases {
e.logf("> Running testcase: %s", testCase.description)
testCase.fn(nodes)
tc := testCase
e.Run("cluster-wide: "+tc.description, func() {
tc.fn(nodes)
})
}

// Clean up cluster-wide deployment to prepare for namespace deployment
Expand Down Expand Up @@ -120,8 +122,10 @@ func (e *e2e) TestSecurityProfilesOperator() {
e.deployOperator(namespaceManifest, namespaceDefaultProfiles)

for _, testCase := range testCases {
e.logf("> Running testcase: %s", testCase.description)
testCase.fn(nodes)
tc := testCase
e.Run("namespaced: "+tc.description, func() {
tc.fn(nodes)
})
}
}

Expand Down
5 changes: 4 additions & 1 deletion test/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ type openShifte2e struct {
skipBuildImages bool
}

// We're unable to use parallel tests because of our usage of testify/suite.
// See https://github.com/stretchr/testify/issues/187
//
// nolint:paralleltest
func TestSuite(t *testing.T) {
t.Parallel()
fmt.Printf("cluster-type: %s\n", clusterType)

switch {
Expand Down

0 comments on commit cd64c5b

Please sign in to comment.