Use tester suite wrapper in cli package (#2593)

## 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

- [x] 💪 Manual
- [ ]  Unit test
- [ ] 💚 E2E
This commit is contained in:
ashmrtn 2023-02-21 10:12:02 -08:00 committed by GitHub
parent 6e0b9183b4
commit cfc2b2a206
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 207 additions and 169 deletions

View File

@ -39,7 +39,7 @@ var backupDataSets = []path.CategoryType{email, contacts, events}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
type NoBackupExchangeIntegrationSuite struct { type NoBackupExchangeIntegrationSuite struct {
suite.Suite tester.Suite
acct account.Account acct account.Account
st storage.Storage st storage.Storage
vpr *viper.Viper vpr *viper.Viper
@ -50,13 +50,11 @@ type NoBackupExchangeIntegrationSuite struct {
} }
func TestNoBackupExchangeIntegrationSuite(t *testing.T) { func TestNoBackupExchangeIntegrationSuite(t *testing.T) {
tester.RunOnAny( suite.Run(t, &NoBackupExchangeIntegrationSuite{Suite: tester.NewIntegrationSuite(
t, t,
tester.CorsoCITests, [][]string{tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs},
tester.CorsoCLITests, tester.CorsoCLITests,
tester.CorsoCLIBackupTests) tester.CorsoCLIBackupTests)})
suite.Run(t, new(NoBackupExchangeIntegrationSuite))
} }
func (suite *NoBackupExchangeIntegrationSuite) SetupSuite() { func (suite *NoBackupExchangeIntegrationSuite) SetupSuite() {
@ -65,8 +63,6 @@ func (suite *NoBackupExchangeIntegrationSuite) SetupSuite() {
defer flush() defer flush()
tester.MustGetEnvSets(t, tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs)
// prepare common details // prepare common details
suite.acct = tester.NewM365Account(t) suite.acct = tester.NewM365Account(t)
suite.st = tester.NewPrefixedS3Storage(t) suite.st = tester.NewPrefixedS3Storage(t)
@ -123,7 +119,7 @@ func (suite *NoBackupExchangeIntegrationSuite) TestExchangeBackupListCmd_empty()
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
type BackupExchangeIntegrationSuite struct { type BackupExchangeIntegrationSuite struct {
suite.Suite tester.Suite
acct account.Account acct account.Account
st storage.Storage st storage.Storage
vpr *viper.Viper vpr *viper.Viper
@ -133,13 +129,11 @@ type BackupExchangeIntegrationSuite struct {
} }
func TestBackupExchangeIntegrationSuite(t *testing.T) { func TestBackupExchangeIntegrationSuite(t *testing.T) {
tester.RunOnAny( suite.Run(t, &BackupExchangeIntegrationSuite{Suite: tester.NewIntegrationSuite(
t, t,
tester.CorsoCITests, [][]string{tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs},
tester.CorsoCLITests, tester.CorsoCLITests,
tester.CorsoCLIBackupTests) tester.CorsoCLIBackupTests)})
suite.Run(t, new(BackupExchangeIntegrationSuite))
} }
func (suite *BackupExchangeIntegrationSuite) SetupSuite() { func (suite *BackupExchangeIntegrationSuite) SetupSuite() {
@ -148,8 +142,6 @@ func (suite *BackupExchangeIntegrationSuite) SetupSuite() {
defer flush() defer flush()
tester.MustGetEnvSets(t, tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs)
// prepare common details // prepare common details
suite.acct = tester.NewM365Account(t) suite.acct = tester.NewM365Account(t)
suite.st = tester.NewPrefixedS3Storage(t) suite.st = tester.NewPrefixedS3Storage(t)
@ -179,7 +171,9 @@ func (suite *BackupExchangeIntegrationSuite) TestExchangeBackupCmd() {
for _, set := range backupDataSets { for _, set := range backupDataSets {
recorder.Reset() recorder.Reset()
suite.T().Run(set.String(), func(t *testing.T) { suite.Run(set.String(), func() {
t := suite.T()
ctx, flush := tester.NewContext() ctx, flush := tester.NewContext()
ctx = config.SetViper(ctx, suite.vpr) ctx = config.SetViper(ctx, suite.vpr)
defer flush() defer flush()
@ -212,7 +206,7 @@ func (suite *BackupExchangeIntegrationSuite) TestExchangeBackupCmd() {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
type PreparedBackupExchangeIntegrationSuite struct { type PreparedBackupExchangeIntegrationSuite struct {
suite.Suite tester.Suite
acct account.Account acct account.Account
st storage.Storage st storage.Storage
vpr *viper.Viper vpr *viper.Viper
@ -224,18 +218,15 @@ type PreparedBackupExchangeIntegrationSuite struct {
} }
func TestPreparedBackupExchangeIntegrationSuite(t *testing.T) { func TestPreparedBackupExchangeIntegrationSuite(t *testing.T) {
tester.RunOnAny( suite.Run(t, &PreparedBackupExchangeIntegrationSuite{Suite: tester.NewIntegrationSuite(
t, t,
tester.CorsoCITests, [][]string{tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs},
tester.CorsoCLITests, tester.CorsoCLITests,
tester.CorsoCLIBackupTests) tester.CorsoCLIBackupTests)})
suite.Run(t, new(PreparedBackupExchangeIntegrationSuite))
} }
func (suite *PreparedBackupExchangeIntegrationSuite) SetupSuite() { func (suite *PreparedBackupExchangeIntegrationSuite) SetupSuite() {
t := suite.T() t := suite.T()
tester.MustGetEnvSets(t, tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs)
// prepare common details // prepare common details
suite.acct = tester.NewM365Account(t) suite.acct = tester.NewM365Account(t)
@ -309,7 +300,9 @@ func (suite *PreparedBackupExchangeIntegrationSuite) TestExchangeListCmd() {
for _, set := range backupDataSets { for _, set := range backupDataSets {
suite.recorder.Reset() suite.recorder.Reset()
suite.T().Run(set.String(), func(t *testing.T) { suite.Run(set.String(), func() {
t := suite.T()
ctx, flush := tester.NewContext() ctx, flush := tester.NewContext()
ctx = config.SetViper(ctx, suite.vpr) ctx = config.SetViper(ctx, suite.vpr)
defer flush() defer flush()
@ -337,7 +330,9 @@ func (suite *PreparedBackupExchangeIntegrationSuite) TestExchangeListCmd_singleI
for _, set := range backupDataSets { for _, set := range backupDataSets {
suite.recorder.Reset() suite.recorder.Reset()
suite.T().Run(set.String(), func(t *testing.T) { suite.Run(set.String(), func() {
t := suite.T()
ctx, flush := tester.NewContext() ctx, flush := tester.NewContext()
ctx = config.SetViper(ctx, suite.vpr) ctx = config.SetViper(ctx, suite.vpr)
defer flush() defer flush()
@ -366,7 +361,9 @@ func (suite *PreparedBackupExchangeIntegrationSuite) TestExchangeListCmd_singleI
func (suite *PreparedBackupExchangeIntegrationSuite) TestExchangeListCmd_badID() { func (suite *PreparedBackupExchangeIntegrationSuite) TestExchangeListCmd_badID() {
for _, set := range backupDataSets { for _, set := range backupDataSets {
suite.T().Run(set.String(), func(t *testing.T) { suite.Run(set.String(), func() {
t := suite.T()
ctx, flush := tester.NewContext() ctx, flush := tester.NewContext()
ctx = config.SetViper(ctx, suite.vpr) ctx = config.SetViper(ctx, suite.vpr)
defer flush() defer flush()
@ -389,7 +386,9 @@ func (suite *PreparedBackupExchangeIntegrationSuite) TestExchangeDetailsCmd() {
for _, set := range backupDataSets { for _, set := range backupDataSets {
suite.recorder.Reset() suite.recorder.Reset()
suite.T().Run(set.String(), func(t *testing.T) { suite.Run(set.String(), func() {
t := suite.T()
ctx, flush := tester.NewContext() ctx, flush := tester.NewContext()
ctx = config.SetViper(ctx, suite.vpr) ctx = config.SetViper(ctx, suite.vpr)
defer flush() defer flush()
@ -427,8 +426,8 @@ func (suite *PreparedBackupExchangeIntegrationSuite) TestExchangeDetailsCmd() {
continue continue
} }
t.Run(fmt.Sprintf("detail %d", i), func(t *testing.T) { suite.Run(fmt.Sprintf("detail %d", i), func() {
assert.Contains(t, result, ent.ShortRef) assert.Contains(suite.T(), result, ent.ShortRef)
}) })
i++ i++
@ -445,7 +444,7 @@ func (suite *PreparedBackupExchangeIntegrationSuite) TestExchangeDetailsCmd() {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
type BackupDeleteExchangeIntegrationSuite struct { type BackupDeleteExchangeIntegrationSuite struct {
suite.Suite tester.Suite
acct account.Account acct account.Account
st storage.Storage st storage.Storage
vpr *viper.Viper vpr *viper.Viper
@ -455,18 +454,17 @@ type BackupDeleteExchangeIntegrationSuite struct {
} }
func TestBackupDeleteExchangeIntegrationSuite(t *testing.T) { func TestBackupDeleteExchangeIntegrationSuite(t *testing.T) {
tester.RunOnAny( suite.Run(t, &BackupDeleteExchangeIntegrationSuite{
t, Suite: tester.NewIntegrationSuite(
tester.CorsoCITests, t,
tester.CorsoCLITests, [][]string{tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs},
tester.CorsoCLIBackupTests) tester.CorsoCLITests,
tester.CorsoCLIBackupTests),
suite.Run(t, new(BackupDeleteExchangeIntegrationSuite)) })
} }
func (suite *BackupDeleteExchangeIntegrationSuite) SetupSuite() { func (suite *BackupDeleteExchangeIntegrationSuite) SetupSuite() {
t := suite.T() t := suite.T()
tester.MustGetEnvSets(t, tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs)
// prepare common details // prepare common details
suite.acct = tester.NewM365Account(t) suite.acct = tester.NewM365Account(t)

View File

@ -14,11 +14,11 @@ import (
) )
type ExchangeSuite struct { type ExchangeSuite struct {
suite.Suite tester.Suite
} }
func TestExchangeSuite(t *testing.T) { func TestExchangeSuite(t *testing.T) {
suite.Run(t, new(ExchangeSuite)) suite.Run(t, &ExchangeSuite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *ExchangeSuite) TestAddExchangeCommands() { func (suite *ExchangeSuite) TestAddExchangeCommands() {
@ -49,7 +49,9 @@ func (suite *ExchangeSuite) TestAddExchangeCommands() {
}, },
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
t := suite.T()
cmd := &cobra.Command{Use: test.use} cmd := &cobra.Command{Use: test.use}
c := addExchangeCommands(cmd) c := addExchangeCommands(cmd)
@ -94,7 +96,9 @@ func (suite *ExchangeSuite) TestValidateBackupCreateFlags() {
}, },
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
t := suite.T()
test.expect(t, validateExchangeBackupCreateFlags(test.user, test.data)) test.expect(t, validateExchangeBackupCreateFlags(test.user, test.data))
}) })
} }
@ -206,7 +210,9 @@ func (suite *ExchangeSuite) TestExchangeBackupCreateSelectors() {
}, },
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
t := suite.T()
sel := exchangeBackupCreateSelectors(test.user, test.data) sel := exchangeBackupCreateSelectors(test.user, test.data)
assert.Equal(t, test.expectIncludeLen, len(sel.Includes)) assert.Equal(t, test.expectIncludeLen, len(sel.Includes))
}) })
@ -218,7 +224,9 @@ func (suite *ExchangeSuite) TestExchangeBackupDetailsSelectors() {
defer flush() defer flush()
for _, test := range testdata.ExchangeOptionDetailLookups { for _, test := range testdata.ExchangeOptionDetailLookups {
suite.T().Run(test.Name, func(t *testing.T) { suite.Run(test.Name, func() {
t := suite.T()
output, err := runDetailsExchangeCmd( output, err := runDetailsExchangeCmd(
ctx, ctx,
test.BackupGetter, test.BackupGetter,
@ -235,7 +243,9 @@ func (suite *ExchangeSuite) TestExchangeBackupDetailsSelectorsBadFormats() {
defer flush() defer flush()
for _, test := range testdata.BadExchangeOptionsFormats { for _, test := range testdata.BadExchangeOptionsFormats {
suite.T().Run(test.Name, func(t *testing.T) { suite.Run(test.Name, func() {
t := suite.T()
output, err := runDetailsExchangeCmd( output, err := runDetailsExchangeCmd(
ctx, ctx,
test.BackupGetter, test.BackupGetter,

View File

@ -29,7 +29,7 @@ import (
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
type NoBackupOneDriveIntegrationSuite struct { type NoBackupOneDriveIntegrationSuite struct {
suite.Suite tester.Suite
acct account.Account acct account.Account
st storage.Storage st storage.Storage
vpr *viper.Viper vpr *viper.Viper
@ -40,9 +40,13 @@ type NoBackupOneDriveIntegrationSuite struct {
} }
func TestNoBackupOneDriveIntegrationSuite(t *testing.T) { func TestNoBackupOneDriveIntegrationSuite(t *testing.T) {
tester.RunOnAny(t, tester.CorsoCITests, tester.CorsoCLITests, tester.CorsoCLIBackupTests) suite.Run(t, &NoBackupOneDriveIntegrationSuite{
Suite: tester.NewIntegrationSuite(
suite.Run(t, new(NoBackupOneDriveIntegrationSuite)) t,
[][]string{tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs},
tester.CorsoCLITests,
tester.CorsoCLIBackupTests),
})
} }
func (suite *NoBackupOneDriveIntegrationSuite) SetupSuite() { func (suite *NoBackupOneDriveIntegrationSuite) SetupSuite() {
@ -51,8 +55,6 @@ func (suite *NoBackupOneDriveIntegrationSuite) SetupSuite() {
defer flush() defer flush()
tester.MustGetEnvSets(t, tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs)
// prepare common details // prepare common details
suite.acct = tester.NewM365Account(t) suite.acct = tester.NewM365Account(t)
suite.st = tester.NewPrefixedS3Storage(t) suite.st = tester.NewPrefixedS3Storage(t)
@ -114,7 +116,7 @@ func (suite *NoBackupOneDriveIntegrationSuite) TestOneDriveBackupListCmd_empty()
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
type BackupDeleteOneDriveIntegrationSuite struct { type BackupDeleteOneDriveIntegrationSuite struct {
suite.Suite tester.Suite
acct account.Account acct account.Account
st storage.Storage st storage.Storage
vpr *viper.Viper vpr *viper.Viper
@ -125,18 +127,17 @@ type BackupDeleteOneDriveIntegrationSuite struct {
} }
func TestBackupDeleteOneDriveIntegrationSuite(t *testing.T) { func TestBackupDeleteOneDriveIntegrationSuite(t *testing.T) {
tester.RunOnAny( suite.Run(t, &BackupDeleteOneDriveIntegrationSuite{
t, Suite: tester.NewIntegrationSuite(
tester.CorsoCITests, t,
tester.CorsoCLITests, [][]string{tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs},
tester.CorsoCLIBackupTests) tester.CorsoCLITests,
tester.CorsoCLIBackupTests),
suite.Run(t, new(BackupDeleteOneDriveIntegrationSuite)) })
} }
func (suite *BackupDeleteOneDriveIntegrationSuite) SetupSuite() { func (suite *BackupDeleteOneDriveIntegrationSuite) SetupSuite() {
t := suite.T() t := suite.T()
tester.MustGetEnvSets(t, tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs)
// prepare common details // prepare common details
suite.acct = tester.NewM365Account(t) suite.acct = tester.NewM365Account(t)

View File

@ -13,11 +13,11 @@ import (
) )
type OneDriveSuite struct { type OneDriveSuite struct {
suite.Suite tester.Suite
} }
func TestOneDriveSuite(t *testing.T) { func TestOneDriveSuite(t *testing.T) {
suite.Run(t, new(OneDriveSuite)) suite.Run(t, &OneDriveSuite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *OneDriveSuite) TestAddOneDriveCommands() { func (suite *OneDriveSuite) TestAddOneDriveCommands() {
@ -48,7 +48,9 @@ func (suite *OneDriveSuite) TestAddOneDriveCommands() {
}, },
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
t := suite.T()
cmd := &cobra.Command{Use: test.use} cmd := &cobra.Command{Use: test.use}
c := addOneDriveCommands(cmd) c := addOneDriveCommands(cmd)
@ -82,8 +84,8 @@ func (suite *OneDriveSuite) TestValidateOneDriveBackupCreateFlags() {
}, },
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
test.expect(t, validateOneDriveBackupCreateFlags(test.user)) test.expect(suite.T(), validateOneDriveBackupCreateFlags(test.user))
}) })
} }
} }
@ -93,7 +95,9 @@ func (suite *OneDriveSuite) TestOneDriveBackupDetailsSelectors() {
defer flush() defer flush()
for _, test := range testdata.OneDriveOptionDetailLookups { for _, test := range testdata.OneDriveOptionDetailLookups {
suite.T().Run(test.Name, func(t *testing.T) { suite.Run(test.Name, func() {
t := suite.T()
output, err := runDetailsOneDriveCmd( output, err := runDetailsOneDriveCmd(
ctx, ctx,
test.BackupGetter, test.BackupGetter,
@ -110,7 +114,9 @@ func (suite *OneDriveSuite) TestOneDriveBackupDetailsSelectorsBadFormats() {
defer flush() defer flush()
for _, test := range testdata.BadOneDriveOptionsFormats { for _, test := range testdata.BadOneDriveOptionsFormats {
suite.T().Run(test.Name, func(t *testing.T) { suite.Run(test.Name, func() {
t := suite.T()
output, err := runDetailsOneDriveCmd( output, err := runDetailsOneDriveCmd(
ctx, ctx,
test.BackupGetter, test.BackupGetter,

View File

@ -29,7 +29,7 @@ import (
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
type NoBackupSharePointIntegrationSuite struct { type NoBackupSharePointIntegrationSuite struct {
suite.Suite tester.Suite
acct account.Account acct account.Account
st storage.Storage st storage.Storage
vpr *viper.Viper vpr *viper.Viper
@ -40,9 +40,10 @@ type NoBackupSharePointIntegrationSuite struct {
} }
func TestNoBackupSharePointIntegrationSuite(t *testing.T) { func TestNoBackupSharePointIntegrationSuite(t *testing.T) {
tester.RunOnAny(t, tester.CorsoCITests, tester.CorsoCLITests, tester.CorsoCLIBackupTests) suite.Run(t, &NoBackupSharePointIntegrationSuite{Suite: tester.NewIntegrationSuite(
t,
suite.Run(t, new(NoBackupSharePointIntegrationSuite)) [][]string{tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs},
tester.CorsoCLITests, tester.CorsoCLIBackupTests)})
} }
func (suite *NoBackupSharePointIntegrationSuite) SetupSuite() { func (suite *NoBackupSharePointIntegrationSuite) SetupSuite() {
@ -51,8 +52,6 @@ func (suite *NoBackupSharePointIntegrationSuite) SetupSuite() {
defer flush() defer flush()
tester.MustGetEnvSets(t, tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs)
// prepare common details // prepare common details
suite.acct = tester.NewM365Account(t) suite.acct = tester.NewM365Account(t)
suite.st = tester.NewPrefixedS3Storage(t) suite.st = tester.NewPrefixedS3Storage(t)
@ -108,7 +107,7 @@ func (suite *NoBackupSharePointIntegrationSuite) TestSharePointBackupListCmd_emp
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
type BackupDeleteSharePointIntegrationSuite struct { type BackupDeleteSharePointIntegrationSuite struct {
suite.Suite tester.Suite
acct account.Account acct account.Account
st storage.Storage st storage.Storage
vpr *viper.Viper vpr *viper.Viper
@ -119,14 +118,16 @@ type BackupDeleteSharePointIntegrationSuite struct {
} }
func TestBackupDeleteSharePointIntegrationSuite(t *testing.T) { func TestBackupDeleteSharePointIntegrationSuite(t *testing.T) {
tester.RunOnAny(t, tester.CorsoCITests, tester.CorsoCLITests, tester.CorsoCLIBackupTests) suite.Run(t, &BackupDeleteSharePointIntegrationSuite{
Suite: tester.NewIntegrationSuite(
suite.Run(t, new(BackupDeleteSharePointIntegrationSuite)) t,
[][]string{tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs},
tester.CorsoCLITests, tester.CorsoCLIBackupTests),
})
} }
func (suite *BackupDeleteSharePointIntegrationSuite) SetupSuite() { func (suite *BackupDeleteSharePointIntegrationSuite) SetupSuite() {
t := suite.T() t := suite.T()
tester.MustGetEnvSets(t, tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs)
// prepare common details // prepare common details
suite.acct = tester.NewM365Account(t) suite.acct = tester.NewM365Account(t)

View File

@ -16,11 +16,11 @@ import (
) )
type SharePointSuite struct { type SharePointSuite struct {
suite.Suite tester.Suite
} }
func TestSharePointSuite(t *testing.T) { func TestSharePointSuite(t *testing.T) {
suite.Run(t, new(SharePointSuite)) suite.Run(t, &SharePointSuite{tester.NewUnitSuite(t)})
} }
func (suite *SharePointSuite) TestAddSharePointCommands() { func (suite *SharePointSuite) TestAddSharePointCommands() {
@ -51,7 +51,9 @@ func (suite *SharePointSuite) TestAddSharePointCommands() {
}, },
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
t := suite.T()
cmd := &cobra.Command{Use: test.use} cmd := &cobra.Command{Use: test.use}
c := addSharePointCommands(cmd) c := addSharePointCommands(cmd)
@ -97,8 +99,8 @@ func (suite *SharePointSuite) TestValidateSharePointBackupCreateFlags() {
}, },
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
test.expect(t, validateSharePointBackupCreateFlags(test.site, test.weburl, nil)) test.expect(suite.T(), validateSharePointBackupCreateFlags(test.site, test.weburl, nil))
}) })
} }
} }
@ -191,7 +193,9 @@ func (suite *SharePointSuite) TestSharePointBackupCreateSelectors() {
}, },
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
t := suite.T()
ctx, flush := tester.NewContext() ctx, flush := tester.NewContext()
defer flush() defer flush()
@ -208,7 +212,9 @@ func (suite *SharePointSuite) TestSharePointBackupDetailsSelectors() {
defer flush() defer flush()
for _, test := range testdata.SharePointOptionDetailLookups { for _, test := range testdata.SharePointOptionDetailLookups {
suite.T().Run(test.Name, func(t *testing.T) { suite.Run(test.Name, func() {
t := suite.T()
output, err := runDetailsSharePointCmd( output, err := runDetailsSharePointCmd(
ctx, ctx,
test.BackupGetter, test.BackupGetter,
@ -225,7 +231,9 @@ func (suite *SharePointSuite) TestSharePointBackupDetailsSelectorsBadFormats() {
defer flush() defer flush()
for _, test := range testdata.BadSharePointOptionsFormats { for _, test := range testdata.BadSharePointOptionsFormats {
suite.T().Run(test.Name, func(t *testing.T) { suite.Run(test.Name, func() {
t := suite.T()
output, err := runDetailsSharePointCmd( output, err := runDetailsSharePointCmd(
ctx, ctx,
test.BackupGetter, test.BackupGetter,

View File

@ -8,14 +8,15 @@ import (
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/alcionai/corso/src/cli" "github.com/alcionai/corso/src/cli"
"github.com/alcionai/corso/src/internal/tester"
) )
type CLISuite struct { type CLISuite struct {
suite.Suite tester.Suite
} }
func TestCLISuite(t *testing.T) { func TestCLISuite(t *testing.T) {
suite.Run(t, new(CLISuite)) suite.Run(t, &CLISuite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *CLISuite) TestAddCommands_noPanics() { func (suite *CLISuite) TestAddCommands_noPanics() {

View File

@ -31,11 +31,11 @@ const (
) )
type ConfigSuite struct { type ConfigSuite struct {
suite.Suite tester.Suite
} }
func TestConfigSuite(t *testing.T) { func TestConfigSuite(t *testing.T) {
suite.Run(t, new(ConfigSuite)) suite.Run(t, &ConfigSuite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *ConfigSuite) TestReadRepoConfigBasic() { func (suite *ConfigSuite) TestReadRepoConfigBasic() {
@ -172,8 +172,8 @@ func (suite *ConfigSuite) TestMustMatchConfig() {
}, },
} }
for _, test := range table { for _, test := range table {
t.Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
test.errCheck(t, mustMatchConfig(vpr, test.input)) test.errCheck(suite.T(), mustMatchConfig(vpr, test.input))
}) })
} }
} }
@ -183,20 +183,14 @@ func (suite *ConfigSuite) TestMustMatchConfig() {
// ------------------------------------------------------------ // ------------------------------------------------------------
type ConfigIntegrationSuite struct { type ConfigIntegrationSuite struct {
suite.Suite tester.Suite
} }
func TestConfigIntegrationSuite(t *testing.T) { func TestConfigIntegrationSuite(t *testing.T) {
tester.RunOnAny( suite.Run(t, &ConfigIntegrationSuite{Suite: tester.NewIntegrationSuite(
t, t,
tester.CorsoCITests, [][]string{tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs},
tester.CorsoCLIConfigTests) tester.CorsoCLIConfigTests)})
suite.Run(t, new(ConfigIntegrationSuite))
}
func (suite *ConfigIntegrationSuite) SetupSuite() {
tester.MustGetEnvSets(suite.T(), tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs)
} }
func (suite *ConfigIntegrationSuite) TestGetStorageAndAccount() { func (suite *ConfigIntegrationSuite) TestGetStorageAndAccount() {

View File

@ -12,11 +12,11 @@ import (
) )
type EnvSuite struct { type EnvSuite struct {
suite.Suite tester.Suite
} }
func TestEnvSuite(t *testing.T) { func TestEnvSuite(t *testing.T) {
suite.Run(t, new(EnvSuite)) suite.Run(t, &EnvSuite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *EnvSuite) TestAddEnvCommands() { func (suite *EnvSuite) TestAddEnvCommands() {

View File

@ -2,28 +2,31 @@ package print
import ( import (
"bytes" "bytes"
"context"
"testing" "testing"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/alcionai/corso/src/internal/tester"
) )
type PrintUnitSuite struct { type PrintUnitSuite struct {
suite.Suite tester.Suite
} }
func TestPrintUnitSuite(t *testing.T) { func TestPrintUnitSuite(t *testing.T) {
suite.Run(t, new(PrintUnitSuite)) suite.Run(t, &PrintUnitSuite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *PrintUnitSuite) TestOnly() { func (suite *PrintUnitSuite) TestOnly() {
t := suite.T() t := suite.T()
c := &cobra.Command{} c := &cobra.Command{}
// cannot use tester.NewContext() here: circular imports
//nolint:forbidigo ctx, flush := tester.NewContext()
ctx := SetRootCmd(context.Background(), c) defer flush()
ctx = SetRootCmd(ctx, c)
assert.NoError(t, Only(ctx, nil)) assert.NoError(t, Only(ctx, nil))
assert.True(t, c.SilenceUsage) assert.True(t, c.SilenceUsage)
} }

View File

@ -16,21 +16,15 @@ import (
) )
type S3IntegrationSuite struct { type S3IntegrationSuite struct {
suite.Suite tester.Suite
} }
func TestS3IntegrationSuite(t *testing.T) { func TestS3IntegrationSuite(t *testing.T) {
tester.RunOnAny( suite.Run(t, &S3IntegrationSuite{Suite: tester.NewIntegrationSuite(
t, t,
tester.CorsoCITests, [][]string{tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs},
tester.CorsoCLITests, tester.CorsoCLITests,
tester.CorsoCLIRepoTests) tester.CorsoCLIRepoTests)})
suite.Run(t, new(S3IntegrationSuite))
}
func (suite *S3IntegrationSuite) SetupSuite() {
tester.MustGetEnvSets(suite.T(), tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs)
} }
func (suite *S3IntegrationSuite) TestInitS3Cmd() { func (suite *S3IntegrationSuite) TestInitS3Cmd() {
@ -49,7 +43,9 @@ func (suite *S3IntegrationSuite) TestInitS3Cmd() {
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
t := suite.T()
ctx, flush := tester.NewContext() ctx, flush := tester.NewContext()
defer flush() defer flush()
@ -148,7 +144,9 @@ func (suite *S3IntegrationSuite) TestConnectS3Cmd() {
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
t := suite.T()
ctx, flush := tester.NewContext() ctx, flush := tester.NewContext()
defer flush() defer flush()

View File

@ -12,11 +12,11 @@ import (
) )
type S3Suite struct { type S3Suite struct {
suite.Suite tester.Suite
} }
func TestS3Suite(t *testing.T) { func TestS3Suite(t *testing.T) {
suite.Run(t, new(S3Suite)) suite.Run(t, &S3Suite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *S3Suite) TestAddS3Commands() { func (suite *S3Suite) TestAddS3Commands() {
@ -33,7 +33,9 @@ func (suite *S3Suite) TestAddS3Commands() {
{"connect s3", connectCommand, expectUse, s3ConnectCmd().Short, connectS3Cmd}, {"connect s3", connectCommand, expectUse, s3ConnectCmd().Short, connectS3Cmd},
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
t := suite.T()
cmd := &cobra.Command{Use: test.use} cmd := &cobra.Command{Use: test.use}
c := addS3Commands(cmd) c := addS3Commands(cmd)

View File

@ -31,7 +31,7 @@ var (
var backupDataSets = []path.CategoryType{email, contacts, events} var backupDataSets = []path.CategoryType{email, contacts, events}
type RestoreExchangeIntegrationSuite struct { type RestoreExchangeIntegrationSuite struct {
suite.Suite tester.Suite
acct account.Account acct account.Account
st storage.Storage st storage.Storage
vpr *viper.Viper vpr *viper.Viper
@ -42,13 +42,13 @@ type RestoreExchangeIntegrationSuite struct {
} }
func TestRestoreExchangeIntegrationSuite(t *testing.T) { func TestRestoreExchangeIntegrationSuite(t *testing.T) {
tester.RunOnAny( suite.Run(t, &RestoreExchangeIntegrationSuite{
t, Suite: tester.NewIntegrationSuite(
tester.CorsoCITests, t,
tester.CorsoCLITests, [][]string{tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs},
tester.CorsoCLIRestoreTests) tester.CorsoCLITests,
tester.CorsoCLIRestoreTests),
suite.Run(t, new(RestoreExchangeIntegrationSuite)) })
} }
func (suite *RestoreExchangeIntegrationSuite) SetupSuite() { func (suite *RestoreExchangeIntegrationSuite) SetupSuite() {
@ -57,8 +57,6 @@ func (suite *RestoreExchangeIntegrationSuite) SetupSuite() {
ctx, flush := tester.NewContext() ctx, flush := tester.NewContext()
defer flush() defer flush()
tester.MustGetEnvSets(t, tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs)
// aggregate required details // aggregate required details
suite.acct = tester.NewM365Account(t) suite.acct = tester.NewM365Account(t)
suite.st = tester.NewPrefixedS3Storage(t) suite.st = tester.NewPrefixedS3Storage(t)
@ -119,7 +117,9 @@ func (suite *RestoreExchangeIntegrationSuite) SetupSuite() {
func (suite *RestoreExchangeIntegrationSuite) TestExchangeRestoreCmd() { func (suite *RestoreExchangeIntegrationSuite) TestExchangeRestoreCmd() {
for _, set := range backupDataSets { for _, set := range backupDataSets {
suite.T().Run(set.String(), func(t *testing.T) { suite.Run(set.String(), func() {
t := suite.T()
ctx, flush := tester.NewContext() ctx, flush := tester.NewContext()
ctx = config.SetViper(ctx, suite.vpr) ctx = config.SetViper(ctx, suite.vpr)
@ -143,7 +143,9 @@ func (suite *RestoreExchangeIntegrationSuite) TestExchangeRestoreCmd_badTimeFlag
suite.T().Skip() suite.T().Skip()
} }
suite.T().Run(set.String(), func(t *testing.T) { suite.Run(set.String(), func() {
t := suite.T()
ctx, flush := tester.NewContext() ctx, flush := tester.NewContext()
ctx = config.SetViper(ctx, suite.vpr) ctx = config.SetViper(ctx, suite.vpr)
@ -176,7 +178,9 @@ func (suite *RestoreExchangeIntegrationSuite) TestExchangeRestoreCmd_badBoolFlag
suite.T().Skip() suite.T().Skip()
} }
suite.T().Run(set.String(), func(t *testing.T) { suite.Run(set.String(), func() {
t := suite.T()
//nolint:forbidigo //nolint:forbidigo
ctx := config.SetViper(context.Background(), suite.vpr) ctx := config.SetViper(context.Background(), suite.vpr)
ctx, flush := tester.WithContext(ctx) ctx, flush := tester.WithContext(ctx)

View File

@ -12,11 +12,11 @@ import (
) )
type ExchangeSuite struct { type ExchangeSuite struct {
suite.Suite tester.Suite
} }
func TestExchangeSuite(t *testing.T) { func TestExchangeSuite(t *testing.T) {
suite.Run(t, new(ExchangeSuite)) suite.Run(t, &ExchangeSuite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *ExchangeSuite) TestAddExchangeCommands() { func (suite *ExchangeSuite) TestAddExchangeCommands() {
@ -32,7 +32,9 @@ func (suite *ExchangeSuite) TestAddExchangeCommands() {
{"restore exchange", restoreCommand, expectUse, exchangeRestoreCmd().Short, restoreExchangeCmd}, {"restore exchange", restoreCommand, expectUse, exchangeRestoreCmd().Short, restoreExchangeCmd},
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
t := suite.T()
cmd := &cobra.Command{Use: test.use} cmd := &cobra.Command{Use: test.use}
c := addExchangeCommands(cmd) c := addExchangeCommands(cmd)

View File

@ -12,11 +12,11 @@ import (
) )
type OneDriveSuite struct { type OneDriveSuite struct {
suite.Suite tester.Suite
} }
func TestOneDriveSuite(t *testing.T) { func TestOneDriveSuite(t *testing.T) {
suite.Run(t, new(OneDriveSuite)) suite.Run(t, &OneDriveSuite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *OneDriveSuite) TestAddOneDriveCommands() { func (suite *OneDriveSuite) TestAddOneDriveCommands() {
@ -32,7 +32,9 @@ func (suite *OneDriveSuite) TestAddOneDriveCommands() {
{"restore onedrive", restoreCommand, expectUse, oneDriveRestoreCmd().Short, restoreOneDriveCmd}, {"restore onedrive", restoreCommand, expectUse, oneDriveRestoreCmd().Short, restoreOneDriveCmd},
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
t := suite.T()
cmd := &cobra.Command{Use: test.use} cmd := &cobra.Command{Use: test.use}
c := addOneDriveCommands(cmd) c := addOneDriveCommands(cmd)

View File

@ -12,11 +12,11 @@ import (
) )
type SharePointSuite struct { type SharePointSuite struct {
suite.Suite tester.Suite
} }
func TestSharePointSuite(t *testing.T) { func TestSharePointSuite(t *testing.T) {
suite.Run(t, new(SharePointSuite)) suite.Run(t, &SharePointSuite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *SharePointSuite) TestAddSharePointCommands() { func (suite *SharePointSuite) TestAddSharePointCommands() {
@ -32,7 +32,9 @@ func (suite *SharePointSuite) TestAddSharePointCommands() {
{"restore onedrive", restoreCommand, expectUse, sharePointRestoreCmd().Short, restoreSharePointCmd}, {"restore onedrive", restoreCommand, expectUse, sharePointRestoreCmd().Short, restoreSharePointCmd},
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
t := suite.T()
cmd := &cobra.Command{Use: test.use} cmd := &cobra.Command{Use: test.use}
c := addSharePointCommands(cmd) c := addSharePointCommands(cmd)

View File

@ -8,15 +8,16 @@ import (
"github.com/alcionai/corso/src/cli/utils" "github.com/alcionai/corso/src/cli/utils"
"github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/common"
"github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/pkg/selectors" "github.com/alcionai/corso/src/pkg/selectors"
) )
type ExchangeUtilsSuite struct { type ExchangeUtilsSuite struct {
suite.Suite tester.Suite
} }
func TestExchangeUtilsSuite(t *testing.T) { func TestExchangeUtilsSuite(t *testing.T) {
suite.Run(t, new(ExchangeUtilsSuite)) suite.Run(t, &ExchangeUtilsSuite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *ExchangeUtilsSuite) TestValidateRestoreFlags() { func (suite *ExchangeUtilsSuite) TestValidateRestoreFlags() {
@ -50,8 +51,8 @@ func (suite *ExchangeUtilsSuite) TestValidateRestoreFlags() {
}, },
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
test.expect(t, utils.ValidateExchangeRestoreFlags(test.backupID, test.opts)) test.expect(suite.T(), utils.ValidateExchangeRestoreFlags(test.backupID, test.opts))
}) })
} }
} }
@ -300,9 +301,9 @@ func (suite *ExchangeUtilsSuite) TestIncludeExchangeRestoreDataSelectors() {
}, },
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
sel := utils.IncludeExchangeRestoreDataSelectors(test.opts) sel := utils.IncludeExchangeRestoreDataSelectors(test.opts)
assert.Len(t, sel.Includes, test.expectIncludeLen) assert.Len(suite.T(), sel.Includes, test.expectIncludeLen)
}) })
} }
} }
@ -361,11 +362,11 @@ func (suite *ExchangeUtilsSuite) TestAddExchangeInclude() {
}, },
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
sel := selectors.NewExchangeRestore(nil) sel := selectors.NewExchangeRestore(nil)
// no return, mutates sel as a side effect // no return, mutates sel as a side effect
utils.AddExchangeInclude(sel, test.folders, test.items, eisc) utils.AddExchangeInclude(sel, test.folders, test.items, eisc)
assert.Len(t, sel.Includes, test.expectIncludeLen) assert.Len(suite.T(), sel.Includes, test.expectIncludeLen)
}) })
} }
} }
@ -477,10 +478,10 @@ func (suite *ExchangeUtilsSuite) TestFilterExchangeRestoreInfoSelectors() {
}, },
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
sel := selectors.NewExchangeRestore(nil) sel := selectors.NewExchangeRestore(nil)
utils.FilterExchangeRestoreInfoSelectors(sel, test.opts) utils.FilterExchangeRestoreInfoSelectors(sel, test.opts)
assert.Len(t, sel.Filters, test.expectFilterLen) assert.Len(suite.T(), sel.Filters, test.expectFilterLen)
}) })
} }
} }

View File

@ -7,14 +7,15 @@ import (
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/alcionai/corso/src/cli/utils" "github.com/alcionai/corso/src/cli/utils"
"github.com/alcionai/corso/src/internal/tester"
) )
type OneDriveUtilsSuite struct { type OneDriveUtilsSuite struct {
suite.Suite tester.Suite
} }
func TestOneDriveUtilsSuite(t *testing.T) { func TestOneDriveUtilsSuite(t *testing.T) {
suite.Run(t, new(OneDriveUtilsSuite)) suite.Run(t, &OneDriveUtilsSuite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *OneDriveUtilsSuite) TestIncludeOneDriveRestoreDataSelectors() { func (suite *OneDriveUtilsSuite) TestIncludeOneDriveRestoreDataSelectors() {
@ -88,9 +89,9 @@ func (suite *OneDriveUtilsSuite) TestIncludeOneDriveRestoreDataSelectors() {
}, },
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
sel := utils.IncludeOneDriveRestoreDataSelectors(test.opts) sel := utils.IncludeOneDriveRestoreDataSelectors(test.opts)
assert.Len(t, sel.Includes, test.expectIncludeLen) assert.Len(suite.T(), sel.Includes, test.expectIncludeLen)
}) })
} }
} }

View File

@ -7,14 +7,15 @@ import (
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/alcionai/corso/src/cli/utils" "github.com/alcionai/corso/src/cli/utils"
"github.com/alcionai/corso/src/internal/tester"
) )
type SharePointUtilsSuite struct { type SharePointUtilsSuite struct {
suite.Suite tester.Suite
} }
func TestSharePointUtilsSuite(t *testing.T) { func TestSharePointUtilsSuite(t *testing.T) {
suite.Run(t, new(SharePointUtilsSuite)) suite.Run(t, &SharePointUtilsSuite{Suite: tester.NewUnitSuite(t)})
} }
// Tests selector build for SharePoint properly // Tests selector build for SharePoint properly
@ -181,9 +182,9 @@ func (suite *SharePointUtilsSuite) TestIncludeSharePointRestoreDataSelectors() {
}, },
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
sel := utils.IncludeSharePointRestoreDataSelectors(test.opts) sel := utils.IncludeSharePointRestoreDataSelectors(test.opts)
assert.Len(t, sel.Includes, test.expectIncludeLen) assert.Len(suite.T(), sel.Includes, test.expectIncludeLen)
}) })
} }
} }

View File

@ -6,15 +6,16 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/pkg/selectors" "github.com/alcionai/corso/src/pkg/selectors"
) )
type CliUtilsSuite struct { type CliUtilsSuite struct {
suite.Suite tester.Suite
} }
func TestCliUtilsSuite(t *testing.T) { func TestCliUtilsSuite(t *testing.T) {
suite.Run(t, new(CliUtilsSuite)) suite.Run(t, &CliUtilsSuite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *CliUtilsSuite) TestRequireProps() { func (suite *CliUtilsSuite) TestRequireProps() {
@ -75,7 +76,9 @@ func (suite *CliUtilsSuite) TestSplitFoldersIntoContainsAndPrefix() {
}, },
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
t := suite.T()
c, p := splitFoldersIntoContainsAndPrefix(test.input) c, p := splitFoldersIntoContainsAndPrefix(test.input)
assert.ElementsMatch(t, test.expectC, c, "contains set") assert.ElementsMatch(t, test.expectC, c, "contains set")
assert.ElementsMatch(t, test.expectP, p, "prefix set") assert.ElementsMatch(t, test.expectP, p, "prefix set")