Remove duplicate mocks from kopia wrapper tests (#4083)

<!-- PR description-->

No logic changes. Only removing duplicate test code.


---

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

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Supportability/Tests
- [ ] 💻 CI/Deployment
- [x] 🧹 Tech Debt/Cleanup

#### Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->
* #<issue>

#### Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
Abhishek Pandey 2023-08-22 18:25:08 +05:30 committed by GitHub
parent 0e6ef90e41
commit 4ace4bee76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,6 +25,7 @@ import (
"github.com/alcionai/corso/src/internal/data" "github.com/alcionai/corso/src/internal/data"
dataMock "github.com/alcionai/corso/src/internal/data/mock" dataMock "github.com/alcionai/corso/src/internal/data/mock"
"github.com/alcionai/corso/src/internal/m365/collection/drive/metadata" "github.com/alcionai/corso/src/internal/m365/collection/drive/metadata"
m365Mock "github.com/alcionai/corso/src/internal/m365/mock"
exchMock "github.com/alcionai/corso/src/internal/m365/service/exchange/mock" exchMock "github.com/alcionai/corso/src/internal/m365/service/exchange/mock"
"github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/pkg/backup/details" "github.com/alcionai/corso/src/pkg/backup/details"
@ -1128,10 +1129,10 @@ func (suite *KopiaIntegrationSuite) TestBackupCollections_NoDetailsForMeta() {
streams = append(streams, ms) streams = append(streams, ms)
} }
mc := &mockBackupCollection{ mc := &m365Mock.BackupCollection{
path: storePath, Path: storePath,
loc: locPath, Loc: locPath,
streams: streams, Streams: streams,
} }
return []data.BackupCollection{mc} return []data.BackupCollection{mc}
@ -1155,11 +1156,11 @@ func (suite *KopiaIntegrationSuite) TestBackupCollections_NoDetailsForMeta() {
ItemInfo: details.ItemInfo{OneDrive: &info}, ItemInfo: details.ItemInfo{OneDrive: &info},
} }
mc := &mockBackupCollection{ mc := &m365Mock.BackupCollection{
path: storePath, Path: storePath,
loc: locPath, Loc: locPath,
streams: []data.Item{ms}, Streams: []data.Item{ms},
state: data.NotMovedState, CState: data.NotMovedState,
} }
return []data.BackupCollection{mc} return []data.BackupCollection{mc}
@ -1293,48 +1294,6 @@ func (suite *KopiaIntegrationSuite) TestRestoreAfterCompressionChange() {
testForFiles(t, ctx, expected, result) testForFiles(t, ctx, expected, result)
} }
// TODO(pandeyabs): Switch to m365/mock/BackupCollection.
type mockBackupCollection struct {
path path.Path
loc *path.Builder
streams []data.Item
state data.CollectionState
}
func (c *mockBackupCollection) Items(context.Context, *fault.Bus) <-chan data.Item {
res := make(chan data.Item)
go func() {
defer close(res)
for _, s := range c.streams {
res <- s
}
}()
return res
}
func (c mockBackupCollection) FullPath() path.Path {
return c.path
}
func (c mockBackupCollection) PreviousPath() path.Path {
return c.path
}
func (c mockBackupCollection) LocationPath() *path.Builder {
return c.loc
}
func (c mockBackupCollection) State() data.CollectionState {
return c.state
}
func (c mockBackupCollection) DoNotMergeItems() bool {
return false
}
func (suite *KopiaIntegrationSuite) TestBackupCollections_ReaderError() { func (suite *KopiaIntegrationSuite) TestBackupCollections_ReaderError() {
t := suite.T() t := suite.T()
@ -1343,10 +1302,10 @@ func (suite *KopiaIntegrationSuite) TestBackupCollections_ReaderError() {
r := NewReason(testTenant, testUser, path.ExchangeService, path.EmailCategory) r := NewReason(testTenant, testUser, path.ExchangeService, path.EmailCategory)
collections := []data.BackupCollection{ collections := []data.BackupCollection{
&mockBackupCollection{ &m365Mock.BackupCollection{
path: suite.storePath1, Path: suite.storePath1,
loc: loc1, Loc: loc1,
streams: []data.Item{ Streams: []data.Item{
&dataMock.Item{ &dataMock.Item{
ItemID: testFileName, ItemID: testFileName,
Reader: io.NopCloser(bytes.NewReader(testFileData)), Reader: io.NopCloser(bytes.NewReader(testFileData)),
@ -1359,10 +1318,10 @@ func (suite *KopiaIntegrationSuite) TestBackupCollections_ReaderError() {
}, },
}, },
}, },
&mockBackupCollection{ &m365Mock.BackupCollection{
path: suite.storePath2, Path: suite.storePath2,
loc: loc2, Loc: loc2,
streams: []data.Item{ Streams: []data.Item{
&dataMock.Item{ &dataMock.Item{
ItemID: testFileName3, ItemID: testFileName3,
Reader: io.NopCloser(bytes.NewReader(testFileData3)), Reader: io.NopCloser(bytes.NewReader(testFileData3)),
@ -1603,11 +1562,11 @@ func (suite *KopiaSimpleRepoIntegrationSuite) SetupTest() {
for _, parent := range []path.Path{suite.testPath1, suite.testPath2} { for _, parent := range []path.Path{suite.testPath1, suite.testPath2} {
loc := path.Builder{}.Append(parent.Folders()...) loc := path.Builder{}.Append(parent.Folders()...)
collection := &mockBackupCollection{path: parent, loc: loc} collection := &m365Mock.BackupCollection{Path: parent, Loc: loc}
for _, item := range suite.files[parent.String()] { for _, item := range suite.files[parent.String()] {
collection.streams = append( collection.Streams = append(
collection.streams, collection.Streams,
&dataMock.Item{ &dataMock.Item{
ItemID: item.itemPath.Item(), ItemID: item.itemPath.Item(),
Reader: io.NopCloser(bytes.NewReader(item.data)), Reader: io.NopCloser(bytes.NewReader(item.data)),