Use test wrapper in pkg package (#2531)

## Description

Leave out account and storage subpackages as those are used by tester and create an import cycle.

## 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-24 20:50:00 -08:00 committed by GitHub
parent 9e783efe3a
commit 40cb810861
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 350 additions and 166 deletions

View File

@ -12,17 +12,18 @@ import (
"github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/common"
"github.com/alcionai/corso/src/internal/model" "github.com/alcionai/corso/src/internal/model"
"github.com/alcionai/corso/src/internal/stats" "github.com/alcionai/corso/src/internal/stats"
"github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/pkg/backup" "github.com/alcionai/corso/src/pkg/backup"
"github.com/alcionai/corso/src/pkg/fault" "github.com/alcionai/corso/src/pkg/fault"
"github.com/alcionai/corso/src/pkg/selectors" "github.com/alcionai/corso/src/pkg/selectors"
) )
type BackupSuite struct { type BackupSuite struct {
suite.Suite tester.Suite
} }
func TestBackupSuite(t *testing.T) { func TestBackupSuite(t *testing.T) {
suite.Run(t, new(BackupSuite)) suite.Run(t, &BackupSuite{Suite: tester.NewUnitSuite(t)})
} }
func stubBackup(t time.Time) backup.Backup { func stubBackup(t time.Time) backup.Backup {

View File

@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"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/path" "github.com/alcionai/corso/src/pkg/path"
) )
@ -17,11 +18,11 @@ import (
// ------------------------------------------------------------ // ------------------------------------------------------------
type DetailsUnitSuite struct { type DetailsUnitSuite struct {
suite.Suite tester.Suite
} }
func TestDetailsUnitSuite(t *testing.T) { func TestDetailsUnitSuite(t *testing.T) {
suite.Run(t, new(DetailsUnitSuite)) suite.Run(t, &DetailsUnitSuite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *DetailsUnitSuite) TestDetailsEntry_HeadersValues() { func (suite *DetailsUnitSuite) TestDetailsEntry_HeadersValues() {
@ -153,7 +154,9 @@ func (suite *DetailsUnitSuite) TestDetailsEntry_HeadersValues() {
} }
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()
hs := test.entry.Headers() hs := test.entry.Headers()
assert.Equal(t, test.expectHs, hs) assert.Equal(t, test.expectHs, hs)
vs := test.entry.Values() vs := test.entry.Values()
@ -291,7 +294,9 @@ var pathItemsTable = []struct {
func (suite *DetailsUnitSuite) TestDetailsModel_Path() { func (suite *DetailsUnitSuite) TestDetailsModel_Path() {
for _, test := range pathItemsTable { for _, test := range pathItemsTable {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
t := suite.T()
d := Details{ d := Details{
DetailsModel: DetailsModel{ DetailsModel: DetailsModel{
Entries: test.ents, Entries: test.ents,
@ -304,7 +309,9 @@ func (suite *DetailsUnitSuite) TestDetailsModel_Path() {
func (suite *DetailsUnitSuite) TestDetailsModel_Items() { func (suite *DetailsUnitSuite) TestDetailsModel_Items() {
for _, test := range pathItemsTable { for _, test := range pathItemsTable {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
t := suite.T()
d := Details{ d := Details{
DetailsModel: DetailsModel{ DetailsModel: DetailsModel{
Entries: test.ents, Entries: test.ents,
@ -462,7 +469,9 @@ func (suite *DetailsUnitSuite) TestDetails_AddFolders() {
}, },
} }
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()
builder := Builder{} builder := Builder{}
builder.AddFoldersForItem(test.folders, itemInfo, true) builder.AddFoldersForItem(test.folders, itemInfo, true)
deets := builder.Details() deets := builder.Details()
@ -547,7 +556,9 @@ func (suite *DetailsUnitSuite) TestDetails_AddFoldersUpdate() {
}, },
} }
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()
builder := Builder{} builder := Builder{}
builder.AddFoldersForItem(test.folders, itemInfo, test.itemUpdated) builder.AddFoldersForItem(test.folders, itemInfo, test.itemUpdated)
deets := builder.Details() deets := builder.Details()
@ -613,7 +624,9 @@ func (suite *DetailsUnitSuite) TestDetails_AddFoldersDifferentServices() {
}, },
} }
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()
folder := folderEntry{ folder := folderEntry{
RepoRef: "rr1", RepoRef: "rr1",
ShortRef: "sr1", ShortRef: "sr1",
@ -806,7 +819,9 @@ func (suite *DetailsUnitSuite) TestUpdateItem() {
} }
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()
item := test.input item := test.input
err := UpdateItem(&item, test.repoPath) err := UpdateItem(&item, test.repoPath)
test.errCheck(t, err) test.errCheck(t, err)
@ -972,7 +987,9 @@ func (suite *DetailsUnitSuite) TestFolderEntriesForPath() {
// }, // },
} }
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()
result := FolderEntriesForPath(test.parent, test.location) result := FolderEntriesForPath(test.parent, test.location)
assert.ElementsMatch(t, test.expect, result) assert.ElementsMatch(t, test.expect, result)
}) })

View File

@ -10,15 +10,16 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/pkg/fault" "github.com/alcionai/corso/src/pkg/fault"
) )
type FaultErrorsUnitSuite struct { type FaultErrorsUnitSuite struct {
suite.Suite tester.Suite
} }
func TestFaultErrorsUnitSuite(t *testing.T) { func TestFaultErrorsUnitSuite(t *testing.T) {
suite.Run(t, new(FaultErrorsUnitSuite)) suite.Run(t, &FaultErrorsUnitSuite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *FaultErrorsUnitSuite) TestNew() { func (suite *FaultErrorsUnitSuite) TestNew() {
@ -72,7 +73,9 @@ func (suite *FaultErrorsUnitSuite) TestErr() {
}, },
} }
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()
n := fault.New(test.failFast) n := fault.New(test.failFast)
require.NotNil(t, n) require.NotNil(t, n)
require.NoError(t, n.Failure()) require.NoError(t, n.Failure())
@ -147,7 +150,9 @@ func (suite *FaultErrorsUnitSuite) TestErrs() {
}, },
} }
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()
n := fault.New(test.failFast) n := fault.New(test.failFast)
require.NotNil(t, n) require.NotNil(t, n)

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/filters" "github.com/alcionai/corso/src/pkg/filters"
) )
type FiltersSuite struct { type FiltersSuite struct {
suite.Suite tester.Suite
} }
func TestFiltersSuite(t *testing.T) { func TestFiltersSuite(t *testing.T) {
suite.Run(t, new(FiltersSuite)) suite.Run(t, &FiltersSuite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *FiltersSuite) TestEquals() { func (suite *FiltersSuite) TestEquals() {
@ -30,7 +31,9 @@ func (suite *FiltersSuite) TestEquals() {
{"bar", assert.False, assert.True}, {"bar", assert.False, assert.True},
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.input, func(t *testing.T) { suite.Run(test.input, func() {
t := suite.T()
test.expectF(t, f.Compare(test.input), "filter") test.expectF(t, f.Compare(test.input), "filter")
test.expectNF(t, nf.Compare(test.input), "negated filter") test.expectNF(t, nf.Compare(test.input), "negated filter")
}) })
@ -51,7 +54,9 @@ func (suite *FiltersSuite) TestEquals_any() {
{"not includes target", []string{"baz", "qux"}, assert.False, assert.True}, {"not includes target", []string{"baz", "qux"}, assert.False, assert.True},
} }
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.expectF(t, f.CompareAny(test.input...), "filter") test.expectF(t, f.CompareAny(test.input...), "filter")
test.expectNF(t, nf.CompareAny(test.input...), "negated filter") test.expectNF(t, nf.CompareAny(test.input...), "negated filter")
}) })
@ -72,7 +77,9 @@ func (suite *FiltersSuite) TestGreater() {
{"6", assert.False, assert.True}, {"6", assert.False, assert.True},
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.input, func(t *testing.T) { suite.Run(test.input, func() {
t := suite.T()
test.expectF(t, f.Compare(test.input), "filter") test.expectF(t, f.Compare(test.input), "filter")
test.expectNF(t, nf.Compare(test.input), "negated filter") test.expectNF(t, nf.Compare(test.input), "negated filter")
}) })
@ -93,7 +100,9 @@ func (suite *FiltersSuite) TestLess() {
{"4", assert.False, assert.True}, {"4", assert.False, assert.True},
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.input, func(t *testing.T) { suite.Run(test.input, func() {
t := suite.T()
test.expectF(t, f.Compare(test.input), "filter") test.expectF(t, f.Compare(test.input), "filter")
test.expectNF(t, nf.Compare(test.input), "negated filter") test.expectNF(t, nf.Compare(test.input), "negated filter")
}) })
@ -113,7 +122,9 @@ func (suite *FiltersSuite) TestContains() {
{"frum", assert.False, assert.True}, {"frum", assert.False, assert.True},
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.input, func(t *testing.T) { suite.Run(test.input, func() {
t := suite.T()
test.expectF(t, f.Compare(test.input), "filter") test.expectF(t, f.Compare(test.input), "filter")
test.expectNF(t, nf.Compare(test.input), "negated filter") test.expectNF(t, nf.Compare(test.input), "negated filter")
}) })
@ -134,7 +145,9 @@ func (suite *FiltersSuite) TestContains_Joined() {
{"fnords", assert.False, assert.True}, {"fnords", assert.False, assert.True},
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.input, func(t *testing.T) { suite.Run(test.input, func() {
t := suite.T()
test.expectF(t, f.Compare(test.input), "filter") test.expectF(t, f.Compare(test.input), "filter")
test.expectNF(t, nf.Compare(test.input), "negated filter") test.expectNF(t, nf.Compare(test.input), "negated filter")
}) })
@ -154,7 +167,9 @@ func (suite *FiltersSuite) TestIn() {
{"sfrums", assert.False, assert.True}, {"sfrums", assert.False, assert.True},
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.input, func(t *testing.T) { suite.Run(test.input, func() {
t := suite.T()
test.expectF(t, f.Compare(test.input), "filter") test.expectF(t, f.Compare(test.input), "filter")
test.expectNF(t, nf.Compare(test.input), "negated filter") test.expectNF(t, nf.Compare(test.input), "negated filter")
}) })
@ -174,7 +189,9 @@ func (suite *FiltersSuite) TestIn_Joined() {
{"arf,user", assert.False, assert.True}, {"arf,user", assert.False, assert.True},
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.input, func(t *testing.T) { suite.Run(test.input, func() {
t := suite.T()
test.expectF(t, f.Compare(test.input), "filter") test.expectF(t, f.Compare(test.input), "filter")
test.expectNF(t, nf.Compare(test.input), "negated filter") test.expectNF(t, nf.Compare(test.input), "negated filter")
}) })
@ -199,7 +216,9 @@ func (suite *FiltersSuite) TestPrefixes() {
{"Should not match substring", "folder1/folderA", assert.False, assert.True}, {"Should not match substring", "folder1/folderA", assert.False, assert.True},
} }
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.expectF(t, f.Compare(test.input), "filter") test.expectF(t, f.Compare(test.input), "filter")
test.expectNF(t, nf.Compare(test.input), "negated filter") test.expectNF(t, nf.Compare(test.input), "negated filter")
}) })
@ -224,7 +243,9 @@ func (suite *FiltersSuite) TestSuffixes() {
{"Should not match substring", "folderB/folder1", assert.False, assert.True}, {"Should not match substring", "folderB/folder1", assert.False, assert.True},
} }
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.expectF(t, f.Compare(test.input), "filter") test.expectF(t, f.Compare(test.input), "filter")
test.expectNF(t, nf.Compare(test.input), "negated filter") test.expectNF(t, nf.Compare(test.input), "negated filter")
}) })
@ -270,7 +291,9 @@ func (suite *FiltersSuite) TestPathPrefix() {
{"Slice - none match", []string{"foo", "fa/f", "f"}, "/fA/fb", assert.False, assert.True}, {"Slice - none match", []string{"foo", "fa/f", "f"}, "/fA/fb", assert.False, assert.True},
} }
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()
f := filters.PathPrefix(test.targets) f := filters.PathPrefix(test.targets)
nf := filters.NotPathPrefix(test.targets) nf := filters.NotPathPrefix(test.targets)
@ -300,7 +323,9 @@ func (suite *FiltersSuite) TestPathPrefix_NormalizedTargets() {
{"Multi input - both slashes", []string{"/fA/", "/fB/"}, []string{"/fA/", "/fB/"}}, {"Multi input - both slashes", []string{"/fA/", "/fB/"}, []string{"/fA/", "/fB/"}},
} }
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()
f := filters.PathPrefix(test.targets) f := filters.PathPrefix(test.targets)
assert.Equal(t, test.expect, f.NormalizedTargets) assert.Equal(t, test.expect, f.NormalizedTargets)
}) })
@ -349,7 +374,9 @@ func (suite *FiltersSuite) TestPathContains() {
{"Slice - none match", []string{"foo", "fa/f", "f"}, "/fA/fb", assert.False, assert.True}, {"Slice - none match", []string{"foo", "fa/f", "f"}, "/fA/fb", assert.False, assert.True},
} }
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()
f := filters.PathContains(test.targets) f := filters.PathContains(test.targets)
nf := filters.NotPathContains(test.targets) nf := filters.NotPathContains(test.targets)
@ -379,7 +406,9 @@ func (suite *FiltersSuite) TestPathContains_NormalizedTargets() {
{"Multi input - both slashes", []string{"/fA/", "/fB/"}, []string{"/fA/", "/fB/"}}, {"Multi input - both slashes", []string{"/fA/", "/fB/"}, []string{"/fA/", "/fB/"}},
} }
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()
f := filters.PathContains(test.targets) f := filters.PathContains(test.targets)
assert.Equal(t, test.expect, f.NormalizedTargets) assert.Equal(t, test.expect, f.NormalizedTargets)
}) })
@ -425,7 +454,9 @@ func (suite *FiltersSuite) TestPathSuffix() {
{"Slice - none match", []string{"foo", "fa/f", "f"}, "/fA/fb", assert.False, assert.True}, {"Slice - none match", []string{"foo", "fa/f", "f"}, "/fA/fb", assert.False, assert.True},
} }
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()
f := filters.PathSuffix(test.targets) f := filters.PathSuffix(test.targets)
nf := filters.NotPathSuffix(test.targets) nf := filters.NotPathSuffix(test.targets)
@ -455,7 +486,9 @@ func (suite *FiltersSuite) TestPathSuffix_NormalizedTargets() {
{"Multi input - both slashes", []string{"/fA/", "/fB/"}, []string{"/fA/", "/fB/"}}, {"Multi input - both slashes", []string{"/fA/", "/fB/"}, []string{"/fA/", "/fB/"}},
} }
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()
f := filters.PathSuffix(test.targets) f := filters.PathSuffix(test.targets)
assert.Equal(t, test.expect, f.NormalizedTargets) assert.Equal(t, test.expect, f.NormalizedTargets)
}) })
@ -492,7 +525,9 @@ func (suite *FiltersSuite) TestPathEquals() {
{"Slice - none match", []string{"foo", "fa/f", "f"}, "/fA/fb", assert.False, assert.True}, {"Slice - none match", []string{"foo", "fa/f", "f"}, "/fA/fb", assert.False, assert.True},
} }
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()
f := filters.PathEquals(test.targets) f := filters.PathEquals(test.targets)
nf := filters.NotPathEquals(test.targets) nf := filters.NotPathEquals(test.targets)
@ -522,7 +557,9 @@ func (suite *FiltersSuite) TestPathEquals_NormalizedTargets() {
{"Multi input - both slashes", []string{"/fA/", "/fB/"}, []string{"/fA/", "/fB/"}}, {"Multi input - both slashes", []string{"/fA/", "/fB/"}, []string{"/fA/", "/fB/"}},
} }
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()
f := filters.PathEquals(test.targets) f := filters.PathEquals(test.targets)
assert.Equal(t, test.expect, f.NormalizedTargets) assert.Equal(t, test.expect, f.NormalizedTargets)
}) })

View File

@ -7,15 +7,16 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/pkg/path" "github.com/alcionai/corso/src/pkg/path"
) )
type OneDrivePathSuite struct { type OneDrivePathSuite struct {
suite.Suite tester.Suite
} }
func TestOneDrivePathSuite(t *testing.T) { func TestOneDrivePathSuite(t *testing.T) {
suite.Run(t, new(OneDrivePathSuite)) suite.Run(t, &OneDrivePathSuite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *OneDrivePathSuite) Test_ToOneDrivePath() { func (suite *OneDrivePathSuite) Test_ToOneDrivePath() {
@ -44,7 +45,9 @@ func (suite *OneDrivePathSuite) Test_ToOneDrivePath() {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
suite.T().Run(tt.name, func(t *testing.T) { suite.Run(tt.name, func() {
t := suite.T()
p, err := path.Builder{}.Append(tt.pathElements...).ToDataLayerOneDrivePath("tenant", "user", false) p, err := path.Builder{}.Append(tt.pathElements...).ToDataLayerOneDrivePath("tenant", "user", false)
require.NoError(suite.T(), err) require.NoError(suite.T(), err)

View File

@ -8,6 +8,8 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/alcionai/corso/src/internal/tester"
) )
type testData struct { type testData struct {
@ -213,17 +215,19 @@ var basicEscapedInputs = []testData{
} }
type PathUnitSuite struct { type PathUnitSuite struct {
suite.Suite tester.Suite
} }
func TestPathUnitSuite(t *testing.T) { func TestPathUnitSuite(t *testing.T) {
suite.Run(t, new(PathUnitSuite)) suite.Run(t, &PathUnitSuite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *PathUnitSuite) TestAppend() { func (suite *PathUnitSuite) TestAppend() {
table := append(append([]testData{}, genericCases...), basicUnescapedInputs...) table := append(append([]testData{}, genericCases...), basicUnescapedInputs...)
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()
p := Builder{}.Append(test.input...) p := Builder{}.Append(test.input...)
assert.Equal(t, test.expectedString, p.String()) assert.Equal(t, test.expectedString, p.String())
}) })
@ -233,7 +237,9 @@ func (suite *PathUnitSuite) TestAppend() {
func (suite *PathUnitSuite) TestUnescapeAndAppend() { func (suite *PathUnitSuite) TestUnescapeAndAppend() {
table := append(append([]testData{}, genericCases...), basicEscapedInputs...) table := append(append([]testData{}, genericCases...), basicEscapedInputs...)
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()
p, err := Builder{}.UnescapeAndAppend(test.input...) p, err := Builder{}.UnescapeAndAppend(test.input...)
require.NoError(t, err) require.NoError(t, err)
@ -327,7 +333,9 @@ func (suite *PathUnitSuite) TestElements() {
}, },
} }
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()
p, err := test.pathFunc(test.input) p, err := test.pathFunc(test.input)
require.NoError(t, err) require.NoError(t, err)
@ -359,7 +367,9 @@ func (suite *PathUnitSuite) TestPopFront() {
}, },
} }
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()
assert.Equal(t, test.expectedString, test.base.PopFront().String()) assert.Equal(t, test.expectedString, test.base.PopFront().String())
}) })
} }
@ -383,7 +393,7 @@ func (suite *PathUnitSuite) TestShortRef() {
}, },
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
pb := Builder{}.Append(test.inputElements...) pb := Builder{}.Append(test.inputElements...)
ref := pb.ShortRef() ref := pb.ShortRef()
assert.Len(suite.T(), ref, test.expectedLen) assert.Len(suite.T(), ref, test.expectedLen)
@ -473,7 +483,9 @@ func (suite *PathUnitSuite) TestFromStringErrors() {
}, },
} }
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()
_, err := FromDataLayerPath(test.escapedPath, false) _, err := FromDataLayerPath(test.escapedPath, false)
assert.Error(t, err) assert.Error(t, err)
}) })
@ -544,7 +556,9 @@ func (suite *PathUnitSuite) TestFolder() {
}, },
} }
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()
p := test.p(t) p := test.p(t)
result := p.Folder(test.escape) result := p.Folder(test.escape)
assert.Equal(t, test.expectFolder, result) assert.Equal(t, test.expectFolder, result)

View File

@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/pkg/path" "github.com/alcionai/corso/src/pkg/path"
) )
@ -127,20 +128,22 @@ var (
) )
type DataLayerResourcePath struct { type DataLayerResourcePath struct {
suite.Suite tester.Suite
} }
func TestDataLayerResourcePath(t *testing.T) { func TestDataLayerResourcePath(t *testing.T) {
suite.Run(t, new(DataLayerResourcePath)) suite.Run(t, &DataLayerResourcePath{Suite: tester.NewUnitSuite(t)})
} }
func (suite *DataLayerResourcePath) TestMissingInfoErrors() { func (suite *DataLayerResourcePath) TestMissingInfoErrors() {
for _, types := range serviceCategories { for _, types := range serviceCategories {
suite.T().Run(types.service.String()+types.category.String(), func(t1 *testing.T) { suite.Run(types.service.String()+types.category.String(), func() {
for _, m := range modes { for _, m := range modes {
t1.Run(m.name, func(t2 *testing.T) { suite.Run(m.name, func() {
for _, test := range missingInfo { for _, test := range missingInfo {
t2.Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
t := suite.T()
b := path.Builder{}.Append(test.rest...) b := path.Builder{}.Append(test.rest...)
_, err := types.pathFunc( _, err := types.pathFunc(
@ -163,7 +166,9 @@ func (suite *DataLayerResourcePath) TestMailItemNoFolder() {
b := path.Builder{}.Append(item) b := path.Builder{}.Append(item)
for _, types := range serviceCategories { for _, types := range serviceCategories {
suite.T().Run(types.service.String()+types.category.String(), func(t *testing.T) { suite.Run(types.service.String()+types.category.String(), func() {
t := suite.T()
p, err := types.pathFunc( p, err := types.pathFunc(
b, b,
testTenant, testTenant,
@ -186,7 +191,9 @@ func (suite *DataLayerResourcePath) TestPopFront() {
)...) )...)
for _, m := range modes { for _, m := range modes {
suite.T().Run(m.name, func(t *testing.T) { suite.Run(m.name, func() {
t := suite.T()
pb := path.Builder{}.Append(rest...) pb := path.Builder{}.Append(rest...)
p, err := pb.ToDataLayerExchangePathForCategory( p, err := pb.ToDataLayerExchangePathForCategory(
testTenant, testTenant,
@ -211,7 +218,7 @@ func (suite *DataLayerResourcePath) TestDir() {
} }
for _, m := range modes { for _, m := range modes {
suite.T().Run(m.name, func(t1 *testing.T) { suite.Run(m.name, func() {
pb := path.Builder{}.Append(rest...) pb := path.Builder{}.Append(rest...)
p, err := pb.ToDataLayerExchangePathForCategory( p, err := pb.ToDataLayerExchangePathForCategory(
testTenant, testTenant,
@ -219,10 +226,12 @@ func (suite *DataLayerResourcePath) TestDir() {
path.EmailCategory, path.EmailCategory,
m.isItem, m.isItem,
) )
require.NoError(t1, err) require.NoError(suite.T(), err)
for i := 1; i <= len(rest); i++ { for i := 1; i <= len(rest); i++ {
t1.Run(fmt.Sprintf("%v", i), func(t *testing.T) { suite.Run(fmt.Sprintf("%v", i), func() {
t := suite.T()
p, err = p.Dir() p, err = p.Dir()
require.NoError(t, err) require.NoError(t, err)
@ -232,9 +241,9 @@ func (suite *DataLayerResourcePath) TestDir() {
}) })
} }
t1.Run("All", func(t *testing.T) { suite.Run("All", func() {
p, err = p.Dir() p, err = p.Dir()
assert.Error(t, err) assert.Error(suite.T(), err)
}) })
}) })
} }
@ -317,11 +326,13 @@ func (suite *DataLayerResourcePath) TestToServiceCategoryMetadataPath() {
} }
for _, test := range table { for _, test := range table {
suite.T().Run(strings.Join([]string{ suite.Run(strings.Join([]string{
test.name, test.name,
test.service.String(), test.service.String(),
test.category.String(), test.category.String(),
}, "_"), func(t *testing.T) { }, "_"), func() {
t := suite.T()
pb := path.Builder{}.Append(test.postfix...) pb := path.Builder{}.Append(test.postfix...)
p, err := pb.ToServiceCategoryMetadataPath( p, err := pb.ToServiceCategoryMetadataPath(
tenant, tenant,
@ -371,9 +382,11 @@ func (suite *DataLayerResourcePath) TestToExchangePathForCategory() {
} }
for _, m := range modes { for _, m := range modes {
suite.T().Run(m.name, func(t1 *testing.T) { suite.Run(m.name, func() {
for _, test := range table { for _, test := range table {
t1.Run(test.category.String(), func(t *testing.T) { suite.Run(test.category.String(), func() {
t := suite.T()
p, err := b.ToDataLayerExchangePathForCategory( p, err := b.ToDataLayerExchangePathForCategory(
testTenant, testTenant,
testUser, testUser,
@ -401,13 +414,13 @@ func (suite *DataLayerResourcePath) TestToExchangePathForCategory() {
} }
type PopulatedDataLayerResourcePath struct { type PopulatedDataLayerResourcePath struct {
suite.Suite tester.Suite
// Bool value is whether the path is an item path or a folder path. // Bool value is whether the path is an item path or a folder path.
paths map[bool]path.Path paths map[bool]path.Path
} }
func TestPopulatedDataLayerResourcePath(t *testing.T) { func TestPopulatedDataLayerResourcePath(t *testing.T) {
suite.Run(t, new(PopulatedDataLayerResourcePath)) suite.Run(t, &PopulatedDataLayerResourcePath{Suite: tester.NewUnitSuite(t)})
} }
func (suite *PopulatedDataLayerResourcePath) SetupSuite() { func (suite *PopulatedDataLayerResourcePath) SetupSuite() {
@ -429,7 +442,9 @@ func (suite *PopulatedDataLayerResourcePath) SetupSuite() {
func (suite *PopulatedDataLayerResourcePath) TestTenant() { func (suite *PopulatedDataLayerResourcePath) TestTenant() {
for _, m := range modes { for _, m := range modes {
suite.T().Run(m.name, func(t *testing.T) { suite.Run(m.name, func() {
t := suite.T()
assert.Equal(t, testTenant, suite.paths[m.isItem].Tenant()) assert.Equal(t, testTenant, suite.paths[m.isItem].Tenant())
}) })
} }
@ -437,7 +452,9 @@ func (suite *PopulatedDataLayerResourcePath) TestTenant() {
func (suite *PopulatedDataLayerResourcePath) TestService() { func (suite *PopulatedDataLayerResourcePath) TestService() {
for _, m := range modes { for _, m := range modes {
suite.T().Run(m.name, func(t *testing.T) { suite.Run(m.name, func() {
t := suite.T()
assert.Equal(t, path.ExchangeService, suite.paths[m.isItem].Service()) assert.Equal(t, path.ExchangeService, suite.paths[m.isItem].Service())
}) })
} }
@ -445,7 +462,9 @@ func (suite *PopulatedDataLayerResourcePath) TestService() {
func (suite *PopulatedDataLayerResourcePath) TestCategory() { func (suite *PopulatedDataLayerResourcePath) TestCategory() {
for _, m := range modes { for _, m := range modes {
suite.T().Run(m.name, func(t *testing.T) { suite.Run(m.name, func() {
t := suite.T()
assert.Equal(t, path.EmailCategory, suite.paths[m.isItem].Category()) assert.Equal(t, path.EmailCategory, suite.paths[m.isItem].Category())
}) })
} }
@ -453,7 +472,9 @@ func (suite *PopulatedDataLayerResourcePath) TestCategory() {
func (suite *PopulatedDataLayerResourcePath) TestResourceOwner() { func (suite *PopulatedDataLayerResourcePath) TestResourceOwner() {
for _, m := range modes { for _, m := range modes {
suite.T().Run(m.name, func(t *testing.T) { suite.Run(m.name, func() {
t := suite.T()
assert.Equal(t, testUser, suite.paths[m.isItem].ResourceOwner()) assert.Equal(t, testUser, suite.paths[m.isItem].ResourceOwner())
}) })
} }
@ -461,7 +482,9 @@ func (suite *PopulatedDataLayerResourcePath) TestResourceOwner() {
func (suite *PopulatedDataLayerResourcePath) TestFolder() { func (suite *PopulatedDataLayerResourcePath) TestFolder() {
for _, m := range modes { for _, m := range modes {
suite.T().Run(m.name, func(t *testing.T) { suite.Run(m.name, func() {
t := suite.T()
assert.Equal( assert.Equal(
t, t,
strings.Join(m.expectedFolders, "/"), strings.Join(m.expectedFolders, "/"),
@ -473,7 +496,9 @@ func (suite *PopulatedDataLayerResourcePath) TestFolder() {
func (suite *PopulatedDataLayerResourcePath) TestFolders() { func (suite *PopulatedDataLayerResourcePath) TestFolders() {
for _, m := range modes { for _, m := range modes {
suite.T().Run(m.name, func(t *testing.T) { suite.Run(m.name, func() {
t := suite.T()
assert.Equal(t, m.expectedFolders, suite.paths[m.isItem].Folders()) assert.Equal(t, m.expectedFolders, suite.paths[m.isItem].Folders())
}) })
} }
@ -481,7 +506,9 @@ func (suite *PopulatedDataLayerResourcePath) TestFolders() {
func (suite *PopulatedDataLayerResourcePath) TestItem() { func (suite *PopulatedDataLayerResourcePath) TestItem() {
for _, m := range modes { for _, m := range modes {
suite.T().Run(m.name, func(t *testing.T) { suite.Run(m.name, func() {
t := suite.T()
assert.Equal(t, m.expectedItem, suite.paths[m.isItem].Item()) assert.Equal(t, m.expectedItem, suite.paths[m.isItem].Item())
}) })
} }
@ -514,9 +541,11 @@ func (suite *PopulatedDataLayerResourcePath) TestAppend() {
} }
for _, m := range modes { for _, m := range modes {
suite.T().Run(m.name, func(t1 *testing.T) { suite.Run(m.name, func() {
for _, test := range isItem { for _, test := range isItem {
t1.Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
t := suite.T()
newPath, err := suite.paths[m.isItem].Append(newElement, test.hasItem) newPath, err := suite.paths[m.isItem].Append(newElement, test.hasItem)
// Items don't allow appending. // Items don't allow appending.
@ -593,7 +622,9 @@ func (suite *PopulatedDataLayerResourcePath) TestUpdateParent() {
} }
for _, tc := range cases { for _, tc := range cases {
suite.T().Run(tc.name, func(t *testing.T) { suite.Run(tc.name, func() {
t := suite.T()
item := buildPath(t, tc.item, true) item := buildPath(t, tc.item, true)
prev := buildPath(t, tc.prev, false) prev := buildPath(t, tc.prev, false)
cur := buildPath(t, tc.cur, false) cur := buildPath(t, tc.cur, false)

View File

@ -6,14 +6,17 @@ 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"
) )
type ServiceCategoryUnitSuite struct { type ServiceCategoryUnitSuite struct {
suite.Suite tester.Suite
} }
func TestServiceCategoryUnitSuite(t *testing.T) { func TestServiceCategoryUnitSuite(t *testing.T) {
suite.Run(t, new(ServiceCategoryUnitSuite)) s := &ServiceCategoryUnitSuite{Suite: tester.NewUnitSuite(t)}
suite.Run(t, s)
} }
func (suite *ServiceCategoryUnitSuite) TestValidateServiceAndCategoryBadStringErrors() { func (suite *ServiceCategoryUnitSuite) TestValidateServiceAndCategoryBadStringErrors() {
@ -34,7 +37,7 @@ func (suite *ServiceCategoryUnitSuite) TestValidateServiceAndCategoryBadStringEr
}, },
} }
for _, test := range table { for _, test := range table {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
_, _, err := validateServiceAndCategoryStrings(test.service, test.category) _, _, err := validateServiceAndCategoryStrings(test.service, test.category)
assert.Error(suite.T(), err) assert.Error(suite.T(), err)
}) })
@ -116,7 +119,9 @@ func (suite *ServiceCategoryUnitSuite) TestValidateServiceAndCategory() {
}, },
} }
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()
s, c, err := validateServiceAndCategoryStrings(test.service, test.category) s, c, err := validateServiceAndCategoryStrings(test.service, test.category)
test.check(t, err) test.check(t, err)
@ -148,7 +153,9 @@ func (suite *ServiceCategoryUnitSuite) TestToServiceType() {
}, },
} }
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()
assert.Equal(t, test.expected, toServiceType(test.service)) assert.Equal(t, test.expected, toServiceType(test.service))
}) })
} }
@ -172,7 +179,9 @@ func (suite *ServiceCategoryUnitSuite) TestToCategoryType() {
}, },
} }
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()
assert.Equal(t, test.expected, ToCategoryType(test.category)) assert.Equal(t, test.expected, ToCategoryType(test.category))
}) })
} }

View File

@ -20,11 +20,11 @@ import (
// --------------- // ---------------
type RepositorySuite struct { type RepositorySuite struct {
suite.Suite tester.Suite
} }
func TestRepositorySuite(t *testing.T) { func TestRepositorySuite(t *testing.T) {
suite.Run(t, new(RepositorySuite)) suite.Run(t, &RepositorySuite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *RepositorySuite) TestInitialize() { func (suite *RepositorySuite) TestInitialize() {
@ -44,7 +44,9 @@ func (suite *RepositorySuite) TestInitialize() {
}, },
} }
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()
@ -75,7 +77,9 @@ func (suite *RepositorySuite) TestConnect() {
}, },
} }
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()
@ -92,21 +96,17 @@ func (suite *RepositorySuite) TestConnect() {
// --------------- // ---------------
type RepositoryIntegrationSuite struct { type RepositoryIntegrationSuite struct {
suite.Suite tester.Suite
} }
func TestRepositoryIntegrationSuite(t *testing.T) { func TestRepositoryIntegrationSuite(t *testing.T) {
tester.RunOnAny( suite.Run(t, &RepositoryIntegrationSuite{
t, Suite: tester.NewIntegrationSuite(
tester.CorsoCITests, t,
tester.CorsoRepositoryTests) [][]string{tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs},
tester.CorsoRepositoryTests,
suite.Run(t, new(RepositoryIntegrationSuite)) ),
} })
// ensure all required env values are populated
func (suite *RepositoryIntegrationSuite) SetupSuite() {
tester.MustGetEnvSets(suite.T(), tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs)
} }
func (suite *RepositoryIntegrationSuite) TestInitialize() { func (suite *RepositoryIntegrationSuite) TestInitialize() {
@ -126,7 +126,9 @@ func (suite *RepositoryIntegrationSuite) TestInitialize() {
}, },
} }
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()
st := test.storage(t) st := test.storage(t)
r, err := repository.Initialize(ctx, test.account, st, control.Options{}) r, err := repository.Initialize(ctx, test.account, st, control.Options{})
if err == nil { if err == nil {

View File

@ -12,21 +12,17 @@ import (
) )
type RepositoryModelSuite struct { type RepositoryModelSuite struct {
suite.Suite tester.Suite
} }
func TestRepositoryModelSuite(t *testing.T) { func TestRepositoryModelSuite(t *testing.T) {
tester.RunOnAny( suite.Run(t, &RepositoryModelSuite{
t, Suite: tester.NewIntegrationSuite(
tester.CorsoCITests, t,
tester.CorsoRepositoryTests) [][]string{tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs},
tester.CorsoRepositoryTests,
suite.Run(t, new(RepositoryModelSuite)) ),
} })
// ensure all required env values are populated
func (suite *RepositoryModelSuite) SetupSuite() {
tester.MustGetEnvSets(suite.T(), tester.AWSStorageCredEnvs, tester.M365AcctCredEnvs)
} }
func (suite *RepositoryModelSuite) TestWriteGetModel() { func (suite *RepositoryModelSuite) TestWriteGetModel() {

View File

@ -17,11 +17,11 @@ import (
) )
type ExchangeSelectorSuite struct { type ExchangeSelectorSuite struct {
suite.Suite tester.Suite
} }
func TestExchangeSelectorSuite(t *testing.T) { func TestExchangeSelectorSuite(t *testing.T) {
suite.Run(t, new(ExchangeSelectorSuite)) suite.Run(t, &ExchangeSelectorSuite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *ExchangeSelectorSuite) TestNewExchangeBackup() { func (suite *ExchangeSelectorSuite) TestNewExchangeBackup() {
@ -693,7 +693,9 @@ func (suite *ExchangeSelectorSuite) TestExchangeScope_MatchesInfo() {
{"contact with a subname search", details.ExchangeContact, es.ContactName(name[2:5]), assert.True}, {"contact with a subname search", details.ExchangeContact, es.ContactName(name[2:5]), assert.True},
} }
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()
scopes := setScopesToDefault(test.scope) scopes := setScopesToDefault(test.scope)
for _, scope := range scopes { for _, scope := range scopes {
test.expect(t, scope.matchesInfo(infoWith(test.itype))) test.expect(t, scope.matchesInfo(infoWith(test.itype)))
@ -750,7 +752,9 @@ func (suite *ExchangeSelectorSuite) TestExchangeScope_MatchesPath() {
{"non-leaf short ref", es.Mails([]string{short}, []string{"foo"}), short, assert.False}, {"non-leaf short ref", es.Mails([]string{short}, []string{"foo"}), short, assert.False},
} }
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()
scopes := setScopesToDefault(test.scope) scopes := setScopesToDefault(test.scope)
var aMatch bool var aMatch bool
for _, scope := range scopes { for _, scope := range scopes {
@ -1034,7 +1038,9 @@ func (suite *ExchangeSelectorSuite) TestExchangeRestore_Reduce() {
}, },
} }
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()
@ -1258,7 +1264,9 @@ func (suite *ExchangeSelectorSuite) TestExchangeRestore_Reduce_locationRef() {
}, },
} }
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()
@ -1315,7 +1323,9 @@ func (suite *ExchangeSelectorSuite) TestScopesByCategory() {
{"all", makeInput(allData, contacts, events, mail), expect{2, 2, 2}}, {"all", makeInput(allData, contacts, events, mail), expect{2, 2, 2}},
} }
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()
result := scopesByCategory[ExchangeScope](test.scopes, cats, false) result := scopesByCategory[ExchangeScope](test.scopes, cats, false)
assert.Len(t, result[ExchangeContact], test.expect.contact) assert.Len(t, result[ExchangeContact], test.expect.contact)
assert.Len(t, result[ExchangeEvent], test.expect.event) assert.Len(t, result[ExchangeEvent], test.expect.event)
@ -1359,7 +1369,9 @@ func (suite *ExchangeSelectorSuite) TestPasses() {
{"filter Other", nil, otherMail, allMail, assert.False}, {"filter Other", nil, otherMail, allMail, assert.False},
} }
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()
repoVals, locVals := cat.pathValues(pth, pth) repoVals, locVals := cat.pathValues(pth, pth)
result := passes( result := passes(
@ -1399,7 +1411,9 @@ func (suite *ExchangeSelectorSuite) TestContains() {
{"wrong type but right target", wrongTypeGoodTarget, assert.False}, {"wrong type but right target", wrongTypeGoodTarget, assert.False},
} }
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()
var result bool var result bool
for _, scope := range test.scopes { for _, scope := range test.scopes {
if scope.Matches(ExchangeMail, target) { if scope.Matches(ExchangeMail, target) {
@ -1430,7 +1444,9 @@ func (suite *ExchangeSelectorSuite) TestIsAny() {
{"wrong category", anyMail, ExchangeEvent, assert.False}, {"wrong category", anyMail, ExchangeEvent, assert.False},
} }
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()
var result bool var result bool
for _, scope := range test.scopes { for _, scope := range test.scopes {
if scope.IsAny(test.cat) { if scope.IsAny(test.cat) {
@ -1553,7 +1569,9 @@ func (suite *ExchangeSelectorSuite) TestCategoryFromItemType() {
}, },
} }
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()
result := categoryFromItemType(test.input) result := categoryFromItemType(test.input)
assert.Equal(t, test.expect, result) assert.Equal(t, test.expect, result)
}) })

View File

@ -16,11 +16,11 @@ import (
) )
type OneDriveSelectorSuite struct { type OneDriveSelectorSuite struct {
suite.Suite tester.Suite
} }
func TestOneDriveSelectorSuite(t *testing.T) { func TestOneDriveSelectorSuite(t *testing.T) {
suite.Run(t, new(OneDriveSelectorSuite)) suite.Run(t, &OneDriveSelectorSuite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *OneDriveSelectorSuite) TestNewOneDriveBackup() { func (suite *OneDriveSelectorSuite) TestNewOneDriveBackup() {
@ -65,7 +65,9 @@ func (suite *OneDriveSelectorSuite) TestOneDriveSelector_AllData() {
{"Filter Scopes", sel.Filters}, {"Filter Scopes", sel.Filters},
} }
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()
require.Len(t, test.scopesToCheck, 1) require.Len(t, test.scopesToCheck, 1)
for _, scope := range test.scopesToCheck { for _, scope := range test.scopesToCheck {
scopeMustHave( scopeMustHave(
@ -238,7 +240,9 @@ func (suite *OneDriveSelectorSuite) TestOneDriveRestore_Reduce() {
}, },
} }
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()
@ -307,7 +311,9 @@ func (suite *OneDriveSelectorSuite) TestOneDriveScope_MatchesInfo() {
{"file modified before epoch", ods.ModifiedBefore(common.FormatTime(now)), assert.False}, {"file modified before epoch", ods.ModifiedBefore(common.FormatTime(now)), assert.False},
} }
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()
scopes := setScopesToDefault(test.scope) scopes := setScopesToDefault(test.scope)
for _, scope := range scopes { for _, scope := range scopes {
test.expect(t, scope.matchesInfo(itemInfo)) test.expect(t, scope.matchesInfo(itemInfo))

View File

@ -19,11 +19,11 @@ import (
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
type SelectorScopesSuite struct { type SelectorScopesSuite struct {
suite.Suite tester.Suite
} }
func TestSelectorScopesSuite(t *testing.T) { func TestSelectorScopesSuite(t *testing.T) {
suite.Run(t, new(SelectorScopesSuite)) suite.Run(t, &SelectorScopesSuite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *SelectorScopesSuite) TestContains() { func (suite *SelectorScopesSuite) TestContains() {
@ -94,7 +94,9 @@ func (suite *SelectorScopesSuite) TestContains() {
}, },
} }
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( test.expect(
t, t,
matches(test.scope(), rootCatStub, test.check)) matches(test.scope(), rootCatStub, test.check))
@ -270,7 +272,9 @@ func (suite *SelectorScopesSuite) TestReduce() {
} }
for _, test := range reduceTestTable { for _, test := range reduceTestTable {
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()
@ -314,7 +318,9 @@ func (suite *SelectorScopesSuite) TestReduce_locationRef() {
} }
for _, test := range reduceTestTable { for _, test := range reduceTestTable {
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()
@ -354,7 +360,9 @@ func (suite *SelectorScopesSuite) TestPasses() {
entry := details.DetailsEntry{} entry := details.DetailsEntry{}
for _, test := range reduceTestTable { for _, test := range reduceTestTable {
suite.T().Run(test.name, func(t *testing.T) { suite.Run(test.name, func() {
t := suite.T()
sel := test.sel() sel := test.sel()
excl := toMockScope(sel.Excludes) excl := toMockScope(sel.Excludes)
filt := toMockScope(sel.Filters) filt := toMockScope(sel.Filters)
@ -430,7 +438,9 @@ func (suite *SelectorScopesSuite) TestMatchesPathValues() {
}, },
} }
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()
sc := stubScope("") sc := stubScope("")
sc[rootCatStub.String()] = filterize(scopeConfig{}, test.rootVal) sc[rootCatStub.String()] = filterize(scopeConfig{}, test.rootVal)
sc[leafCatStub.String()] = filterize(scopeConfig{}, test.leafVal) sc[leafCatStub.String()] = filterize(scopeConfig{}, test.leafVal)
@ -478,7 +488,9 @@ func (suite *SelectorScopesSuite) TestClean() {
}, },
} }
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()
result := clean(test.input) result := clean(test.input)
assert.Equal(t, result, test.expect) assert.Equal(t, result, test.expect)
}) })
@ -516,7 +528,9 @@ func (suite *SelectorScopesSuite) TestWrapFilter() {
}, },
} }
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()
ff := wrapFilter(test.filter)(test.input) ff := wrapFilter(test.filter)(test.input)
assert.Equal(t, int(ff.Comparator), test.comparator) assert.Equal(t, int(ff.Comparator), test.comparator)
assert.Equal(t, ff.Target, test.target) assert.Equal(t, ff.Target, test.target)
@ -544,7 +558,9 @@ func (suite *SelectorScopesSuite) TestScopeConfig() {
}, },
} }
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()
result := filterize(test.config, input) result := filterize(test.config, input)
assert.Equal(t, test.expect, int(result.Comparator)) assert.Equal(t, test.expect, int(result.Comparator))
}) })

View File

@ -16,11 +16,11 @@ import (
) )
type SelectorReduceSuite struct { type SelectorReduceSuite struct {
suite.Suite tester.Suite
} }
func TestSelectorReduceSuite(t *testing.T) { func TestSelectorReduceSuite(t *testing.T) {
suite.Run(t, new(SelectorReduceSuite)) suite.Run(t, &SelectorReduceSuite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *SelectorReduceSuite) TestReduce() { func (suite *SelectorReduceSuite) TestReduce() {
@ -264,7 +264,9 @@ func (suite *SelectorReduceSuite) TestReduce() {
} }
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()
output := test.selFunc().Reduce(ctx, allDetails, fault.New(true)) output := test.selFunc().Reduce(ctx, allDetails, fault.New(true))
assert.ElementsMatch(t, test.expected, output.Entries) assert.ElementsMatch(t, test.expected, output.Entries)
}) })

View File

@ -6,16 +6,17 @@ 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/filters" "github.com/alcionai/corso/src/pkg/filters"
"github.com/alcionai/corso/src/pkg/path" "github.com/alcionai/corso/src/pkg/path"
) )
type SelectorSuite struct { type SelectorSuite struct {
suite.Suite tester.Suite
} }
func TestSelectorSuite(t *testing.T) { func TestSelectorSuite(t *testing.T) {
suite.Run(t, new(SelectorSuite)) suite.Run(t, &SelectorSuite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *SelectorSuite) TestNewSelector() { func (suite *SelectorSuite) TestNewSelector() {
@ -87,7 +88,9 @@ func (suite *SelectorSuite) TestResourceOwnersIn() {
}, },
} }
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()
result := resourceOwnersIn(test.input, rootCat) result := resourceOwnersIn(test.input, rootCat)
assert.ElementsMatch(t, test.expect, result) assert.ElementsMatch(t, test.expect, result)
}) })
@ -120,7 +123,9 @@ func (suite *SelectorSuite) TestPathCategoriesIn() {
}, },
} }
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()
result := pathCategoriesIn[mockScope, mockCategorizer](test.input) result := pathCategoriesIn[mockScope, mockCategorizer](test.input)
assert.ElementsMatch(t, test.expect, result) assert.ElementsMatch(t, test.expect, result)
}) })
@ -218,7 +223,9 @@ func (suite *SelectorSuite) TestSplitByResourceOnwer() {
}, },
} }
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()
s := newSelector(ServiceUnknown, test.input) s := newSelector(ServiceUnknown, test.input)
result := splitByResourceOwner[mockScope](s, allOwners, rootCatStub) result := splitByResourceOwner[mockScope](s, allOwners, rootCatStub)
@ -356,7 +363,9 @@ func (suite *SelectorSuite) TestPathCategories_includes() {
}, },
} }
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()
obj := test.getSelector(t) obj := test.getSelector(t)
cats, err := obj.PathCategories() cats, err := obj.PathCategories()
for _, entry := range cats.Includes { for _, entry := range cats.Includes {

View File

@ -14,11 +14,11 @@ import (
) )
type SharePointSelectorSuite struct { type SharePointSelectorSuite struct {
suite.Suite tester.Suite
} }
func TestSharePointSelectorSuite(t *testing.T) { func TestSharePointSelectorSuite(t *testing.T) {
suite.Run(t, new(SharePointSelectorSuite)) suite.Run(t, &SharePointSelectorSuite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *SharePointSelectorSuite) TestNewSharePointBackup() { func (suite *SharePointSelectorSuite) TestNewSharePointBackup() {
@ -136,7 +136,9 @@ func (suite *SharePointSelectorSuite) TestSharePointSelector_Include_WebURLs_any
}, },
} }
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 := NewSharePointRestore(Any()) sel := NewSharePointRestore(Any())
sel.Include(sel.WebURL(test.in)) sel.Include(sel.WebURL(test.in))
scopes := sel.Includes scopes := sel.Includes
@ -302,7 +304,9 @@ func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() {
}, },
} }
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()
@ -341,7 +345,9 @@ func (suite *SharePointSelectorSuite) TestSharePointCategory_PathValues() {
} }
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()
itemPath, err := pathBuilder.ToDataLayerSharePointPath( itemPath, err := pathBuilder.ToDataLayerSharePointPath(
"tenant", "tenant",
"site", "site",
@ -381,7 +387,9 @@ func (suite *SharePointSelectorSuite) TestSharePointScope_MatchesInfo() {
{"host mismatch", host, ods.WebURL([]string{"www.google.com"}), assert.False}, {"host mismatch", host, ods.WebURL([]string{"www.google.com"}), assert.False},
} }
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()
itemInfo := details.ItemInfo{ itemInfo := details.ItemInfo{
SharePoint: &details.SharePointInfo{ SharePoint: &details.SharePointInfo{
ItemType: details.SharePointItem, ItemType: details.SharePointItem,

View File

@ -12,16 +12,16 @@ import (
) )
type M365IntegrationSuite struct { type M365IntegrationSuite struct {
suite.Suite tester.Suite
} }
func TestM365IntegrationSuite(t *testing.T) { func TestM365IntegrationSuite(t *testing.T) {
tester.RunOnAny(t, tester.CorsoCITests) suite.Run(t, &M365IntegrationSuite{
suite.Run(t, new(M365IntegrationSuite)) Suite: tester.NewIntegrationSuite(
} t,
[][]string{tester.M365AcctCredEnvs},
func (suite *M365IntegrationSuite) SetupSuite() { ),
tester.MustGetEnvSets(suite.T(), tester.M365AcctCredEnvs) })
} }
func (suite *M365IntegrationSuite) TestUsers() { func (suite *M365IntegrationSuite) TestUsers() {
@ -39,7 +39,9 @@ func (suite *M365IntegrationSuite) TestUsers() {
require.Greater(t, len(users), 0) require.Greater(t, len(users), 0)
for _, u := range users { for _, u := range users {
t.Run("user_"+u.ID, func(t *testing.T) { suite.Run("user_"+u.ID, func() {
t := suite.T()
assert.NotEmpty(t, u.ID) assert.NotEmpty(t, u.ID)
assert.NotEmpty(t, u.PrincipalName) assert.NotEmpty(t, u.PrincipalName)
assert.NotEmpty(t, u.Name) assert.NotEmpty(t, u.Name)

View File

@ -34,11 +34,11 @@ var (
) )
type StoreBackupUnitSuite struct { type StoreBackupUnitSuite struct {
suite.Suite tester.Suite
} }
func TestStoreBackupUnitSuite(t *testing.T) { func TestStoreBackupUnitSuite(t *testing.T) {
suite.Run(t, new(StoreBackupUnitSuite)) suite.Run(t, &StoreBackupUnitSuite{Suite: tester.NewUnitSuite(t)})
} }
func (suite *StoreBackupUnitSuite) TestGetBackup() { func (suite *StoreBackupUnitSuite) TestGetBackup() {
@ -62,7 +62,9 @@ func (suite *StoreBackupUnitSuite) TestGetBackup() {
}, },
} }
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()
sm := &store.Wrapper{Storer: test.mock} sm := &store.Wrapper{Storer: test.mock}
result, err := sm.GetBackup(ctx, model.StableID(uuid.NewString())) result, err := sm.GetBackup(ctx, model.StableID(uuid.NewString()))
test.expect(t, err) test.expect(t, err)
@ -95,7 +97,9 @@ func (suite *StoreBackupUnitSuite) TestGetBackups() {
}, },
} }
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()
sm := &store.Wrapper{Storer: test.mock} sm := &store.Wrapper{Storer: test.mock}
result, err := sm.GetBackups(ctx) result, err := sm.GetBackups(ctx)
test.expect(t, err) test.expect(t, err)
@ -129,7 +133,9 @@ func (suite *StoreBackupUnitSuite) TestDeleteBackup() {
}, },
} }
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()
sm := &store.Wrapper{Storer: test.mock} sm := &store.Wrapper{Storer: test.mock}
err := sm.DeleteBackup(ctx, model.StableID(uuid.NewString())) err := sm.DeleteBackup(ctx, model.StableID(uuid.NewString()))
test.expect(t, err) test.expect(t, err)
@ -158,7 +164,9 @@ func (suite *StoreBackupUnitSuite) TestGetDetailsIDFromBackupID() {
}, },
} }
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()
store := &store.Wrapper{Storer: test.mock} store := &store.Wrapper{Storer: test.mock}
dResult, bResult, err := store.GetDetailsIDFromBackupID(ctx, model.StableID(uuid.NewString())) dResult, bResult, err := store.GetDetailsIDFromBackupID(ctx, model.StableID(uuid.NewString()))
test.expect(t, err) test.expect(t, err)