From 7d72cd12a4314dee60cd31f1490db87a7e4f2165 Mon Sep 17 00:00:00 2001 From: Keepers Date: Fri, 14 Oct 2022 14:38:33 -0600 Subject: [PATCH] unskip event restores (#1019) ## Type of change - [x] :robot: Test ## Issue(s) * #1018 ## Test Plan - [x] :green_heart: E2E --- src/cli/restore/exchange_integration_test.go | 7 +- .../exchange/exchange_service_test.go | 66 +++++++++---------- src/internal/operations/backup.go | 1 - src/internal/operations/backup_test.go | 16 ++--- src/internal/operations/restore_test.go | 6 +- 5 files changed, 45 insertions(+), 51 deletions(-) diff --git a/src/cli/restore/exchange_integration_test.go b/src/cli/restore/exchange_integration_test.go index b020d73f4..2c80d84e5 100644 --- a/src/cli/restore/exchange_integration_test.go +++ b/src/cli/restore/exchange_integration_test.go @@ -28,12 +28,7 @@ var ( events = path.EventsCategory ) -// TODO: bring back event restore testing when they no longer produce -// notification emails. Currently, the duplication causes our tests -// dataset to grow until timeouts occur. -// var backupDataSets = []path.CategoryType{email, contacts, events} - -var backupDataSets = []path.CategoryType{contacts, email} +var backupDataSets = []path.CategoryType{email, contacts, events} type RestoreExchangeIntegrationSuite struct { suite.Suite diff --git a/src/internal/connector/exchange/exchange_service_test.go b/src/internal/connector/exchange/exchange_service_test.go index 89571a9d2..a997b8689 100644 --- a/src/internal/connector/exchange/exchange_service_test.go +++ b/src/internal/connector/exchange/exchange_service_test.go @@ -448,9 +448,6 @@ func (suite *ExchangeServiceSuite) TestRestoreEvent() { // TestRestoreExchangeObject verifies path.Category usage for restored objects func (suite *ExchangeServiceSuite) TestRestoreExchangeObject() { - ctx, flush := tester.NewContext() - defer flush() - t := suite.T() userID := tester.M365UserID(t) now := time.Now() @@ -459,14 +456,14 @@ func (suite *ExchangeServiceSuite) TestRestoreExchangeObject() { bytes []byte category path.CategoryType cleanupFunc func(context.Context, graph.Service, string, string) error - destination func() string + destination func(context.Context) string }{ { name: "Test Mail", bytes: mockconnector.GetMockMessageBytes("Restore Exchange Object"), category: path.EmailCategory, cleanupFunc: DeleteMailFolder, - destination: func() string { + destination: func(ctx context.Context) string { folderName := "TestRestoreMailObject: " + common.FormatSimpleDateTime(now) folder, err := CreateMailFolder(ctx, suite.es, userID, folderName) require.NoError(t, err) @@ -479,7 +476,7 @@ func (suite *ExchangeServiceSuite) TestRestoreExchangeObject() { bytes: mockconnector.GetMockMessageWithDirectAttachment("Restore 1 Attachment"), category: path.EmailCategory, cleanupFunc: DeleteMailFolder, - destination: func() string { + destination: func(ctx context.Context) string { folderName := "TestRestoreMailwithAttachment: " + common.FormatSimpleDateTime(now) folder, err := CreateMailFolder(ctx, suite.es, userID, folderName) require.NoError(t, err) @@ -492,7 +489,7 @@ func (suite *ExchangeServiceSuite) TestRestoreExchangeObject() { bytes: mockconnector.GetMockMessageWithLargeAttachment("Restore Large Attachment"), category: path.EmailCategory, cleanupFunc: DeleteMailFolder, - destination: func() string { + destination: func(ctx context.Context) string { folderName := "TestRestoreMailwithLargeAttachment: " + common.FormatSimpleDateTime(now) folder, err := CreateMailFolder(ctx, suite.es, userID, folderName) require.NoError(t, err) @@ -505,7 +502,7 @@ func (suite *ExchangeServiceSuite) TestRestoreExchangeObject() { bytes: mockconnector.GetMockMessageWithTwoAttachments("Restore 2 Attachments"), category: path.EmailCategory, cleanupFunc: DeleteMailFolder, - destination: func() string { + destination: func(ctx context.Context) string { folderName := "TestRestoreMailwithAttachments: " + common.FormatSimpleDateTime(now) folder, err := CreateMailFolder(ctx, suite.es, userID, folderName) require.NoError(t, err) @@ -514,38 +511,41 @@ func (suite *ExchangeServiceSuite) TestRestoreExchangeObject() { }, }, // TODO: #884 - reinstate when able to specify root folder by name - // { - // name: "Test Contact", - // bytes: mockconnector.GetMockContactBytes("Test_Omega"), - // category: path.ContactsCategory, - // cleanupFunc: DeleteContactFolder, - // destination: func() string { - // folderName := "TestRestoreContactObject: " + common.FormatSimpleDateTime(now) - // folder, err := CreateContactFolder(suite.es, userID, folderName) - // require.NoError(t, err) + { + name: "Test Contact", + bytes: mockconnector.GetMockContactBytes("Test_Omega"), + category: path.ContactsCategory, + cleanupFunc: DeleteContactFolder, + destination: func(ctx context.Context) string { + folderName := "TestRestoreContactObject: " + common.FormatSimpleDateTime(now) + folder, err := CreateContactFolder(ctx, suite.es, userID, folderName) + require.NoError(t, err) - // return *folder.GetId() - // }, - // }, - // { - // name: "Test Events", - // bytes: mockconnector.GetMockEventBytes("Restored Event Object"), - // category: path.EventsCategory, - // cleanupFunc: DeleteCalendar, - // destination: func() string { - // calendarName := "TestRestoreEventObject: " + common.FormatSimpleDateTime(now) - // calendar, err := CreateCalendar(suite.es, userID, calendarName) - // require.NoError(t, err) + return *folder.GetId() + }, + }, + { + name: "Test Events", + bytes: mockconnector.GetMockEventBytes("Restored Event Object"), + category: path.EventsCategory, + cleanupFunc: DeleteCalendar, + destination: func(ctx context.Context) string { + calendarName := "TestRestoreEventObject: " + common.FormatSimpleDateTime(now) + calendar, err := CreateCalendar(ctx, suite.es, userID, calendarName) + require.NoError(t, err) - // return *calendar.GetId() - // }, - // }, + return *calendar.GetId() + }, + }, } for _, test := range tests { suite.T().Run(test.name, func(t *testing.T) { + ctx, flush := tester.NewContext() + defer flush() + service := loadService(t) - destination := test.destination() + destination := test.destination(ctx) info, err := RestoreExchangeObject( ctx, test.bytes, diff --git a/src/internal/operations/backup.go b/src/internal/operations/backup.go index 0b647e547..6e7bb05ae 100644 --- a/src/internal/operations/backup.go +++ b/src/internal/operations/backup.go @@ -231,7 +231,6 @@ func (op *BackupOperation) createBackupModels( events.Service: op.Selectors.Service.String(), events.StartTime: op.Results.StartedAt, events.Status: op.Status, - // TODO: events.ExchangeDataObserved: , }, ) diff --git a/src/internal/operations/backup_test.go b/src/internal/operations/backup_test.go index addb906fd..7deecbc80 100644 --- a/src/internal/operations/backup_test.go +++ b/src/internal/operations/backup_test.go @@ -178,10 +178,8 @@ func (suite *BackupOpIntegrationSuite) TestBackup_Run() { ctx, flush := tester.NewContext() defer flush() - t := suite.T() - - m365UserID := tester.M365UserID(t) - acct := tester.NewM365Account(t) + m365UserID := tester.M365UserID(suite.T()) + acct := tester.NewM365Account(suite.T()) tests := []struct { name string @@ -195,7 +193,6 @@ func (suite *BackupOpIntegrationSuite) TestBackup_Run() { return &sel.Selector }, }, - { name: "Integration Exchange.Contacts", selectFunc: func() *selectors.Selector { @@ -209,7 +206,6 @@ func (suite *BackupOpIntegrationSuite) TestBackup_Run() { selectFunc: func() *selectors.Selector { sel := selectors.NewExchangeBackup() sel.Include(sel.EventCalendars([]string{m365UserID}, []string{exchange.DefaultCalendar})) - return &sel.Selector }, }, @@ -250,14 +246,14 @@ func (suite *BackupOpIntegrationSuite) TestBackup_Run() { require.NoError(t, bo.Run(ctx)) require.NotEmpty(t, bo.Results) require.NotEmpty(t, bo.Results.BackupID) - assert.Equal(t, bo.Status, Completed) + assert.Equalf(t, Completed, bo.Status, "backup status %s is not Completed", bo.Status) assert.Less(t, 0, bo.Results.ItemsRead) assert.Less(t, 0, bo.Results.ItemsWritten) assert.Less(t, int64(0), bo.Results.BytesRead, "bytes read") assert.Less(t, int64(0), bo.Results.BytesUploaded, "bytes uploaded") assert.Equal(t, 1, bo.Results.ResourceOwners) - assert.Zero(t, bo.Results.ReadErrors) - assert.Zero(t, bo.Results.WriteErrors) + assert.NoError(t, bo.Results.ReadErrors) + assert.NoError(t, bo.Results.WriteErrors) assert.Equal(t, 1, mb.TimesCalled[events.BackupStart], "backup-start events") assert.Equal(t, 1, mb.TimesCalled[events.BackupEnd], "backup-end events") assert.Equal(t, @@ -316,7 +312,7 @@ func (suite *BackupOpIntegrationSuite) TestBackupOneDrive_Run() { require.NoError(t, bo.Run(ctx)) require.NotEmpty(t, bo.Results) require.NotEmpty(t, bo.Results.BackupID) - assert.Equal(t, bo.Status, Completed) + assert.Equalf(t, Completed, bo.Status, "backup status %s is not Completed", bo.Status) assert.Equal(t, bo.Results.ItemsRead, bo.Results.ItemsWritten) assert.Less(t, int64(0), bo.Results.BytesRead, "bytes read") assert.Less(t, int64(0), bo.Results.BytesUploaded, "bytes uploaded") diff --git a/src/internal/operations/restore_test.go b/src/internal/operations/restore_test.go index 177e342b1..3f190f2a8 100644 --- a/src/internal/operations/restore_test.go +++ b/src/internal/operations/restore_test.go @@ -179,7 +179,11 @@ func (suite *RestoreOpIntegrationSuite) SetupSuite() { suite.sw = sw bsel := selectors.NewExchangeBackup() - bsel.Include(bsel.MailFolders([]string{m365UserID}, []string{exchange.DefaultMailFolder})) + bsel.Include( + bsel.MailFolders([]string{m365UserID}, []string{exchange.DefaultMailFolder}), + bsel.ContactFolders([]string{m365UserID}, []string{exchange.DefaultContactFolder}), + bsel.EventCalendars([]string{m365UserID}, []string{exchange.DefaultCalendar}), + ) bo, err := NewBackupOperation( ctx,