From 86f9d60bf700e8f89c73b8a39847b6ef5004aa61 Mon Sep 17 00:00:00 2001 From: Keepers Date: Mon, 17 Apr 2023 11:54:19 -0600 Subject: [PATCH] relocate connector mocks (#3048) It makes more sense for mock data types to be owned by the service package, not by the connector package as a whole. --- #### Does this PR need a docs update or release note? - [x] :no_entry: No #### Type of change - [x] :broom: Tech Debt/Cleanup #### Test Plan - [x] :zap: Unit test - [x] :green_heart: E2E --- src/cmd/factory/impl/common.go | 4 +- src/cmd/factory/impl/exchange.go | 10 +- .../connector/exchange/api/api_test.go | 6 +- .../connector/exchange/api/events_test.go | 4 +- .../connector/exchange/iterators_test.go | 6 +- .../mock/collections.go} | 91 ++++++++----------- .../mock/contact.go} | 10 +- .../mock/event.go} | 28 +++--- .../mock/mail.go} | 62 ++++++------- .../mock/mock_test.go} | 81 ++++------------- .../connector/exchange/restore_test.go | 42 ++++----- .../connector/graph_connector_helper_test.go | 6 +- .../connector/graph_connector_test.go | 76 +++++++--------- .../connector.go} | 2 +- src/internal/connector/mock/id_name_getter.go | 15 +++ .../connector/sharepoint/api/pages_test.go | 4 +- .../connector/sharepoint/collection_test.go | 8 +- .../mock/list.go} | 54 +++++------ .../connector/sharepoint/mock/mock_test.go | 75 +++++++++++++++ .../mock/page.go} | 6 +- .../connector/support/m365Support_test.go | 11 ++- .../connector/support/m365Transform_test.go | 14 +-- src/internal/kopia/data_collection_test.go | 4 +- src/internal/kopia/upload_test.go | 80 ++++++++-------- src/internal/kopia/wrapper_test.go | 30 +++--- .../operations/backup_integration_test.go | 15 +-- src/internal/operations/backup_test.go | 4 +- src/internal/operations/restore_test.go | 9 +- 28 files changed, 391 insertions(+), 366 deletions(-) rename src/internal/connector/{mockconnector/mock_data_collection.go => exchange/mock/collections.go} (60%) rename src/internal/connector/{mockconnector/mock_data_contact.go => exchange/mock/contact.go} (89%) rename src/internal/connector/{mockconnector/mock_data_event.go => exchange/mock/event.go} (97%) rename src/internal/connector/{mockconnector/mock_data_message.go => exchange/mock/mail.go} (97%) rename src/internal/connector/{mockconnector/mock_data_collection_test.go => exchange/mock/mock_test.go} (61%) rename src/internal/connector/{mockconnector/mock_data_connector.go => mock/connector.go} (98%) create mode 100644 src/internal/connector/mock/id_name_getter.go rename src/internal/connector/{mockconnector/mock_data_list.go => sharepoint/mock/list.go} (74%) create mode 100644 src/internal/connector/sharepoint/mock/mock_test.go rename src/internal/connector/{mockconnector/mock_data_page.go => sharepoint/mock/page.go} (94%) diff --git a/src/cmd/factory/impl/common.go b/src/cmd/factory/impl/common.go index f2760ad3f..16fed2cd6 100644 --- a/src/cmd/factory/impl/common.go +++ b/src/cmd/factory/impl/common.go @@ -12,8 +12,8 @@ import ( "github.com/alcionai/corso/src/cli/print" "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/connector" + exchMock "github.com/alcionai/corso/src/internal/connector/exchange/mock" "github.com/alcionai/corso/src/internal/connector/graph" - "github.com/alcionai/corso/src/internal/connector/mockconnector" "github.com/alcionai/corso/src/internal/data" "github.com/alcionai/corso/src/internal/version" "github.com/alcionai/corso/src/pkg/account" @@ -183,7 +183,7 @@ func buildCollections( return nil, err } - mc := mockconnector.NewMockExchangeCollection(pth, pth, len(c.items)) + mc := exchMock.NewCollection(pth, pth, len(c.items)) for i := 0; i < len(c.items); i++ { mc.Names[i] = c.items[i].name diff --git a/src/cmd/factory/impl/exchange.go b/src/cmd/factory/impl/exchange.go index d88f60eaa..a28fe3389 100644 --- a/src/cmd/factory/impl/exchange.go +++ b/src/cmd/factory/impl/exchange.go @@ -5,7 +5,7 @@ import ( . "github.com/alcionai/corso/src/cli/print" "github.com/alcionai/corso/src/cli/utils" - "github.com/alcionai/corso/src/internal/connector/mockconnector" + exchMock "github.com/alcionai/corso/src/internal/connector/exchange/mock" "github.com/alcionai/corso/src/pkg/control" "github.com/alcionai/corso/src/pkg/fault" "github.com/alcionai/corso/src/pkg/logger" @@ -66,7 +66,7 @@ func handleExchangeEmailFactory(cmd *cobra.Command, args []string) error { Tenant, User, Destination, Count, func(id, now, subject, body string) []byte { - return mockconnector.GetMockMessageWith( + return exchMock.MessageWith( User, User, User, subject, body, body, now, now, now, now) @@ -113,9 +113,9 @@ func handleExchangeCalendarEventFactory(cmd *cobra.Command, args []string) error Tenant, User, Destination, Count, func(id, now, subject, body string) []byte { - return mockconnector.GetMockEventWith( + return exchMock.EventWith( User, subject, body, body, - now, now, mockconnector.NoRecurrence, mockconnector.NoAttendees, false) + now, now, exchMock.NoRecurrence, exchMock.NoAttendees, false) }, control.Options{}, errs) @@ -161,7 +161,7 @@ func handleExchangeContactFactory(cmd *cobra.Command, args []string) error { func(id, now, subject, body string) []byte { given, mid, sur := id[:8], id[9:13], id[len(id)-12:] - return mockconnector.GetMockContactBytesWith( + return exchMock.ContactBytesWith( given+" "+sur, sur+", "+given, given, mid, sur, diff --git a/src/internal/connector/exchange/api/api_test.go b/src/internal/connector/exchange/api/api_test.go index 3d15cc6ec..cfaf8976f 100644 --- a/src/internal/connector/exchange/api/api_test.go +++ b/src/internal/connector/exchange/api/api_test.go @@ -9,8 +9,8 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + exchMock "github.com/alcionai/corso/src/internal/connector/exchange/mock" "github.com/alcionai/corso/src/internal/connector/graph" - "github.com/alcionai/corso/src/internal/connector/mockconnector" "github.com/alcionai/corso/src/internal/connector/support" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/account" @@ -97,7 +97,7 @@ func (suite *ExchangeServiceSuite) TestHasAttachments() { name: "Mock w/out attachment", hasAttachment: assert.False, getBodyable: func(t *testing.T) models.ItemBodyable { - byteArray := mockconnector.GetMockMessageWithBodyBytes( + byteArray := exchMock.MessageWithBodyBytes( "Test", "This is testing", "This is testing", @@ -111,7 +111,7 @@ func (suite *ExchangeServiceSuite) TestHasAttachments() { name: "Mock w/ inline attachment", hasAttachment: assert.True, getBodyable: func(t *testing.T) models.ItemBodyable { - byteArray := mockconnector.GetMessageWithOneDriveAttachment("Test legacy") + byteArray := exchMock.MessageWithOneDriveAttachment("Test legacy") message, err := support.CreateMessageFromBytes(byteArray) require.NoError(t, err, clues.ToCore(err)) return message.GetBody() diff --git a/src/internal/connector/exchange/api/events_test.go b/src/internal/connector/exchange/api/events_test.go index 7482aad3f..a8cf1270b 100644 --- a/src/internal/connector/exchange/api/events_test.go +++ b/src/internal/connector/exchange/api/events_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/alcionai/corso/src/internal/common" - "github.com/alcionai/corso/src/internal/connector/mockconnector" + exchMock "github.com/alcionai/corso/src/internal/connector/exchange/mock" "github.com/alcionai/corso/src/internal/connector/support" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/backup/details" @@ -123,7 +123,7 @@ func (suite *EventsAPIUnitSuite) TestEventInfo() { var ( organizer = "foobar3@8qzvrj.onmicrosoft.com" subject = " Test Mock Review + Lunch" - bytes = mockconnector.GetDefaultMockEventBytes("Test Mock") + bytes = exchMock.EventBytes("Test Mock") future = time.Now().UTC().AddDate(0, 0, 1) eventTime = time.Date(future.Year(), future.Month(), future.Day(), future.Hour(), 0, 0, 0, time.UTC) eventEndTime = eventTime.Add(30 * time.Minute) diff --git a/src/internal/connector/exchange/iterators_test.go b/src/internal/connector/exchange/iterators_test.go index 5e9902b6c..58f66fe55 100644 --- a/src/internal/connector/exchange/iterators_test.go +++ b/src/internal/connector/exchange/iterators_test.go @@ -8,8 +8,8 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + exchMock "github.com/alcionai/corso/src/internal/connector/exchange/mock" "github.com/alcionai/corso/src/internal/connector/graph" - "github.com/alcionai/corso/src/internal/connector/mockconnector" "github.com/alcionai/corso/src/internal/connector/support" "github.com/alcionai/corso/src/internal/tester" ) @@ -24,7 +24,7 @@ func TestExchangeIteratorSuite(t *testing.T) { func (suite *ExchangeIteratorSuite) TestDisplayable() { t := suite.T() - bytes := mockconnector.GetMockContactBytes("Displayable") + bytes := exchMock.ContactBytes("Displayable") contact, err := support.CreateContactFromBytes(bytes) require.NoError(t, err, clues.ToCore(err)) @@ -36,7 +36,7 @@ func (suite *ExchangeIteratorSuite) TestDisplayable() { func (suite *ExchangeIteratorSuite) TestDescendable() { t := suite.T() - bytes := mockconnector.GetMockMessageBytes("Descendable") + bytes := exchMock.MessageBytes("Descendable") message, err := support.CreateMessageFromBytes(bytes) require.NoError(t, err, clues.ToCore(err)) diff --git a/src/internal/connector/mockconnector/mock_data_collection.go b/src/internal/connector/exchange/mock/collections.go similarity index 60% rename from src/internal/connector/mockconnector/mock_data_collection.go rename to src/internal/connector/exchange/mock/collections.go index 0749c6d5f..593af6b9c 100644 --- a/src/internal/connector/mockconnector/mock_data_collection.go +++ b/src/internal/connector/exchange/mock/collections.go @@ -1,4 +1,4 @@ -package mockconnector +package mock import ( "bytes" @@ -15,8 +15,8 @@ import ( "github.com/alcionai/corso/src/pkg/path" ) -// MockExchangeDataCollection represents a mock exchange mailbox -type MockExchangeDataCollection struct { +// DataCollection represents a mock exchange mailbox +type DataCollection struct { fullPath path.Path LocPath path.Path messageCount int @@ -30,20 +30,34 @@ type MockExchangeDataCollection struct { } var ( - _ data.BackupCollection = &MockExchangeDataCollection{} - _ data.Stream = &MockExchangeData{} - _ data.StreamInfo = &MockExchangeData{} - _ data.StreamSize = &MockExchangeData{} + _ data.BackupCollection = &DataCollection{} + _ data.Stream = &Data{} + _ data.StreamInfo = &Data{} + _ data.StreamSize = &Data{} ) -// NewMockExchangeDataCollection creates an data collection that will return the specified number of +func (medc DataCollection) FullPath() path.Path { return medc.fullPath } + +func (medc DataCollection) LocationPath() *path.Builder { + if medc.LocPath == nil { + return nil + } + + return path.Builder{}.Append(medc.LocPath.Folders()...) +} + +func (medc DataCollection) PreviousPath() path.Path { return medc.PrevPath } +func (medc DataCollection) State() data.CollectionState { return medc.ColState } +func (medc DataCollection) DoNotMergeItems() bool { return medc.DoNotMerge } + +// NewCollection creates an data collection that will return the specified number of // mock messages when iterated. Exchange type mail -func NewMockExchangeCollection( +func NewCollection( storagePath path.Path, locationPath path.Path, numMessagesToReturn int, -) *MockExchangeDataCollection { - c := &MockExchangeDataCollection{ +) *DataCollection { + c := &DataCollection{ fullPath: storagePath, LocPath: locationPath, messageCount: numMessagesToReturn, @@ -56,7 +70,7 @@ func NewMockExchangeCollection( for i := 0; i < c.messageCount; i++ { // We can plug in whatever data we want here (can be an io.Reader to a test data file if needed) - c.Data = append(c.Data, GetMockMessageBytes("From: NewMockExchangeCollection")) + c.Data = append(c.Data, MessageBytes("From: NewMockCollection")) c.Names = append(c.Names, uuid.NewString()) c.ModTimes = append(c.ModTimes, baseTime.Add(1*time.Hour)) c.DeletedItems = append(c.DeletedItems, false) @@ -65,10 +79,10 @@ func NewMockExchangeCollection( return c } -// NewMockExchangeDataCollection creates an data collection that will return the specified number of +// NewContactCollection creates an data collection that will return the specified number of // mock messages when iterated. Exchange type mail -func NewMockContactCollection(pathRepresentation path.Path, numMessagesToReturn int) *MockExchangeDataCollection { - c := &MockExchangeDataCollection{ +func NewContactCollection(pathRepresentation path.Path, numMessagesToReturn int) *DataCollection { + c := &DataCollection{ fullPath: pathRepresentation, messageCount: numMessagesToReturn, Data: [][]byte{}, @@ -94,30 +108,16 @@ func NewMockContactCollection(pathRepresentation path.Path, numMessagesToReturn for i := 0; i < c.messageCount; i++ { // We can plug in whatever data we want here (can be an io.Reader to a test data file if needed) - c.Data = append(c.Data, GetMockContactBytes(middleNames[rand.Intn(len(middleNames))])) + c.Data = append(c.Data, ContactBytes(middleNames[rand.Intn(len(middleNames))])) c.Names = append(c.Names, uuid.NewString()) } return c } -func (medc MockExchangeDataCollection) FullPath() path.Path { return medc.fullPath } - -func (medc MockExchangeDataCollection) LocationPath() *path.Builder { - if medc.LocPath == nil { - return nil - } - - return path.Builder{}.Append(medc.LocPath.Folders()...) -} - -func (medc MockExchangeDataCollection) PreviousPath() path.Path { return medc.PrevPath } -func (medc MockExchangeDataCollection) State() data.CollectionState { return medc.ColState } -func (medc MockExchangeDataCollection) DoNotMergeItems() bool { return medc.DoNotMerge } - // Items returns a channel that has the next items in the collection. The // channel is closed when there are no more items available. -func (medc *MockExchangeDataCollection) Items( +func (medc *DataCollection) Items( ctx context.Context, _ *fault.Bus, // unused ) <-chan data.Stream { @@ -127,7 +127,7 @@ func (medc *MockExchangeDataCollection) Items( defer close(res) for i := 0; i < medc.messageCount; i++ { - res <- &MockExchangeData{ + res <- &Data{ ID: medc.Names[i], Reader: io.NopCloser(bytes.NewReader(medc.Data[i])), size: int64(len(medc.Data[i])), @@ -140,8 +140,8 @@ func (medc *MockExchangeDataCollection) Items( return res } -// ExchangeData represents a single item retrieved from exchange -type MockExchangeData struct { +// Data represents a single item retrieved from exchange +type Data struct { ID string Reader io.ReadCloser ReadErr error @@ -150,15 +150,12 @@ type MockExchangeData struct { deleted bool } -func (med *MockExchangeData) UUID() string { - return med.ID -} +func (med *Data) UUID() string { return med.ID } +func (med *Data) Deleted() bool { return med.deleted } +func (med *Data) Size() int64 { return med.size } +func (med *Data) ModTime() time.Time { return med.modifiedTime } -func (med MockExchangeData) Deleted() bool { - return med.deleted -} - -func (med *MockExchangeData) ToReader() io.ReadCloser { +func (med *Data) ToReader() io.ReadCloser { if med.ReadErr != nil { return io.NopCloser(errReader{med.ReadErr}) } @@ -166,7 +163,7 @@ func (med *MockExchangeData) ToReader() io.ReadCloser { return med.Reader } -func (med *MockExchangeData) Info() details.ItemInfo { +func (med *Data) Info() details.ItemInfo { return details.ItemInfo{ Exchange: &details.ExchangeInfo{ Sender: "foo@bar.com", @@ -176,14 +173,6 @@ func (med *MockExchangeData) Info() details.ItemInfo { } } -func (med *MockExchangeData) Size() int64 { - return med.size -} - -func (med *MockExchangeData) ModTime() time.Time { - return med.modifiedTime -} - type errReader struct { readErr error } diff --git a/src/internal/connector/mockconnector/mock_data_contact.go b/src/internal/connector/exchange/mock/contact.go similarity index 89% rename from src/internal/connector/mockconnector/mock_data_contact.go rename to src/internal/connector/exchange/mock/contact.go index c939d1fcb..b1161031b 100644 --- a/src/internal/connector/mockconnector/mock_data_contact.go +++ b/src/internal/connector/exchange/mock/contact.go @@ -1,4 +1,4 @@ -package mockconnector +package mock import "fmt" @@ -43,12 +43,12 @@ const ( defaultContactSurname = "Quail" ) -// GetMockContactBytes returns bytes for Contactable item. +// ContactBytes returns bytes for Contactable item. // When hydrated: contact.GetGivenName() shows differences -func GetMockContactBytes(middleName string) []byte { +func ContactBytes(middleName string) []byte { phone := generatePhoneNumber() - return GetMockContactBytesWith( + return ContactBytesWith( defaultContactDisplayName, defaultContactFileAsName, defaultContactGivenName, @@ -58,7 +58,7 @@ func GetMockContactBytes(middleName string) []byte { ) } -func GetMockContactBytesWith( +func ContactBytesWith( displayName, fileAsName, givenName, middleName, surname, phone string, diff --git a/src/internal/connector/mockconnector/mock_data_event.go b/src/internal/connector/exchange/mock/event.go similarity index 97% rename from src/internal/connector/mockconnector/mock_data_event.go rename to src/internal/connector/exchange/mock/event.go index e6ab44954..560358e4f 100644 --- a/src/internal/connector/mockconnector/mock_data_event.go +++ b/src/internal/connector/exchange/mock/event.go @@ -1,4 +1,4 @@ -package mockconnector +package mock import ( "fmt" @@ -213,37 +213,37 @@ func generatePhoneNumber() string { return phoneNo } -// GetMockEventBytes returns test byte array representative of full Eventable item. -func GetDefaultMockEventBytes(subject string) []byte { - return GetMockEventWithSubjectBytes(" " + subject + " Review + Lunch") +// EventBytes returns test byte array representative of full Eventable item. +func EventBytes(subject string) []byte { + return EventWithSubjectBytes(" " + subject + " Review + Lunch") } -func GetMockEventWithSubjectBytes(subject string) []byte { +func EventWithSubjectBytes(subject string) []byte { tomorrow := time.Now().UTC().AddDate(0, 0, 1) at := time.Date(tomorrow.Year(), tomorrow.Month(), tomorrow.Day(), tomorrow.Hour(), 0, 0, 0, time.UTC) atTime := common.FormatTime(at) endTime := common.FormatTime(at.Add(30 * time.Minute)) - return GetMockEventWith( + return EventWith( defaultEventOrganizer, subject, defaultEventBody, defaultEventBodyPreview, atTime, endTime, NoRecurrence, NoAttendees, false, ) } -func GetMockEventWithAttachment(subject string) []byte { +func EventWithAttachment(subject string) []byte { tomorrow := time.Now().UTC().AddDate(0, 0, 1) at := time.Date(tomorrow.Year(), tomorrow.Month(), tomorrow.Day(), tomorrow.Hour(), 0, 0, 0, time.UTC) atTime := common.FormatTime(at) - return GetMockEventWith( + return EventWith( defaultEventOrganizer, subject, defaultEventBody, defaultEventBodyPreview, atTime, atTime, NoRecurrence, NoAttendees, true, ) } -func GetMockEventWithRecurrenceBytes(subject, recurrenceTimeZone string) []byte { +func EventWithRecurrenceBytes(subject, recurrenceTimeZone string) []byte { tomorrow := time.Now().UTC().AddDate(0, 0, 1) at := time.Date(tomorrow.Year(), tomorrow.Month(), tomorrow.Day(), tomorrow.Hour(), 0, 0, 0, time.UTC) atTime := common.FormatTime(at) @@ -255,31 +255,31 @@ func GetMockEventWithRecurrenceBytes(subject, recurrenceTimeZone string) []byte recurrenceTimeZone, )) - return GetMockEventWith( + return EventWith( defaultEventOrganizer, subject, defaultEventBody, defaultEventBodyPreview, atTime, atTime, recurrence, attendeesTmpl, true, ) } -func GetMockEventWithAttendeesBytes(subject string) []byte { +func EventWithAttendeesBytes(subject string) []byte { tomorrow := time.Now().UTC().AddDate(0, 0, 1) at := time.Date(tomorrow.Year(), tomorrow.Month(), tomorrow.Day(), tomorrow.Hour(), 0, 0, 0, time.UTC) atTime := common.FormatTime(at) - return GetMockEventWith( + return EventWith( defaultEventOrganizer, subject, defaultEventBody, defaultEventBodyPreview, atTime, atTime, NoRecurrence, attendeesTmpl, true, ) } -// GetMockEventWith returns bytes for an Eventable item. +// EventWith returns bytes for an Eventable item. // start and end times should be in the format 2006-01-02T15:04:05.0000000Z. // The timezone (Z) will be automatically stripped. A non-utc timezone may // produce unexpected results. // Body must contain a well-formatted string, consumable in a json payload. IE: no unescaped newlines. -func GetMockEventWith( +func EventWith( organizer, subject, body, bodyPreview, startDateTime, endDateTime, recurrence, attendees string, hasAttachments bool, diff --git a/src/internal/connector/mockconnector/mock_data_message.go b/src/internal/connector/exchange/mock/mail.go similarity index 97% rename from src/internal/connector/mockconnector/mock_data_message.go rename to src/internal/connector/exchange/mock/mail.go index f67fff4b9..32b2bc04f 100644 --- a/src/internal/connector/mockconnector/mock_data_message.go +++ b/src/internal/connector/exchange/mock/mail.go @@ -1,4 +1,4 @@ -package mockconnector +package mock import ( "encoding/base64" @@ -103,19 +103,19 @@ const ( }` ) -// GetMockMessageBytes returns bytes for a Messageable item. +// MessageBytes returns bytes for a Messageable item. // Contents verified as working with sample data from kiota-serialization-json-go v0.5.5 -func GetMockMessageBytes(subject string) []byte { - return GetMockMessageWithBodyBytes( +func MessageBytes(subject string) []byte { + return MessageWithBodyBytes( "TPS Report "+subject+" "+common.FormatNow(common.SimpleDateTime), defaultMessageBody, defaultMessagePreview) } -// GetMockMessageBytes returns bytes for a Messageable item. +// MessageWithBodyBytes returns bytes for a Messageable item. // Contents verified as working with sample data from kiota-serialization-json-go v0.5.5 // Body must contain a well-formatted string, consumable in a json payload. IE: no unescaped newlines. -func GetMockMessageWithBodyBytes(subject, body, preview string) []byte { - return GetMockMessageWith( +func MessageWithBodyBytes(subject, body, preview string) []byte { + return MessageWith( defaultMessageTo, defaultMessageFrom, defaultMessageSender, @@ -129,11 +129,11 @@ func GetMockMessageWithBodyBytes(subject, body, preview string) []byte { ) } -// GetMockMessageWith returns bytes for a Messageable item. +// MessageWith returns bytes for a Messageable item. // Contents verified as working with sample data from kiota-serialization-json-go v0.5.5 // created, modified, sent, and received should be in the format 2006-01-02T15:04:05Z // Body must contain a well-formatted string, consumable in a json payload. IE: no unescaped newlines. -func GetMockMessageWith( +func MessageWith( to, from, sender, // user PNs subject, body, preview, // arbitrary data created, modified, sent, received string, // legacy datetimes @@ -162,10 +162,10 @@ func GetMockMessageWith( return []byte(message) } -// GetMockMessageWithDirectAttachment returns a message an attachment that contains n MB of data. +// MessageWithDirectAttachment returns a message an attachment that contains n MB of data. // Max limit on N is 35 (imposed by exchange) . // Serialized with: kiota-serialization-json-go v0.7.1 -func GetMockMessageWithSizedAttachment(subject string, n int) []byte { +func MessageWithSizedAttachment(subject string, n int) []byte { // I know we said 35, but after base64encoding, 24mb of base content // bloats up to 34mb (35 balloons to 49). So we have to restrict n // appropriately. @@ -197,9 +197,9 @@ func GetMockMessageWithSizedAttachment(subject string, n int) []byte { return []byte(fmt.Sprintf(messageFmt, attachmentSize, base64.StdEncoding.EncodeToString([]byte(attachmentBytes)))) } -// GetMockMessageWithDirectAttachment returns a message with inline attachment +// MessageWithDirectAttachment returns a message with inline attachment // Serialized with: kiota-serialization-json-go v0.7.1 -func GetMockMessageWithDirectAttachment(subject string) []byte { +func MessageWithDirectAttachment(subject string) []byte { //nolint:lll message := "{\"id\":\"AAMkAGZmNjNlYjI3LWJlZWYtNGI4Mi04YjMyLTIxYThkNGQ4NmY1MwBGAAAAAADCNgjhM9QmQYWNcI7hCpPrBwDSEBNbUIB9RL6ePDeF3FIYAAAAAAEMAADSEBNbUIB9RL6ePDeF3FIYAAB4moqeAAA=\"," + "\"@odata.type\":\"#microsoft.graph.message\",\"@odata.etag\":\"W/\\\"CQAAABYAAADSEBNbUIB9RL6ePDeF3FIYAAB3maFQ\\\"\",\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#users('a4a472f8-ccb0-43ec-bf52-3697a91b926c')/messages/$entity\",\"categories\":[]," + @@ -266,16 +266,16 @@ func GetMockMessageWithDirectAttachment(subject string) []byte { return []byte(message) } -// GetMockMessageWithDirectAttachment returns a message with a large attachment. This is derived from the message -// used in GetMockMessageWithDirectAttachment +// MessageWithDirectAttachment returns a message with a large attachment. This is derived from the message +// used in MessageWithDirectAttachment // Serialized with: kiota-serialization-json-go v0.7.1 -func GetMockMessageWithLargeAttachment(subject string) []byte { - return GetMockMessageWithSizedAttachment(subject, 3) +func MessageWithLargeAttachment(subject string) []byte { + return MessageWithSizedAttachment(subject, 3) } // GetMessageWithOneDriveAttachment returns a message with an OneDrive attachment represented in bytes // Serialized with: kiota-serialization-json-go v0.7.1 -func GetMessageWithOneDriveAttachment(subject string) []byte { +func MessageWithOneDriveAttachment(subject string) []byte { //nolint:lll message := "{\"id\":\"AAMkAGZmNjNlYjI3LWJlZWYtNGI4Mi04YjMyLTIxYThkNGQ4NmY1MwBGAAAAAADCNgjhM9QmQYWNcI7hCpPrBwDSEBNbUIB9RL6ePDeF3FIYAAAAAAEMAADSEBNbUIB9RL6ePDeF3FIYAAB4moqfAAA=\"," + "\"@odata.type\":\"#microsoft.graph.message\",\"@odata.etag\":\"W/\\\"CQAAABYAAADSEBNbUIB9RL6ePDeF3FIYAAB3maFw\\\"\",\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#users('a4a472f8-ccb0-43ec-bf52-3697a91b926c')/messages/$entity\",\"categories\":[]," + @@ -293,9 +293,9 @@ func GetMessageWithOneDriveAttachment(subject string) []byte { return []byte(message) } -// GetMockMessageWithTwoAttachments returns byte representation of message with two attachments +// MessageWithTwoAttachments returns byte representation of message with two attachments // Serialized with: kiota-serialization-json-go v0.7.1 -func GetMockMessageWithTwoAttachments(subject string) []byte { +func MessageWithTwoAttachments(subject string) []byte { //nolint:lll message := "{\"id\":\"AAMkAGZmNjNlYjI3LWJlZWYtNGI4Mi04YjMyLTIxYThkNGQ4NmY1MwBGAAAAAADCNgjhM9QmQYWNcI7hCpPrBwDSEBNbUIB9RL6ePDeF3FIYAAAAAAEMAADSEBNbUIB9RL6ePDeF3FIYAAB6LpD0AAA=\",\"@odata.type\":\"#microsoft.graph.message\",\"@odata.etag\":\"W/\\\"CQAAABYAAADSEBNbUIB9RL6ePDeF3FIYAAB5JBpO\\\"\",\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#users('a4a472f8-ccb0-43ec-bf52-3697a91b926c')/messages/$entity\",\"categories\":[],\"changeKey\":\"CQAAABYAAADSEBNbUIB9RL6ePDeF3FIYAAB5JBpO\"," + "\"createdDateTime\":\"2022-09-30T20:31:22Z\",\"lastModifiedDateTime\":\"2022-09-30T20:31:25Z\",\"attachments\":[{\"id\":\"AAMkAGZmNjNlYjI3LWJlZWYtNGI4Mi04YjMyLTIxYThkNGQ4NmY1MwBGAAAAAADCNgjhM9QmQYWNcI7hCpPrBwDSEBNbUIB9RL6ePDeF3FIYAAAAAAEMAADSEBNbUIB9RL6ePDeF3FIYAAB6LpD0AAABEgAQAMIBac0_D4pPgtgr9mhVWaM=\",\"@odata.type\":\"#microsoft.graph.fileAttachment\",\"@odata.mediaContentType\":\"text/plain\",\"contentType\":\"text/plain\",\"isInline\":false,\"lastModifiedDateTime\":\"2022-09-30T20:31:22Z\"," + @@ -313,9 +313,9 @@ func GetMockMessageWithTwoAttachments(subject string) []byte { return []byte(message) } -// GetMockEventMessageResponse returns byte representation of EventMessageResponse +// EventMessageResponse returns byte representation of EventMessageResponse // Special Mock to ensure that EventMessageResponse emails are transformed properly -func GetMockEventMessageResponse(subject string) []byte { +func EventMessageResponse(subject string) []byte { //nolint:lll message := "{\"id\":\"AAMkAGQ1NzViZTdhLTEwMTMtNGJjNi05YWI2LTg4NWRlZDA2Y2UxOABGAAAAAAAPvVwUramXT7jlSGpVU8_7BwB8wYc0thTTTYl3RpEYIUq_AAAAAAEMAAB8wYc0thTTTYl3RpEYIUq_AACL4y38AAA=\"," + "\"@odata.type\":\"#microsoft.graph.eventMessageResponse\",\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#users('dustina%408qzvrj.onmicrosoft.com')/messages/$entity\"," + @@ -329,9 +329,9 @@ func GetMockEventMessageResponse(subject string) []byte { return []byte(message) } -// GetMockEventMessageRequest returns byte representation of EventMessageRequest +// EventMessageRequest returns byte representation of EventMessageRequest // Special Mock to ensure that EventMessageRequests are transformed properly -func GetMockEventMessageRequest(subject string) []byte { +func EventMessageRequest(subject string) []byte { //nolint:lll message := "{\"id\":\"AAMkAGQ1NzViZTdhLTEwMTMtNGJjNi05YWI2LTg4NWRlZDA2Y2UxOABGAAAAAAAPvVwUramXT7jlSGpVU8_7BwB8wYc0thTTTYl3RpEYIUq_AAAAAAEJAAB8wYc0thTTTYl3RpEYIUq_AACL5VwSAAA=\"," + "\"@odata.type\":\"#microsoft.graph.eventMessageRequest\",\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#users('dustina%408qzvrj.onmicrosoft.com')/messages/$entity\"," + @@ -344,7 +344,7 @@ func GetMockEventMessageRequest(subject string) []byte { return []byte(message) } -func GetMockMessageWithItemAttachmentEvent(subject string) []byte { +func MessageWithItemAttachmentEvent(subject string) []byte { //nolint:lll message := "{\"id\":\"AAMkAGQ1NzViZTdhLTEwMTMtNGJjNi05YWI2LTg4NWRlZDA2Y2UxOABGAAAAAAAPvVwUramXT7jlSGpVU8_7BwB8wYc0thTTTYl3RpEYIUq_AAAAAAEMAAB8wYc0thTTTYl3RpEYIUq_AADFfThMAAA=\",\"@odata.type\":\"#microsoft.graph.message\"," + "\"@odata.etag\":\"W/\\\"CQAAABYAAAB8wYc0thTTTYl3RpEYIUq+AADFK3BH\\\"\",\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#users('dustina%408qzvrj.onmicrosoft.com')/messages/$entity\",\"categories\":[]," + @@ -367,7 +367,7 @@ func GetMockMessageWithItemAttachmentEvent(subject string) []byte { return []byte(message) } -func GetMockMessageWithItemAttachmentMail(subject string) []byte { +func MessageWithItemAttachmentMail(subject string) []byte { //nolint:lll // Order of fields: // 1. subject @@ -504,7 +504,7 @@ func GetMockMessageWithItemAttachmentMail(subject string) []byte { return []byte(message) } -func GetMockMessageWithNestedItemAttachmentEvent(subject string) []byte { +func MessageWithNestedItemAttachmentEvent(subject string) []byte { //nolint:lll // Order of fields: // 1. subject @@ -690,8 +690,8 @@ func GetMockMessageWithNestedItemAttachmentEvent(subject string) []byte { return []byte(message) } -func GetMockMessageWithNestedItemAttachmentMail(t *testing.T, nested []byte, subject string) []byte { - base := GetMockMessageBytes(subject) +func MessageWithNestedItemAttachmentMail(t *testing.T, nested []byte, subject string) []byte { + base := MessageBytes(subject) message, err := hydrateMessage(base) require.NoError(t, err, clues.ToCore(err)) @@ -710,8 +710,8 @@ func GetMockMessageWithNestedItemAttachmentMail(t *testing.T, nested []byte, sub return serialize(t, message) } -func GetMockMessageWithNestedItemAttachmentContact(t *testing.T, nested []byte, subject string) []byte { - base := GetMockMessageBytes(subject) +func MessageWithNestedItemAttachmentContact(t *testing.T, nested []byte, subject string) []byte { + base := MessageBytes(subject) message, err := hydrateMessage(base) require.NoError(t, err, clues.ToCore(err)) diff --git a/src/internal/connector/mockconnector/mock_data_collection_test.go b/src/internal/connector/exchange/mock/mock_test.go similarity index 61% rename from src/internal/connector/mockconnector/mock_data_collection_test.go rename to src/internal/connector/exchange/mock/mock_test.go index 7b4919ce8..aab25e055 100644 --- a/src/internal/connector/mockconnector/mock_data_collection_test.go +++ b/src/internal/connector/exchange/mock/mock_test.go @@ -1,4 +1,4 @@ -package mockconnector_test +package mock import ( "bytes" @@ -6,32 +6,30 @@ import ( "testing" "github.com/alcionai/clues" - kioser "github.com/microsoft/kiota-serialization-json-go" "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/corso/src/internal/connector/mockconnector" "github.com/alcionai/corso/src/internal/connector/support" "github.com/alcionai/corso/src/internal/data" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/fault" ) -type MockExchangeCollectionSuite struct { +type MockSuite struct { tester.Suite } -func TestMockExchangeCollectionSuite(t *testing.T) { - suite.Run(t, &MockExchangeCollectionSuite{Suite: tester.NewUnitSuite(t)}) +func TestMockSuite(t *testing.T) { + suite.Run(t, &MockSuite{Suite: tester.NewUnitSuite(t)}) } -func (suite *MockExchangeCollectionSuite) TestMockExchangeCollection() { +func (suite *MockSuite) TestMockExchangeCollection() { ctx, flush := tester.NewContext() defer flush() - mdc := mockconnector.NewMockExchangeCollection(nil, nil, 2) + mdc := NewCollection(nil, nil, 2) messagesRead := 0 for item := range mdc.Items(ctx, fault.New(true)) { @@ -43,12 +41,12 @@ func (suite *MockExchangeCollectionSuite) TestMockExchangeCollection() { assert.Equal(suite.T(), 2, messagesRead) } -func (suite *MockExchangeCollectionSuite) TestMockExchangeCollectionItemSize() { +func (suite *MockSuite) TestMockExchangeCollectionItemSize() { ctx, flush := tester.NewContext() defer flush() t := suite.T() - mdc := mockconnector.NewMockExchangeCollection(nil, nil, 2) + mdc := NewCollection(nil, nil, 2) mdc.Data[1] = []byte("This is some buffer of data so that the size is different than the default") for item := range mdc.Items(ctx, fault.New(true)) { @@ -63,12 +61,12 @@ func (suite *MockExchangeCollectionSuite) TestMockExchangeCollectionItemSize() { // NewExchangeCollectionMail_Hydration tests that mock exchange mail data collection can be used for restoration // functions by verifying no failures on (de)serializing steps using kiota serialization library -func (suite *MockExchangeCollectionSuite) TestMockExchangeCollection_NewExchangeCollectionMail_Hydration() { +func (suite *MockSuite) TestMockExchangeCollection_NewExchangeCollectionMail_Hydration() { ctx, flush := tester.NewContext() defer flush() t := suite.T() - mdc := mockconnector.NewMockExchangeCollection(nil, nil, 3) + mdc := NewCollection(nil, nil, 3) buf := &bytes.Buffer{} for stream := range mdc.Items(ctx, fault.New(true)) { @@ -96,12 +94,12 @@ func (suite *MockExchangeDataSuite) TestMockExchangeData() { table := []struct { name string - reader *mockconnector.MockExchangeData + reader *Data check require.ErrorAssertionFunc }{ { name: "NoError", - reader: &mockconnector.MockExchangeData{ + reader: &Data{ ID: id, Reader: io.NopCloser(bytes.NewReader(itemData)), }, @@ -109,7 +107,7 @@ func (suite *MockExchangeDataSuite) TestMockExchangeData() { }, { name: "Error", - reader: &mockconnector.MockExchangeData{ + reader: &Data{ ID: id, ReadErr: assert.AnError, }, @@ -143,7 +141,7 @@ func (suite *MockExchangeDataSuite) TestMockByteHydration() { { name: "Message Bytes", transformation: func(t *testing.T) error { - bytes := mockconnector.GetMockMessageBytes(subject) + bytes := MessageBytes(subject) _, err := support.CreateMessageFromBytes(bytes) return err }, @@ -151,7 +149,7 @@ func (suite *MockExchangeDataSuite) TestMockByteHydration() { { name: "Event Message Response: Regression", transformation: func(t *testing.T) error { - bytes := mockconnector.GetMockEventMessageResponse(subject) + bytes := EventMessageResponse(subject) _, err := support.CreateMessageFromBytes(bytes) return err }, @@ -159,7 +157,7 @@ func (suite *MockExchangeDataSuite) TestMockByteHydration() { { name: "Event Message Request: Regression", transformation: func(t *testing.T) error { - bytes := mockconnector.GetMockEventMessageRequest(subject) + bytes := EventMessageRequest(subject) _, err := support.CreateMessageFromBytes(bytes) return err }, @@ -167,7 +165,7 @@ func (suite *MockExchangeDataSuite) TestMockByteHydration() { { name: "Contact Bytes", transformation: func(t *testing.T) error { - bytes := mockconnector.GetMockContactBytes(subject) + bytes := ContactBytes(subject) _, err := support.CreateContactFromBytes(bytes) return err }, @@ -175,54 +173,11 @@ func (suite *MockExchangeDataSuite) TestMockByteHydration() { { name: "Event No Attendees Bytes", transformation: func(t *testing.T) error { - bytes := mockconnector.GetDefaultMockEventBytes(subject) + bytes := EventBytes(subject) _, err := support.CreateEventFromBytes(bytes) return err }, }, - { - name: "Event w/ Attendees Bytes", - transformation: func(t *testing.T) error { - bytes := mockconnector.GetMockEventWithAttendeesBytes(subject) - _, err := support.CreateEventFromBytes(bytes) - return err - }, - }, - { - name: "SharePoint: List Empty", - transformation: func(t *testing.T) error { - emptyMap := make(map[string]string) - temp := mockconnector.GetMockList(subject, "Artist", emptyMap) - writer := kioser.NewJsonSerializationWriter() - err := writer.WriteObjectValue("", temp) - require.NoError(t, err, clues.ToCore(err)) - - bytes, err := writer.GetSerializedContent() - require.NoError(t, err, clues.ToCore(err)) - - _, err = support.CreateListFromBytes(bytes) - - return err - }, - }, - { - name: "SharePoint: List 6 Items", - transformation: func(t *testing.T) error { - bytes, err := mockconnector.GetMockListBytes(subject) - require.NoError(t, err, clues.ToCore(err)) - _, err = support.CreateListFromBytes(bytes) - return err - }, - }, - { - name: "SharePoint: Page", - transformation: func(t *testing.T) error { - bytes := mockconnector.GetMockPage(subject) - _, err := support.CreatePageFromBytes(bytes) - - return err - }, - }, } for _, test := range tests { diff --git a/src/internal/connector/exchange/restore_test.go b/src/internal/connector/exchange/restore_test.go index ac28bf3f2..1e298e754 100644 --- a/src/internal/connector/exchange/restore_test.go +++ b/src/internal/connector/exchange/restore_test.go @@ -13,8 +13,8 @@ import ( "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/exchange/api" + exchMock "github.com/alcionai/corso/src/internal/connector/exchange/mock" "github.com/alcionai/corso/src/internal/connector/graph" - "github.com/alcionai/corso/src/internal/connector/mockconnector" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/account" "github.com/alcionai/corso/src/pkg/control" @@ -84,7 +84,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreContact() { info, err := RestoreExchangeContact( ctx, - mockconnector.GetMockContactBytes("Corso TestContact"), + exchMock.ContactBytes("Corso TestContact"), suite.gs, control.Copy, folderID, @@ -122,11 +122,11 @@ func (suite *ExchangeRestoreSuite) TestRestoreEvent() { }{ { name: "Test Event With Attendees", - bytes: mockconnector.GetMockEventWithAttendeesBytes(subject), + bytes: exchMock.EventWithAttendeesBytes(subject), }, { name: "Test recurrenceTimeZone: Empty", - bytes: mockconnector.GetMockEventWithRecurrenceBytes(subject, `""`), + bytes: exchMock.EventWithRecurrenceBytes(subject, `""`), }, } @@ -181,7 +181,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { }{ { name: "Test Mail", - bytes: mockconnector.GetMockMessageBytes("Restore Exchange Object"), + bytes: exchMock.MessageBytes("Restore Exchange Object"), category: path.EmailCategory, destination: func(t *testing.T, ctx context.Context) string { folderName := "TestRestoreMailObject: " + common.FormatSimpleDateTime(now) @@ -193,7 +193,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { }, { name: "Test Mail: One Direct Attachment", - bytes: mockconnector.GetMockMessageWithDirectAttachment("Restore 1 Attachment"), + bytes: exchMock.MessageWithDirectAttachment("Restore 1 Attachment"), category: path.EmailCategory, destination: func(t *testing.T, ctx context.Context) string { folderName := "TestRestoreMailwithAttachment: " + common.FormatSimpleDateTime(now) @@ -205,7 +205,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { }, { name: "Test Mail: Item Attachment_Event", - bytes: mockconnector.GetMockMessageWithItemAttachmentEvent("Event Item Attachment"), + bytes: exchMock.MessageWithItemAttachmentEvent("Event Item Attachment"), category: path.EmailCategory, destination: func(t *testing.T, ctx context.Context) string { folderName := "TestRestoreEventItemAttachment: " + common.FormatSimpleDateTime(now) @@ -217,7 +217,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { }, { name: "Test Mail: Item Attachment_Mail", - bytes: mockconnector.GetMockMessageWithItemAttachmentMail("Mail Item Attachment"), + bytes: exchMock.MessageWithItemAttachmentMail("Mail Item Attachment"), category: path.EmailCategory, destination: func(t *testing.T, ctx context.Context) string { folderName := "TestRestoreMailItemAttachment: " + common.FormatSimpleDateTime(now) @@ -229,8 +229,8 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { }, { name: "Test Mail: Hydrated Item Attachment Mail", - bytes: mockconnector.GetMockMessageWithNestedItemAttachmentMail(t, - mockconnector.GetMockMessageBytes("Basic Item Attachment"), + bytes: exchMock.MessageWithNestedItemAttachmentMail(t, + exchMock.MessageBytes("Basic Item Attachment"), "Mail Item Attachment", ), category: path.EmailCategory, @@ -244,8 +244,8 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { }, { name: "Test Mail: Hydrated Item Attachment Mail One Attach", - bytes: mockconnector.GetMockMessageWithNestedItemAttachmentMail(t, - mockconnector.GetMockMessageWithDirectAttachment("Item Attachment Included"), + bytes: exchMock.MessageWithNestedItemAttachmentMail(t, + exchMock.MessageWithDirectAttachment("Item Attachment Included"), "Mail Item Attachment", ), category: path.EmailCategory, @@ -259,8 +259,8 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { }, { name: "Test Mail: Item Attachment_Contact", - bytes: mockconnector.GetMockMessageWithNestedItemAttachmentContact(t, - mockconnector.GetMockContactBytes("Victor"), + bytes: exchMock.MessageWithNestedItemAttachmentContact(t, + exchMock.ContactBytes("Victor"), "Contact Item Attachment", ), category: path.EmailCategory, @@ -274,7 +274,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { }, { // Restore will upload the Message without uploading the attachment name: "Test Mail: Item Attachment_NestedEvent", - bytes: mockconnector.GetMockMessageWithNestedItemAttachmentEvent("Nested Item Attachment"), + bytes: exchMock.MessageWithNestedItemAttachmentEvent("Nested Item Attachment"), category: path.EmailCategory, destination: func(t *testing.T, ctx context.Context) string { folderName := "TestRestoreNestedEventItemAttachment: " + common.FormatSimpleDateTime(now) @@ -286,7 +286,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { }, { name: "Test Mail: One Large Attachment", - bytes: mockconnector.GetMockMessageWithLargeAttachment("Restore Large Attachment"), + bytes: exchMock.MessageWithLargeAttachment("Restore Large Attachment"), category: path.EmailCategory, destination: func(t *testing.T, ctx context.Context) string { folderName := "TestRestoreMailwithLargeAttachment: " + common.FormatSimpleDateTime(now) @@ -298,7 +298,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { }, { name: "Test Mail: Two Attachments", - bytes: mockconnector.GetMockMessageWithTwoAttachments("Restore 2 Attachments"), + bytes: exchMock.MessageWithTwoAttachments("Restore 2 Attachments"), category: path.EmailCategory, destination: func(t *testing.T, ctx context.Context) string { folderName := "TestRestoreMailwithAttachments: " + common.FormatSimpleDateTime(now) @@ -310,7 +310,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { }, { name: "Test Mail: Reference(OneDrive) Attachment", - bytes: mockconnector.GetMessageWithOneDriveAttachment("Restore Reference(OneDrive) Attachment"), + bytes: exchMock.MessageWithOneDriveAttachment("Restore Reference(OneDrive) Attachment"), category: path.EmailCategory, destination: func(t *testing.T, ctx context.Context) string { folderName := "TestRestoreMailwithReferenceAttachment: " + common.FormatSimpleDateTime(now) @@ -323,7 +323,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { // TODO: #884 - reinstate when able to specify root folder by name { name: "Test Contact", - bytes: mockconnector.GetMockContactBytes("Test_Omega"), + bytes: exchMock.ContactBytes("Test_Omega"), category: path.ContactsCategory, destination: func(t *testing.T, ctx context.Context) string { folderName := "TestRestoreContactObject: " + common.FormatSimpleDateTime(now) @@ -335,7 +335,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { }, { name: "Test Events", - bytes: mockconnector.GetDefaultMockEventBytes("Restored Event Object"), + bytes: exchMock.EventBytes("Restored Event Object"), category: path.EventsCategory, destination: func(t *testing.T, ctx context.Context) string { calendarName := "TestRestoreEventObject: " + common.FormatSimpleDateTime(now) @@ -347,7 +347,7 @@ func (suite *ExchangeRestoreSuite) TestRestoreExchangeObject() { }, { name: "Test Event with Attachment", - bytes: mockconnector.GetMockEventWithAttachment("Restored Event Attachment"), + bytes: exchMock.EventWithAttachment("Restored Event Attachment"), category: path.EventsCategory, destination: func(t *testing.T, ctx context.Context) string { calendarName := "TestRestoreEventObject_" + common.FormatSimpleDateTime(now) diff --git a/src/internal/connector/graph_connector_helper_test.go b/src/internal/connector/graph_connector_helper_test.go index 54e7c7b5a..2f3ecbef5 100644 --- a/src/internal/connector/graph_connector_helper_test.go +++ b/src/internal/connector/graph_connector_helper_test.go @@ -18,7 +18,7 @@ import ( "golang.org/x/exp/slices" "github.com/alcionai/corso/src/internal/common/ptr" - "github.com/alcionai/corso/src/internal/connector/mockconnector" + exchMock "github.com/alcionai/corso/src/internal/connector/exchange/mock" "github.com/alcionai/corso/src/internal/connector/onedrive" "github.com/alcionai/corso/src/internal/connector/support" "github.com/alcionai/corso/src/internal/data" @@ -1208,7 +1208,7 @@ func collectionsForInfo( info.pathElements, false) - mc := mockconnector.NewMockExchangeCollection(pth, pth, len(info.items)) + mc := exchMock.NewCollection(pth, pth, len(info.items)) baseDestPath := backupOutputPathFromRestore(t, dest, pth) baseExpected := expectedData[baseDestPath.String()] @@ -1237,7 +1237,7 @@ func collectionsForInfo( c := mockRestoreCollection{Collection: mc, auxItems: map[string]data.Stream{}} for _, aux := range info.auxItems { - c.auxItems[aux.name] = &mockconnector.MockExchangeData{ + c.auxItems[aux.name] = &exchMock.Data{ ID: aux.name, Reader: io.NopCloser(bytes.NewReader(aux.data)), } diff --git a/src/internal/connector/graph_connector_test.go b/src/internal/connector/graph_connector_test.go index 746cf1fbd..5a758fc91 100644 --- a/src/internal/connector/graph_connector_test.go +++ b/src/internal/connector/graph_connector_test.go @@ -14,8 +14,9 @@ import ( "golang.org/x/exp/maps" "github.com/alcionai/corso/src/internal/common" + exchMock "github.com/alcionai/corso/src/internal/connector/exchange/mock" "github.com/alcionai/corso/src/internal/connector/graph" - "github.com/alcionai/corso/src/internal/connector/mockconnector" + "github.com/alcionai/corso/src/internal/connector/mock" "github.com/alcionai/corso/src/internal/connector/support" "github.com/alcionai/corso/src/internal/data" "github.com/alcionai/corso/src/internal/tester" @@ -39,19 +40,6 @@ func TestGraphConnectorUnitSuite(t *testing.T) { suite.Run(t, &GraphConnectorUnitSuite{Suite: tester.NewUnitSuite(t)}) } -var _ getIDAndNamer = &mockNameIDGetter{} - -type mockNameIDGetter struct { - id, name string -} - -func (mnig mockNameIDGetter) GetIDAndName( - _ context.Context, - _ string, -) (string, string, error) { - return mnig.id, mnig.name, nil -} - func (suite *GraphConnectorUnitSuite) TestPopulateOwnerIDAndNamesFrom() { const ( id = "owner-id" @@ -63,9 +51,9 @@ func (suite *GraphConnectorUnitSuite) TestPopulateOwnerIDAndNamesFrom() { nti = map[string]string{name: id} lookup = &resourceClient{ enum: Users, - getter: &mockNameIDGetter{id: id, name: name}, + getter: &mock.IDNameGetter{ID: id, Name: name}, } - noLookup = &resourceClient{enum: Users, getter: &mockNameIDGetter{}} + noLookup = &resourceClient{enum: Users, getter: &mock.IDNameGetter{}} ) table := []struct { @@ -719,14 +707,14 @@ func (suite *GraphConnectorIntegrationSuite) TestRestoreAndBackup() { items: []itemInfo{ { name: "someencodeditemID", - data: mockconnector.GetMockMessageWithDirectAttachment( + data: exchMock.MessageWithDirectAttachment( subjectText + "-1", ), lookupKey: subjectText + "-1", }, { name: "someencodeditemID2", - data: mockconnector.GetMockMessageWithTwoAttachments( + data: exchMock.MessageWithTwoAttachments( subjectText + "-2", ), lookupKey: subjectText + "-2", @@ -746,7 +734,7 @@ func (suite *GraphConnectorIntegrationSuite) TestRestoreAndBackup() { items: []itemInfo{ { name: "someencodeditemID", - data: mockconnector.GetMockMessageWithBodyBytes( + data: exchMock.MessageWithBodyBytes( subjectText+"-1", bodyText+" 1.", bodyText+" 1.", @@ -761,7 +749,7 @@ func (suite *GraphConnectorIntegrationSuite) TestRestoreAndBackup() { items: []itemInfo{ { name: "someencodeditemID2", - data: mockconnector.GetMockMessageWithBodyBytes( + data: exchMock.MessageWithBodyBytes( subjectText+"-2", bodyText+" 2.", bodyText+" 2.", @@ -770,7 +758,7 @@ func (suite *GraphConnectorIntegrationSuite) TestRestoreAndBackup() { }, { name: "someencodeditemID3", - data: mockconnector.GetMockMessageWithBodyBytes( + data: exchMock.MessageWithBodyBytes( subjectText+"-3", bodyText+" 3.", bodyText+" 3.", @@ -785,7 +773,7 @@ func (suite *GraphConnectorIntegrationSuite) TestRestoreAndBackup() { items: []itemInfo{ { name: "someencodeditemID4", - data: mockconnector.GetMockMessageWithBodyBytes( + data: exchMock.MessageWithBodyBytes( subjectText+"-4", bodyText+" 4.", bodyText+" 4.", @@ -800,7 +788,7 @@ func (suite *GraphConnectorIntegrationSuite) TestRestoreAndBackup() { items: []itemInfo{ { name: "someencodeditemID5", - data: mockconnector.GetMockMessageWithBodyBytes( + data: exchMock.MessageWithBodyBytes( subjectText+"-5", bodyText+" 5.", bodyText+" 5.", @@ -822,17 +810,17 @@ func (suite *GraphConnectorIntegrationSuite) TestRestoreAndBackup() { items: []itemInfo{ { name: "someencodeditemID", - data: mockconnector.GetMockContactBytes("Ghimley"), + data: exchMock.ContactBytes("Ghimley"), lookupKey: "Ghimley", }, { name: "someencodeditemID2", - data: mockconnector.GetMockContactBytes("Irgot"), + data: exchMock.ContactBytes("Irgot"), lookupKey: "Irgot", }, { name: "someencodeditemID3", - data: mockconnector.GetMockContactBytes("Jannes"), + data: exchMock.ContactBytes("Jannes"), lookupKey: "Jannes", }, }, @@ -850,17 +838,17 @@ func (suite *GraphConnectorIntegrationSuite) TestRestoreAndBackup() { items: []itemInfo{ { name: "someencodeditemID", - data: mockconnector.GetMockContactBytes("Ghimley"), + data: exchMock.ContactBytes("Ghimley"), lookupKey: "Ghimley", }, { name: "someencodeditemID2", - data: mockconnector.GetMockContactBytes("Irgot"), + data: exchMock.ContactBytes("Irgot"), lookupKey: "Irgot", }, { name: "someencodeditemID3", - data: mockconnector.GetMockContactBytes("Jannes"), + data: exchMock.ContactBytes("Jannes"), lookupKey: "Jannes", }, }, @@ -871,12 +859,12 @@ func (suite *GraphConnectorIntegrationSuite) TestRestoreAndBackup() { items: []itemInfo{ { name: "someencodeditemID4", - data: mockconnector.GetMockContactBytes("Argon"), + data: exchMock.ContactBytes("Argon"), lookupKey: "Argon", }, { name: "someencodeditemID5", - data: mockconnector.GetMockContactBytes("Bernard"), + data: exchMock.ContactBytes("Bernard"), lookupKey: "Bernard", }, }, @@ -893,17 +881,17 @@ func (suite *GraphConnectorIntegrationSuite) TestRestoreAndBackup() { // items: []itemInfo{ // { // name: "someencodeditemID", - // data: mockconnector.GetMockEventWithSubjectBytes("Ghimley"), + // data: exchMock.EventWithSubjectBytes("Ghimley"), // lookupKey: "Ghimley", // }, // { // name: "someencodeditemID2", - // data: mockconnector.GetMockEventWithSubjectBytes("Irgot"), + // data: exchMock.EventWithSubjectBytes("Irgot"), // lookupKey: "Irgot", // }, // { // name: "someencodeditemID3", - // data: mockconnector.GetMockEventWithSubjectBytes("Jannes"), + // data: exchMock.EventWithSubjectBytes("Jannes"), // lookupKey: "Jannes", // }, // }, @@ -920,17 +908,17 @@ func (suite *GraphConnectorIntegrationSuite) TestRestoreAndBackup() { // items: []itemInfo{ // { // name: "someencodeditemID", - // data: mockconnector.GetMockEventWithSubjectBytes("Ghimley"), + // data: exchMock.EventWithSubjectBytes("Ghimley"), // lookupKey: "Ghimley", // }, // { // name: "someencodeditemID2", - // data: mockconnector.GetMockEventWithSubjectBytes("Irgot"), + // data: exchMock.EventWithSubjectBytes("Irgot"), // lookupKey: "Irgot", // }, // { // name: "someencodeditemID3", - // data: mockconnector.GetMockEventWithSubjectBytes("Jannes"), + // data: exchMock.EventWithSubjectBytes("Jannes"), // lookupKey: "Jannes", // }, // }, @@ -941,12 +929,12 @@ func (suite *GraphConnectorIntegrationSuite) TestRestoreAndBackup() { // items: []itemInfo{ // { // name: "someencodeditemID4", - // data: mockconnector.GetMockEventWithSubjectBytes("Argon"), + // data: exchMock.EventWithSubjectBytes("Argon"), // lookupKey: "Argon", // }, // { // name: "someencodeditemID5", - // data: mockconnector.GetMockEventWithSubjectBytes("Bernard"), + // data: exchMock.EventWithSubjectBytes("Bernard"), // lookupKey: "Bernard", // }, // }, @@ -985,7 +973,7 @@ func (suite *GraphConnectorIntegrationSuite) TestMultiFolderBackupDifferentNames items: []itemInfo{ { name: "someencodeditemID", - data: mockconnector.GetMockContactBytes("Ghimley"), + data: exchMock.ContactBytes("Ghimley"), lookupKey: "Ghimley", }, }, @@ -996,7 +984,7 @@ func (suite *GraphConnectorIntegrationSuite) TestMultiFolderBackupDifferentNames items: []itemInfo{ { name: "someencodeditemID2", - data: mockconnector.GetMockContactBytes("Irgot"), + data: exchMock.ContactBytes("Irgot"), lookupKey: "Irgot", }, }, @@ -1013,7 +1001,7 @@ func (suite *GraphConnectorIntegrationSuite) TestMultiFolderBackupDifferentNames // items: []itemInfo{ // { // name: "someencodeditemID", - // data: mockconnector.GetMockEventWithSubjectBytes("Ghimley"), + // data: exchMock.EventWithSubjectBytes("Ghimley"), // lookupKey: "Ghimley", // }, // }, @@ -1024,7 +1012,7 @@ func (suite *GraphConnectorIntegrationSuite) TestMultiFolderBackupDifferentNames // items: []itemInfo{ // { // name: "someencodeditemID2", - // data: mockconnector.GetMockEventWithSubjectBytes("Irgot"), + // data: exchMock.EventWithSubjectBytes("Irgot"), // lookupKey: "Irgot", // }, // }, @@ -1162,7 +1150,7 @@ func (suite *GraphConnectorIntegrationSuite) TestRestoreAndBackup_largeMailAttac items: []itemInfo{ { name: "35mbAttachment", - data: mockconnector.GetMockMessageWithSizedAttachment(subjectText, 35), + data: exchMock.MessageWithSizedAttachment(subjectText, 35), lookupKey: subjectText, }, }, diff --git a/src/internal/connector/mockconnector/mock_data_connector.go b/src/internal/connector/mock/connector.go similarity index 98% rename from src/internal/connector/mockconnector/mock_data_connector.go rename to src/internal/connector/mock/connector.go index 6c5850bdb..d6d68f067 100644 --- a/src/internal/connector/mockconnector/mock_data_connector.go +++ b/src/internal/connector/mock/connector.go @@ -1,4 +1,4 @@ -package mockconnector +package mock import ( "context" diff --git a/src/internal/connector/mock/id_name_getter.go b/src/internal/connector/mock/id_name_getter.go new file mode 100644 index 000000000..443f84d8f --- /dev/null +++ b/src/internal/connector/mock/id_name_getter.go @@ -0,0 +1,15 @@ +package mock + +import "context" + +type IDNameGetter struct { + ID, Name string + Err error +} + +func (ing IDNameGetter) GetIDAndName( + _ context.Context, + _ string, +) (string, string, error) { + return ing.ID, ing.Name, ing.Err +} diff --git a/src/internal/connector/sharepoint/api/pages_test.go b/src/internal/connector/sharepoint/api/pages_test.go index a10b7525a..49775b87e 100644 --- a/src/internal/connector/sharepoint/api/pages_test.go +++ b/src/internal/connector/sharepoint/api/pages_test.go @@ -12,9 +12,9 @@ import ( "github.com/alcionai/corso/src/internal/common" discover "github.com/alcionai/corso/src/internal/connector/discovery/api" - "github.com/alcionai/corso/src/internal/connector/mockconnector" "github.com/alcionai/corso/src/internal/connector/sharepoint" "github.com/alcionai/corso/src/internal/connector/sharepoint/api" + spMock "github.com/alcionai/corso/src/internal/connector/sharepoint/mock" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/account" "github.com/alcionai/corso/src/pkg/fault" @@ -86,7 +86,7 @@ func (suite *SharePointPageSuite) TestRestoreSinglePage() { // Create Test Page //nolint:lll - byteArray := mockconnector.GetMockPage("Byte Test") + byteArray := spMock.Page("Byte Test") pageData := sharepoint.NewItem( testName, diff --git a/src/internal/connector/sharepoint/collection_test.go b/src/internal/connector/sharepoint/collection_test.go index 08c9e8c21..33103acee 100644 --- a/src/internal/connector/sharepoint/collection_test.go +++ b/src/internal/connector/sharepoint/collection_test.go @@ -14,9 +14,9 @@ import ( "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/common/ptr" - "github.com/alcionai/corso/src/internal/connector/mockconnector" "github.com/alcionai/corso/src/internal/connector/onedrive" "github.com/alcionai/corso/src/internal/connector/sharepoint/api" + spMock "github.com/alcionai/corso/src/internal/connector/sharepoint/mock" "github.com/alcionai/corso/src/internal/connector/support" "github.com/alcionai/corso/src/internal/data" "github.com/alcionai/corso/src/internal/tester" @@ -97,7 +97,7 @@ func (suite *SharePointCollectionSuite) TestCollection_Items() { }, getItem: func(t *testing.T, name string) *Item { ow := kioser.NewJsonSerializationWriter() - listing := mockconnector.GetMockListDefault(name) + listing := spMock.ListDefault(name) listing.SetDisplayName(&name) err := ow.WriteObjectValue("", listing) @@ -132,7 +132,7 @@ func (suite *SharePointCollectionSuite) TestCollection_Items() { return dir }, getItem: func(t *testing.T, itemName string) *Item { - byteArray := mockconnector.GetMockPage(itemName) + byteArray := spMock.Page(itemName) page, err := support.CreatePageFromBytes(byteArray) require.NoError(t, err, clues.ToCore(err)) @@ -182,7 +182,7 @@ func (suite *SharePointCollectionSuite) TestListCollection_Restore() { t := suite.T() service := createTestService(t, suite.creds) - listing := mockconnector.GetMockListDefault("Mock List") + listing := spMock.ListDefault("Mock List") testName := "MockListing" listing.SetDisplayName(&testName) byteArray, err := service.Serialize(listing) diff --git a/src/internal/connector/mockconnector/mock_data_list.go b/src/internal/connector/sharepoint/mock/list.go similarity index 74% rename from src/internal/connector/mockconnector/mock_data_list.go rename to src/internal/connector/sharepoint/mock/list.go index 66fab8b99..885940233 100644 --- a/src/internal/connector/mockconnector/mock_data_list.go +++ b/src/internal/connector/sharepoint/mock/list.go @@ -1,4 +1,4 @@ -package mockconnector +package mock import ( "bytes" @@ -17,37 +17,37 @@ import ( ) var ( - _ data.Stream = &MockListData{} - _ data.BackupCollection = &MockListCollection{} + _ data.Stream = &ListData{} + _ data.BackupCollection = &ListCollection{} ) -type MockListCollection struct { +type ListCollection struct { fullPath path.Path - Data []*MockListData + Data []*ListData Names []string } -func (mlc *MockListCollection) SetPath(p path.Path) { +func (mlc *ListCollection) SetPath(p path.Path) { mlc.fullPath = p } -func (mlc *MockListCollection) State() data.CollectionState { +func (mlc *ListCollection) State() data.CollectionState { return data.NewState } -func (mlc *MockListCollection) FullPath() path.Path { +func (mlc *ListCollection) FullPath() path.Path { return mlc.fullPath } -func (mlc *MockListCollection) DoNotMergeItems() bool { +func (mlc *ListCollection) DoNotMergeItems() bool { return false } -func (mlc *MockListCollection) PreviousPath() path.Path { +func (mlc *ListCollection) PreviousPath() path.Path { return nil } -func (mlc *MockListCollection) Items( +func (mlc *ListCollection) Items( ctx context.Context, _ *fault.Bus, // unused ) <-chan data.Stream { @@ -64,7 +64,7 @@ func (mlc *MockListCollection) Items( return res } -type MockListData struct { +type ListData struct { ID string Reader io.ReadCloser ReadErr error @@ -72,25 +72,25 @@ type MockListData struct { deleted bool } -func (mld *MockListData) UUID() string { +func (mld *ListData) UUID() string { return mld.ID } -func (mld MockListData) Deleted() bool { +func (mld ListData) Deleted() bool { return mld.deleted } -func (mld *MockListData) ToReader() io.ReadCloser { +func (mld *ListData) ToReader() io.ReadCloser { return mld.Reader } -// GetMockList returns a Listable object with two columns. +// List returns a Listable object with two columns. // @param: Name of the displayable list // @param: Column Name: Defines the 2nd Column Name of the created list the values from the map. // The key values of the input map are used for the `Title` column. // The values of the map are placed within the 2nd column. // Source: https://learn.microsoft.com/en-us/graph/api/list-create?view=graph-rest-1.0&tabs=go -func GetMockList(title, columnName string, items map[string]string) models.Listable { +func List(title, columnName string, items map[string]string) models.Listable { requestBody := models.NewList() requestBody.SetDisplayName(&title) requestBody.SetName(&title) @@ -135,15 +135,15 @@ func GetMockList(title, columnName string, items map[string]string) models.Lista return requestBody } -// GetMockListDefault returns a two-list column list of +// ListDefault returns a two-list column list of // Music lbums and the associated artist. -func GetMockListDefault(title string) models.Listable { - return GetMockList(title, "Artist", getItems()) +func ListDefault(title string) models.Listable { + return List(title, "Artist", getItems()) } -// GetMockListBytes returns the byte representation of GetMockList -func GetMockListBytes(title string) ([]byte, error) { - list := GetMockListDefault(title) +// ListBytes returns the byte representation of List +func ListBytes(title string) ([]byte, error) { + list := ListDefault(title) objectWriter := kjson.NewJsonSerializationWriter() defer objectWriter.Close() @@ -156,13 +156,13 @@ func GetMockListBytes(title string) ([]byte, error) { return objectWriter.GetSerializedContent() } -// GetMockListStream returns the data.Stream representation +// ListStream returns the data.Stream representation // of the Mocked SharePoint List -func GetMockListStream(t *testing.T, title string, numOfItems int) *MockListData { - byteArray, err := GetMockListBytes(title) +func ListStream(t *testing.T, title string, numOfItems int) *ListData { + byteArray, err := ListBytes(title) require.NoError(t, err, clues.ToCore(err)) - listData := &MockListData{ + listData := &ListData{ ID: title, Reader: io.NopCloser(bytes.NewReader(byteArray)), size: int64(len(byteArray)), diff --git a/src/internal/connector/sharepoint/mock/mock_test.go b/src/internal/connector/sharepoint/mock/mock_test.go new file mode 100644 index 000000000..63cd0e82e --- /dev/null +++ b/src/internal/connector/sharepoint/mock/mock_test.go @@ -0,0 +1,75 @@ +package mock + +import ( + "testing" + + "github.com/alcionai/clues" + kioser "github.com/microsoft/kiota-serialization-json-go" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" + + "github.com/alcionai/corso/src/internal/connector/support" + "github.com/alcionai/corso/src/internal/tester" +) + +type MockSuite struct { + tester.Suite +} + +func TestMockSuite(t *testing.T) { + suite.Run(t, &MockSuite{Suite: tester.NewUnitSuite(t)}) +} + +func (suite *MockSuite) TestMockByteHydration() { + subject := "Mock Hydration" + tests := []struct { + name string + transformation func(t *testing.T) error + }{ + { + name: "SharePoint: List Empty", + transformation: func(t *testing.T) error { + emptyMap := make(map[string]string) + temp := List(subject, "Artist", emptyMap) + writer := kioser.NewJsonSerializationWriter() + err := writer.WriteObjectValue("", temp) + require.NoError(t, err, clues.ToCore(err)) + + bytes, err := writer.GetSerializedContent() + require.NoError(t, err, clues.ToCore(err)) + + _, err = support.CreateListFromBytes(bytes) + + return err + }, + }, + { + name: "SharePoint: List 6 Items", + transformation: func(t *testing.T) error { + bytes, err := ListBytes(subject) + require.NoError(t, err, clues.ToCore(err)) + _, err = support.CreateListFromBytes(bytes) + return err + }, + }, + { + name: "SharePoint: Page", + transformation: func(t *testing.T) error { + bytes := Page(subject) + _, err := support.CreatePageFromBytes(bytes) + + return err + }, + }, + } + + for _, test := range tests { + suite.Run(test.name, func() { + t := suite.T() + + err := test.transformation(t) + assert.NoError(t, err, clues.ToCore(err)) + }) + } +} diff --git a/src/internal/connector/mockconnector/mock_data_page.go b/src/internal/connector/sharepoint/mock/page.go similarity index 94% rename from src/internal/connector/mockconnector/mock_data_page.go rename to src/internal/connector/sharepoint/mock/page.go index 0b8425418..879be6c6d 100644 --- a/src/internal/connector/mockconnector/mock_data_page.go +++ b/src/internal/connector/sharepoint/mock/page.go @@ -1,8 +1,8 @@ -package mockconnector +package mock -// GetMockPage returns bytes for models.SitePageable object +// Page returns bytes for models.SitePageable object // Title string changes of fields: name and title -func GetMockPage(title string) []byte { +func Page(title string) []byte { fileName := title + ".aspx" // Create Test Page diff --git a/src/internal/connector/support/m365Support_test.go b/src/internal/connector/support/m365Support_test.go index 59aee91dc..dbff1e37b 100644 --- a/src/internal/connector/support/m365Support_test.go +++ b/src/internal/connector/support/m365Support_test.go @@ -9,8 +9,9 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + exchMock "github.com/alcionai/corso/src/internal/connector/exchange/mock" bmodels "github.com/alcionai/corso/src/internal/connector/graph/betasdk/models" - "github.com/alcionai/corso/src/internal/connector/mockconnector" + spMock "github.com/alcionai/corso/src/internal/connector/sharepoint/mock" "github.com/alcionai/corso/src/internal/tester" ) @@ -44,7 +45,7 @@ func (suite *DataSupportSuite) TestCreateMessageFromBytes() { }, { name: "aMessage bytes", - byteArray: mockconnector.GetMockMessageBytes("m365 mail support test"), + byteArray: exchMock.MessageBytes("m365 mail support test"), checkError: assert.NoError, checkObject: assert.NotNil, }, @@ -83,7 +84,7 @@ func (suite *DataSupportSuite) TestCreateContactFromBytes() { }, { name: "Valid Contact", - byteArray: mockconnector.GetMockContactBytes("Support Test"), + byteArray: exchMock.ContactBytes("Support Test"), checkError: assert.NoError, isNil: assert.NotNil, }, @@ -120,7 +121,7 @@ func (suite *DataSupportSuite) TestCreateEventFromBytes() { }, { name: "Valid Event", - byteArray: mockconnector.GetDefaultMockEventBytes("Event Test"), + byteArray: exchMock.EventBytes("Event Test"), checkError: assert.NoError, isNil: assert.NotNil, }, @@ -137,7 +138,7 @@ func (suite *DataSupportSuite) TestCreateEventFromBytes() { } func (suite *DataSupportSuite) TestCreateListFromBytes() { - listBytes, err := mockconnector.GetMockListBytes("DataSupportSuite") + listBytes, err := spMock.ListBytes("DataSupportSuite") require.NoError(suite.T(), err) tests := []struct { diff --git a/src/internal/connector/support/m365Transform_test.go b/src/internal/connector/support/m365Transform_test.go index a50c75f44..924c19bb7 100644 --- a/src/internal/connector/support/m365Transform_test.go +++ b/src/internal/connector/support/m365Transform_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/alcionai/corso/src/internal/common/ptr" - "github.com/alcionai/corso/src/internal/connector/mockconnector" + exchMock "github.com/alcionai/corso/src/internal/connector/exchange/mock" "github.com/alcionai/corso/src/internal/tester" ) @@ -25,7 +25,7 @@ func TestSupportTestSuite(t *testing.T) { func (suite *SupportTestSuite) TestToMessage() { t := suite.T() - bytes := mockconnector.GetMockMessageBytes("m365 mail support test") + bytes := exchMock.MessageBytes("m365 mail support test") message, err := CreateMessageFromBytes(bytes) require.NoError(suite.T(), err, clues.ToCore(err)) @@ -39,7 +39,7 @@ func (suite *SupportTestSuite) TestToMessage() { func (suite *SupportTestSuite) TestToEventSimplified_attendees() { t := suite.T() - bytes := mockconnector.GetMockEventWithAttendeesBytes("M365 Event Support Test") + bytes := exchMock.EventWithAttendeesBytes("M365 Event Support Test") event, err := CreateEventFromBytes(bytes) require.NoError(t, err, clues.ToCore(err)) @@ -71,7 +71,7 @@ func (suite *SupportTestSuite) TestToEventSimplified_recurrence() { { name: "Test recurrence: Unspecified", event: func() models.Eventable { - bytes := mockconnector.GetMockEventWithSubjectBytes(subject) + bytes := exchMock.EventWithSubjectBytes(subject) e, err := CreateEventFromBytes(bytes) require.NoError(t, err, clues.ToCore(err)) return e @@ -84,7 +84,7 @@ func (suite *SupportTestSuite) TestToEventSimplified_recurrence() { { name: "Test recurrenceTimeZone: Unspecified", event: func() models.Eventable { - bytes := mockconnector.GetMockEventWithRecurrenceBytes(subject, `null`) + bytes := exchMock.EventWithRecurrenceBytes(subject, `null`) e, err := CreateEventFromBytes(bytes) require.NoError(t, err, clues.ToCore(err)) return e @@ -97,7 +97,7 @@ func (suite *SupportTestSuite) TestToEventSimplified_recurrence() { { name: "Test recurrenceTimeZone: Empty", event: func() models.Eventable { - bytes := mockconnector.GetMockEventWithRecurrenceBytes(subject, `""`) + bytes := exchMock.EventWithRecurrenceBytes(subject, `""`) event, err := CreateEventFromBytes(bytes) require.NoError(t, err, clues.ToCore(err)) return event @@ -110,7 +110,7 @@ func (suite *SupportTestSuite) TestToEventSimplified_recurrence() { { name: "Test recurrenceTimeZone: Valid", event: func() models.Eventable { - bytes := mockconnector.GetMockEventWithRecurrenceBytes(subject, `"Pacific Standard Time"`) + bytes := exchMock.EventWithRecurrenceBytes(subject, `"Pacific Standard Time"`) event, err := CreateEventFromBytes(bytes) require.NoError(t, err, clues.ToCore(err)) return event diff --git a/src/internal/kopia/data_collection_test.go b/src/internal/kopia/data_collection_test.go index bd37738ae..8ae52157f 100644 --- a/src/internal/kopia/data_collection_test.go +++ b/src/internal/kopia/data_collection_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/corso/src/internal/connector/mockconnector" + exchMock "github.com/alcionai/corso/src/internal/connector/exchange/mock" "github.com/alcionai/corso/src/internal/data" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/fault" @@ -168,7 +168,7 @@ func (suite *KopiaDataCollectionUnitSuite) TestFetch() { noErrFileData = "foo bar baz" - errReader = &mockconnector.MockExchangeData{ + errReader = &exchMock.Data{ ReadErr: assert.AnError, } ) diff --git a/src/internal/kopia/upload_test.go b/src/internal/kopia/upload_test.go index 0ce0904c7..d2e37b0d0 100644 --- a/src/internal/kopia/upload_test.go +++ b/src/internal/kopia/upload_test.go @@ -19,7 +19,7 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/corso/src/internal/connector/mockconnector" + exchMock "github.com/alcionai/corso/src/internal/connector/exchange/mock" "github.com/alcionai/corso/src/internal/data" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/backup/details" @@ -717,11 +717,11 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTree() { } collections := []data.BackupCollection{ - mockconnector.NewMockExchangeCollection( + exchMock.NewCollection( suite.testStoragePath, suite.testLocationPath, expectedFileCount[user1Encoded]), - mockconnector.NewMockExchangeCollection( + exchMock.NewCollection( storeP2, locP2, expectedFileCount[user2Encoded]), @@ -800,11 +800,11 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTree_MixedDirectory() { name: "SubdirFirst", layout: []data.BackupCollection{ - mockconnector.NewMockExchangeCollection( + exchMock.NewCollection( storeP2, locP2, 5), - mockconnector.NewMockExchangeCollection( + exchMock.NewCollection( suite.testStoragePath, suite.testLocationPath, 42), @@ -813,11 +813,11 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTree_MixedDirectory() { name: "SubdirLast", layout: []data.BackupCollection{ - mockconnector.NewMockExchangeCollection( + exchMock.NewCollection( suite.testStoragePath, suite.testLocationPath, 42), - mockconnector.NewMockExchangeCollection( + exchMock.NewCollection( storeP2, locP2, 5), @@ -908,11 +908,11 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTree_Fails() { // - Inbox // - 42 separate files []data.BackupCollection{ - mockconnector.NewMockExchangeCollection( + exchMock.NewCollection( suite.testStoragePath, suite.testLocationPath, 5), - mockconnector.NewMockExchangeCollection( + exchMock.NewCollection( storeP2, locP2, 42), @@ -921,7 +921,7 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTree_Fails() { { "NoCollectionPath", []data.BackupCollection{ - mockconnector.NewMockExchangeCollection( + exchMock.NewCollection( nil, nil, 5), @@ -1047,7 +1047,7 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTreeErrors() { nowPath = storePath2 } - mc := mockconnector.NewMockExchangeCollection(nowPath, locPath, 0) + mc := exchMock.NewCollection(nowPath, locPath, 0) mc.ColState = s mc.PrevPath = prevPath @@ -1113,7 +1113,7 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTreeSingleSubtree() { { name: "SkipsDeletedItems", inputCollections: func() []data.BackupCollection { - mc := mockconnector.NewMockExchangeCollection(storePath, locPath, 1) + mc := exchMock.NewCollection(storePath, locPath, 1) mc.Names[0] = testFileName mc.DeletedItems[0] = true @@ -1137,7 +1137,7 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTreeSingleSubtree() { { name: "AddsNewItems", inputCollections: func() []data.BackupCollection { - mc := mockconnector.NewMockExchangeCollection(storePath, locPath, 1) + mc := exchMock.NewCollection(storePath, locPath, 1) mc.Names[0] = testFileName2 mc.Data[0] = testFileData2 mc.ColState = data.NotMovedState @@ -1172,7 +1172,7 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTreeSingleSubtree() { { name: "SkipsUpdatedItems", inputCollections: func() []data.BackupCollection { - mc := mockconnector.NewMockExchangeCollection(storePath, locPath, 1) + mc := exchMock.NewCollection(storePath, locPath, 1) mc.Names[0] = testFileName mc.Data[0] = testFileData2 mc.ColState = data.NotMovedState @@ -1203,11 +1203,11 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTreeSingleSubtree() { { name: "DeleteAndNew", inputCollections: func() []data.BackupCollection { - mc1 := mockconnector.NewMockExchangeCollection(storePath, locPath, 0) + mc1 := exchMock.NewCollection(storePath, locPath, 0) mc1.ColState = data.DeletedState mc1.PrevPath = storePath - mc2 := mockconnector.NewMockExchangeCollection(storePath, locPath, 1) + mc2 := exchMock.NewCollection(storePath, locPath, 1) mc2.ColState = data.NewState mc2.Names[0] = testFileName2 mc2.Data[0] = testFileData2 @@ -1238,11 +1238,11 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTreeSingleSubtree() { { name: "MovedAndNew", inputCollections: func() []data.BackupCollection { - mc1 := mockconnector.NewMockExchangeCollection(storePath2, locPath2, 0) + mc1 := exchMock.NewCollection(storePath2, locPath2, 0) mc1.ColState = data.MovedState mc1.PrevPath = storePath - mc2 := mockconnector.NewMockExchangeCollection(storePath, locPath, 1) + mc2 := exchMock.NewCollection(storePath, locPath, 1) mc2.ColState = data.NewState mc2.Names[0] = testFileName2 mc2.Data[0] = testFileData2 @@ -1282,7 +1282,7 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTreeSingleSubtree() { { name: "NewDoesntMerge", inputCollections: func() []data.BackupCollection { - mc1 := mockconnector.NewMockExchangeCollection(storePath, locPath, 1) + mc1 := exchMock.NewCollection(storePath, locPath, 1) mc1.ColState = data.NewState mc1.Names[0] = testFileName2 mc1.Data[0] = testFileData2 @@ -1517,7 +1517,7 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTreeMultipleSubdirecto []string{testTenant, service, testUser, category, testInboxDir + "2"}, false) - mc := mockconnector.NewMockExchangeCollection(newStorePath, newLocPath, 0) + mc := exchMock.NewCollection(newStorePath, newLocPath, 0) mc.PrevPath = inboxStorePath mc.ColState = data.MovedState @@ -1585,11 +1585,11 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTreeMultipleSubdirecto []string{testTenant, service, testUser, category, workID}, false) - inbox := mockconnector.NewMockExchangeCollection(newInboxStorePath, newInboxLocPath, 0) + inbox := exchMock.NewCollection(newInboxStorePath, newInboxLocPath, 0) inbox.PrevPath = inboxStorePath inbox.ColState = data.MovedState - work := mockconnector.NewMockExchangeCollection(newWorkStorePath, newWorkLocPath, 0) + work := exchMock.NewCollection(newWorkStorePath, newWorkLocPath, 0) work.PrevPath = workStorePath work.ColState = data.MovedState @@ -1649,11 +1649,11 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTreeMultipleSubdirecto []string{testTenant, service, testUser, category, workDir}, false) - inbox := mockconnector.NewMockExchangeCollection(inboxStorePath, inboxLocPath, 0) + inbox := exchMock.NewCollection(inboxStorePath, inboxLocPath, 0) inbox.PrevPath = inboxStorePath inbox.ColState = data.DeletedState - work := mockconnector.NewMockExchangeCollection(newWorkStorePath, newWorkLocPath, 0) + work := exchMock.NewCollection(newWorkStorePath, newWorkLocPath, 0) work.PrevPath = workStorePath work.ColState = data.MovedState @@ -1682,11 +1682,11 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTreeMultipleSubdirecto { name: "ReplaceDeletedDirectory", inputCollections: func(t *testing.T) []data.BackupCollection { - personal := mockconnector.NewMockExchangeCollection(personalStorePath, personalLocPath, 0) + personal := exchMock.NewCollection(personalStorePath, personalLocPath, 0) personal.PrevPath = personalStorePath personal.ColState = data.DeletedState - work := mockconnector.NewMockExchangeCollection(personalStorePath, personalLocPath, 0) + work := exchMock.NewCollection(personalStorePath, personalLocPath, 0) work.PrevPath = workStorePath work.ColState = data.MovedState @@ -1723,11 +1723,11 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTreeMultipleSubdirecto { name: "ReplaceDeletedDirectoryWithNew", inputCollections: func(t *testing.T) []data.BackupCollection { - personal := mockconnector.NewMockExchangeCollection(personalStorePath, personalLocPath, 0) + personal := exchMock.NewCollection(personalStorePath, personalLocPath, 0) personal.PrevPath = personalStorePath personal.ColState = data.DeletedState - newCol := mockconnector.NewMockExchangeCollection(personalStorePath, personalLocPath, 1) + newCol := exchMock.NewCollection(personalStorePath, personalLocPath, 1) newCol.ColState = data.NewState newCol.Names[0] = workFileName2 newCol.Data[0] = workFileData2 @@ -1774,11 +1774,11 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTreeMultipleSubdirecto { name: "ReplaceDeletedSubtreeWithNew", inputCollections: func(t *testing.T) []data.BackupCollection { - oldInbox := mockconnector.NewMockExchangeCollection(inboxStorePath, inboxLocPath, 0) + oldInbox := exchMock.NewCollection(inboxStorePath, inboxLocPath, 0) oldInbox.PrevPath = inboxStorePath oldInbox.ColState = data.DeletedState - newCol := mockconnector.NewMockExchangeCollection(inboxStorePath, inboxLocPath, 1) + newCol := exchMock.NewCollection(inboxStorePath, inboxLocPath, 1) newCol.ColState = data.NewState newCol.Names[0] = workFileName2 newCol.Data[0] = workFileData2 @@ -1817,11 +1817,11 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTreeMultipleSubdirecto []string{testTenant, service, testUser, category, personalDir}, false) - personal := mockconnector.NewMockExchangeCollection(newPersonalStorePath, newPersonalLocPath, 0) + personal := exchMock.NewCollection(newPersonalStorePath, newPersonalLocPath, 0) personal.PrevPath = personalStorePath personal.ColState = data.MovedState - work := mockconnector.NewMockExchangeCollection(personalStorePath, personalLocPath, 0) + work := exchMock.NewCollection(personalStorePath, personalLocPath, 0) work.PrevPath = workStorePath work.ColState = data.MovedState @@ -1878,7 +1878,7 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTreeMultipleSubdirecto []string{testTenant, service, testUser, category, workDir}, false) - personal := mockconnector.NewMockExchangeCollection(newPersonalStorePath, newPersonalLocPath, 2) + personal := exchMock.NewCollection(newPersonalStorePath, newPersonalLocPath, 2) personal.PrevPath = personalStorePath personal.ColState = data.MovedState personal.Names[0] = personalFileName2 @@ -1957,7 +1957,7 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTreeMultipleSubdirecto []string{testTenant, service, testUser, category, personalDir, workDir}, false) - inbox := mockconnector.NewMockExchangeCollection(newInboxStorePath, newInboxLocPath, 1) + inbox := exchMock.NewCollection(newInboxStorePath, newInboxLocPath, 1) inbox.PrevPath = inboxStorePath inbox.ColState = data.MovedState inbox.DoNotMerge = true @@ -1966,7 +1966,7 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTreeMultipleSubdirecto inbox.Names[0] = inboxFileName2 inbox.Data[0] = inboxFileData2 - work := mockconnector.NewMockExchangeCollection(newWorkStorePath, newWorkLocPath, 1) + work := exchMock.NewCollection(newWorkStorePath, newWorkLocPath, 1) work.PrevPath = workStorePath work.ColState = data.MovedState work.Names[0] = testFileName6 @@ -2025,7 +2025,7 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTreeMultipleSubdirecto { name: "NoMoveParentDeleteFileNoMergeSubtreeMerge", inputCollections: func(t *testing.T) []data.BackupCollection { - inbox := mockconnector.NewMockExchangeCollection(inboxStorePath, inboxLocPath, 1) + inbox := exchMock.NewCollection(inboxStorePath, inboxLocPath, 1) inbox.PrevPath = inboxStorePath inbox.ColState = data.NotMovedState inbox.DoNotMerge = true @@ -2034,7 +2034,7 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTreeMultipleSubdirecto inbox.Names[0] = inboxFileName2 inbox.Data[0] = inboxFileData2 - work := mockconnector.NewMockExchangeCollection(workStorePath, workLocPath, 1) + work := exchMock.NewCollection(workStorePath, workLocPath, 1) work.PrevPath = workStorePath work.ColState = data.NotMovedState work.Names[0] = testFileName6 @@ -2255,7 +2255,7 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTreeSkipsDeletedSubtre toMerge: newMergeDetails(), errs: fault.New(true), } - mc := mockconnector.NewMockExchangeCollection(suite.testStoragePath, suite.testStoragePath, 1) + mc := exchMock.NewCollection(suite.testStoragePath, suite.testStoragePath, 1) mc.PrevPath = mc.FullPath() mc.ColState = data.DeletedState msw := &mockSnapshotWalker{ @@ -2357,7 +2357,7 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTree_HandleEmptyBase() toMerge: newMergeDetails(), errs: fault.New(true), } - mc := mockconnector.NewMockExchangeCollection(archiveStorePath, archiveLocPath, 1) + mc := exchMock.NewCollection(archiveStorePath, archiveLocPath, 1) mc.ColState = data.NewState mc.Names[0] = testFileName2 mc.Data[0] = testFileData2 @@ -2614,7 +2614,7 @@ func (suite *HierarchyBuilderUnitSuite) TestBuildDirectoryTreeSelectsCorrectSubt errs: fault.New(true), } - mc := mockconnector.NewMockExchangeCollection(inboxPath, inboxPath, 1) + mc := exchMock.NewCollection(inboxPath, inboxPath, 1) mc.PrevPath = mc.FullPath() mc.ColState = data.NotMovedState mc.Names[0] = inboxFileName2 diff --git a/src/internal/kopia/wrapper_test.go b/src/internal/kopia/wrapper_test.go index a98c9f8ca..507c4924c 100644 --- a/src/internal/kopia/wrapper_test.go +++ b/src/internal/kopia/wrapper_test.go @@ -17,7 +17,7 @@ import ( "github.com/stretchr/testify/suite" "golang.org/x/exp/maps" - "github.com/alcionai/corso/src/internal/connector/mockconnector" + exchMock "github.com/alcionai/corso/src/internal/connector/exchange/mock" "github.com/alcionai/corso/src/internal/connector/onedrive" "github.com/alcionai/corso/src/internal/data" "github.com/alcionai/corso/src/internal/tester" @@ -209,11 +209,11 @@ func (suite *KopiaIntegrationSuite) TearDownTest() { func (suite *KopiaIntegrationSuite) TestBackupCollections() { collections := []data.BackupCollection{ - mockconnector.NewMockExchangeCollection( + exchMock.NewCollection( suite.storePath1, suite.locPath1, 5), - mockconnector.NewMockExchangeCollection( + exchMock.NewCollection( suite.storePath2, suite.locPath2, 42), @@ -385,7 +385,7 @@ func (suite *KopiaIntegrationSuite) TestBackupCollections_NoDetailsForMeta() { numDeetsEntries: 3, hasMetaDeets: true, cols: func() []data.BackupCollection { - mc := mockconnector.NewMockExchangeCollection( + mc := exchMock.NewCollection( storePath, locPath, 3) @@ -404,7 +404,7 @@ func (suite *KopiaIntegrationSuite) TestBackupCollections_NoDetailsForMeta() { numDeetsEntries: 1, hasMetaDeets: false, cols: func() []data.BackupCollection { - mc := mockconnector.NewMockExchangeCollection( + mc := exchMock.NewCollection( storePath, locPath, 1) @@ -512,8 +512,8 @@ func (suite *KopiaIntegrationSuite) TestRestoreAfterCompressionChange() { tags[k] = "" } - dc1 := mockconnector.NewMockExchangeCollection(suite.storePath1, suite.locPath1, 1) - dc2 := mockconnector.NewMockExchangeCollection(suite.storePath2, suite.locPath2, 1) + dc1 := exchMock.NewCollection(suite.storePath1, suite.locPath1, 1) + dc2 := exchMock.NewCollection(suite.storePath2, suite.locPath2, 1) fp1, err := suite.storePath1.Append(dc1.Names[0], true) require.NoError(t, err, clues.ToCore(err)) @@ -607,11 +607,11 @@ func (suite *KopiaIntegrationSuite) TestBackupCollections_ReaderError() { &mockBackupCollection{ path: suite.storePath1, streams: []data.Stream{ - &mockconnector.MockExchangeData{ + &exchMock.Data{ ID: testFileName, Reader: io.NopCloser(bytes.NewReader(testFileData)), }, - &mockconnector.MockExchangeData{ + &exchMock.Data{ ID: testFileName2, Reader: io.NopCloser(bytes.NewReader(testFileData2)), }, @@ -620,19 +620,19 @@ func (suite *KopiaIntegrationSuite) TestBackupCollections_ReaderError() { &mockBackupCollection{ path: suite.storePath2, streams: []data.Stream{ - &mockconnector.MockExchangeData{ + &exchMock.Data{ ID: testFileName3, Reader: io.NopCloser(bytes.NewReader(testFileData3)), }, - &mockconnector.MockExchangeData{ + &exchMock.Data{ ID: testFileName4, ReadErr: assert.AnError, }, - &mockconnector.MockExchangeData{ + &exchMock.Data{ ID: testFileName5, Reader: io.NopCloser(bytes.NewReader(testFileData5)), }, - &mockconnector.MockExchangeData{ + &exchMock.Data{ ID: testFileName6, Reader: io.NopCloser(bytes.NewReader(testFileData6)), }, @@ -841,7 +841,7 @@ func (suite *KopiaSimpleRepoIntegrationSuite) SetupTest() { for _, item := range suite.files[parent.String()] { collection.streams = append( collection.streams, - &mockconnector.MockExchangeData{ + &exchMock.Data{ ID: item.itemPath.Item(), Reader: io.NopCloser(bytes.NewReader(item.data)), }, @@ -978,7 +978,7 @@ func (suite *KopiaSimpleRepoIntegrationSuite) TestBackupExcludeItem() { expectedCachedItems: len(suite.filesByPath), expectedUncachedItems: 1, cols: func() []data.BackupCollection { - c := mockconnector.NewMockExchangeCollection( + c := exchMock.NewCollection( suite.testPath1, suite.testPath1, 1) diff --git a/src/internal/operations/backup_integration_test.go b/src/internal/operations/backup_integration_test.go index 89a5b62fd..3e3dbca7b 100644 --- a/src/internal/operations/backup_integration_test.go +++ b/src/internal/operations/backup_integration_test.go @@ -21,8 +21,9 @@ import ( "github.com/alcionai/corso/src/internal/connector" "github.com/alcionai/corso/src/internal/connector/exchange" "github.com/alcionai/corso/src/internal/connector/exchange/api" + exchMock "github.com/alcionai/corso/src/internal/connector/exchange/mock" "github.com/alcionai/corso/src/internal/connector/graph" - "github.com/alcionai/corso/src/internal/connector/mockconnector" + "github.com/alcionai/corso/src/internal/connector/mock" "github.com/alcionai/corso/src/internal/connector/onedrive" "github.com/alcionai/corso/src/internal/connector/support" "github.com/alcionai/corso/src/internal/data" @@ -457,7 +458,7 @@ func buildCollections( c.pathFolders, false) - mc := mockconnector.NewMockExchangeCollection(pth, pth, len(c.items)) + mc := exchMock.NewCollection(pth, pth, len(c.items)) for i := 0; i < len(c.items); i++ { mc.Names[i] = c.items[i].name @@ -548,7 +549,7 @@ func (suite *BackupOpIntegrationSuite) SetupSuite() { func (suite *BackupOpIntegrationSuite) TestNewBackupOperation() { kw := &kopia.Wrapper{} sw := &store.Wrapper{} - gc := &mockconnector.GraphConnector{} + gc := &mock.GraphConnector{} acct := tester.NewM365Account(suite.T()) table := []struct { @@ -770,7 +771,7 @@ func (suite *BackupOpIntegrationSuite) TestBackup_Run_exchangeIncrementals() { } mailDBF := func(id, timeStamp, subject, body string) []byte { - return mockconnector.GetMockMessageWith( + return exchMock.MessageWith( suite.user, suite.user, suite.user, subject, body, body, now, now, now, now) @@ -779,7 +780,7 @@ func (suite *BackupOpIntegrationSuite) TestBackup_Run_exchangeIncrementals() { contactDBF := func(id, timeStamp, subject, body string) []byte { given, mid, sur := id[:8], id[9:13], id[len(id)-12:] - return mockconnector.GetMockContactBytesWith( + return exchMock.ContactBytesWith( given+" "+sur, sur+", "+given, given, mid, sur, @@ -788,9 +789,9 @@ func (suite *BackupOpIntegrationSuite) TestBackup_Run_exchangeIncrementals() { } eventDBF := func(id, timeStamp, subject, body string) []byte { - return mockconnector.GetMockEventWith( + return exchMock.EventWith( suite.user, subject, body, body, - now, now, mockconnector.NoRecurrence, mockconnector.NoAttendees, false) + now, now, exchMock.NoRecurrence, exchMock.NoAttendees, false) } // test data set diff --git a/src/internal/operations/backup_test.go b/src/internal/operations/backup_test.go index 41c4d1849..bd95275c8 100644 --- a/src/internal/operations/backup_test.go +++ b/src/internal/operations/backup_test.go @@ -14,7 +14,7 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/corso/src/internal/connector/mockconnector" + "github.com/alcionai/corso/src/internal/connector/mock" "github.com/alcionai/corso/src/internal/data" evmock "github.com/alcionai/corso/src/internal/events/mock" "github.com/alcionai/corso/src/internal/kopia" @@ -397,7 +397,7 @@ func (suite *BackupOpUnitSuite) TestBackupOperation_PersistResults() { var ( kw = &kopia.Wrapper{} sw = &store.Wrapper{} - gc = &mockconnector.GraphConnector{} + gc = &mock.GraphConnector{} acct = account.Account{} now = time.Now() ) diff --git a/src/internal/operations/restore_test.go b/src/internal/operations/restore_test.go index 35ee6d8c6..8496f11da 100644 --- a/src/internal/operations/restore_test.go +++ b/src/internal/operations/restore_test.go @@ -13,8 +13,9 @@ import ( "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/connector" "github.com/alcionai/corso/src/internal/connector/exchange" + exchMock "github.com/alcionai/corso/src/internal/connector/exchange/mock" "github.com/alcionai/corso/src/internal/connector/graph" - "github.com/alcionai/corso/src/internal/connector/mockconnector" + "github.com/alcionai/corso/src/internal/connector/mock" "github.com/alcionai/corso/src/internal/connector/onedrive/api" "github.com/alcionai/corso/src/internal/data" "github.com/alcionai/corso/src/internal/events" @@ -50,7 +51,7 @@ func (suite *RestoreOpSuite) TestRestoreOperation_PersistResults() { var ( kw = &kopia.Wrapper{} sw = &store.Wrapper{} - gc = &mockconnector.GraphConnector{} + gc = &mock.GraphConnector{} acct = account.Account{} now = time.Now() dest = tester.DefaultTestRestoreDestination() @@ -72,7 +73,7 @@ func (suite *RestoreOpSuite) TestRestoreOperation_PersistResults() { }, cs: []data.RestoreCollection{ data.NotFoundRestoreCollection{ - Collection: &mockconnector.MockExchangeDataCollection{}, + Collection: &exchMock.DataCollection{}, }, }, gc: &data.CollectionStats{ @@ -215,7 +216,7 @@ func (suite *RestoreOpIntegrationSuite) TearDownSuite() { func (suite *RestoreOpIntegrationSuite) TestNewRestoreOperation() { kw := &kopia.Wrapper{} sw := &store.Wrapper{} - gc := &mockconnector.GraphConnector{} + gc := &mock.GraphConnector{} acct := tester.NewM365Account(suite.T()) dest := tester.DefaultTestRestoreDestination()