From 31c9195a1204c0da56cbfebd5135cafe774989f1 Mon Sep 17 00:00:00 2001 From: ashmrtn Date: Tue, 14 Feb 2023 09:56:26 -0800 Subject: [PATCH] Proof of concept wrapper for suite.Suite (#2410) ## Description Proof of concept for how to wrap suite.Suite and insert our own logic for determining if a test should be skipped or not. Adds a new env var for running only integration tests May require future work to add unit tests with the same (non-default) labels as their integration tests ## Does this PR need a docs update or release note? - [ ] :white_check_mark: Yes, it's included - [ ] :clock1: Yes, but in a later PR - [x] :no_entry: No ## Type of change - [ ] :sunflower: Feature - [ ] :bug: Bugfix - [ ] :world_map: Documentation - [x] :robot: Test - [ ] :computer: CI/Deployment - [x] :broom: Tech Debt/Cleanup ## Issue(s) * #2373 ## Test Plan - [ ] :muscle: Manual - [x] :zap: Unit test - [ ] :green_heart: E2E --- .../graph_connector_disconnected_test.go | 31 ++++++++++---- src/internal/tester/integration_runners.go | 2 +- src/internal/tester/suite.go | 42 +++++++++++++++++++ 3 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 src/internal/tester/suite.go diff --git a/src/internal/connector/graph_connector_disconnected_test.go b/src/internal/connector/graph_connector_disconnected_test.go index 774e8a050..226ac2904 100644 --- a/src/internal/connector/graph_connector_disconnected_test.go +++ b/src/internal/connector/graph_connector_disconnected_test.go @@ -22,12 +22,15 @@ import ( // Disconnected Test Section // --------------------------------------------------------------- type DisconnectedGraphConnectorSuite struct { - suite.Suite + tester.Suite } func TestDisconnectedGraphSuite(t *testing.T) { - tester.LogTimeOfTest(t) - suite.Run(t, new(DisconnectedGraphConnectorSuite)) + s := &DisconnectedGraphConnectorSuite{ + Suite: tester.NewUnitSuite(t), + } + + suite.Run(t, s) } func (suite *DisconnectedGraphConnectorSuite) TestBadConnection() { @@ -66,8 +69,15 @@ func (suite *DisconnectedGraphConnectorSuite) TestBadConnection() { } for _, test := range table { - suite.T().Run(test.name, func(t *testing.T) { - gc, err := NewGraphConnector(ctx, graph.HTTPClient(graph.NoTimeout()), test.acct(t), Users, fault.New(true)) + suite.Run(test.name, func() { + t := suite.T() + + gc, err := NewGraphConnector( + ctx, + graph.HTTPClient(graph.NoTimeout()), + test.acct(t), + Users, + fault.New(true)) assert.Nil(t, gc, test.name+" failed") assert.NotNil(t, err, test.name+" failed") }) @@ -108,13 +118,16 @@ func (suite *DisconnectedGraphConnectorSuite) TestGraphConnector_Status() { go statusTestTask(&gc, 4, 1, 1) gc.AwaitStatus() - suite.NotEmpty(gc.PrintableStatus()) + + t := suite.T() + + assert.NotEmpty(t, gc.PrintableStatus()) // Expect 8 objects - suite.Equal(8, gc.Status().ObjectCount) + assert.Equal(t, 8, gc.Status().ObjectCount) // Expect 2 success - suite.Equal(2, gc.Status().Successful) + assert.Equal(t, 2, gc.Status().Successful) // Expect 2 folders - suite.Equal(2, gc.Status().FolderCount) + assert.Equal(t, 2, gc.Status().FolderCount) } func (suite *DisconnectedGraphConnectorSuite) TestVerifyBackupInputs() { diff --git a/src/internal/tester/integration_runners.go b/src/internal/tester/integration_runners.go index e35aedcdb..2b982edaf 100644 --- a/src/internal/tester/integration_runners.go +++ b/src/internal/tester/integration_runners.go @@ -52,7 +52,7 @@ func RunOnAny(t *testing.T, tests ...string) { if l == 0 { t.Skipf( - "one or more env vars mus be flagged to run this test: %v", + "one or more env vars must be flagged to run this test: %v", strings.Join(tests, ", ")) } } diff --git a/src/internal/tester/suite.go b/src/internal/tester/suite.go new file mode 100644 index 000000000..9552ea13d --- /dev/null +++ b/src/internal/tester/suite.go @@ -0,0 +1,42 @@ +package tester + +import ( + "testing" + + "github.com/stretchr/testify/suite" +) + +type Suite interface { + suite.TestingSuite + Run(name string, subtest func()) bool +} + +func NewUnitSuite(t *testing.T) *unitSuite { + return new(unitSuite) +} + +type unitSuite struct { + suite.Suite +} + +func NewIntegrationSuite( + t *testing.T, + envSets [][]string, + includeGroups ...string, +) *integrationSuite { + RunOnAny( + t, + append( + []string{CorsoCITests}, + includeGroups..., + )..., + ) + + MustGetEnvSets(t, envSets...) + + return new(integrationSuite) +} + +type integrationSuite struct { + suite.Suite +}