From d5cdb7203b91c17cf581781dcf24a2a1221751f4 Mon Sep 17 00:00:00 2001 From: Juan Antonio Osorio Robles Date: Thu, 28 Jan 2021 09:33:09 +0200 Subject: [PATCH] e2e: Run tests as sub-tests 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 --- test/e2e_test.go | 12 ++++++++---- test/suite_test.go | 5 ++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/test/e2e_test.go b/test/e2e_test.go index 12113c7cc7..66704ceb8b 100644 --- a/test/e2e_test.go +++ b/test/e2e_test.go @@ -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 @@ -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) + }) } } diff --git a/test/suite_test.go b/test/suite_test.go index 8d8cc5e369..76a6de1c18 100644 --- a/test/suite_test.go +++ b/test/suite_test.go @@ -69,8 +69,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 {