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?

- [ ]  Yes, it's included
- [ ] 🕐 Yes, but in a later PR
- [x]  No 

## Type of change

- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [x] 🤖 Test
- [ ] 💻 CI/Deployment
- [x] 🧹 Tech Debt/Cleanup

## Issue(s)

* #2373

## Test Plan

- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
ashmrtn 2023-02-14 09:56:26 -08:00 committed by GitHub
parent 2e128726c0
commit 31c9195a12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 65 additions and 10 deletions

View File

@ -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() {

View File

@ -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, ", "))
}
}

View File

@ -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
}