Basic checks for bad/empty values for restore (#973)
## Description Test bad services or empty collections don't cause an error ## Type of change <!--- Please check the type of change your PR introduces: ---> - [ ] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [x] 🤖 Test - [ ] 💻 CI/Deployment - [ ] 🐹 Trivial/Minor ## Issue(s) * #913 ## Test Plan <!-- How will this be tested prior to merging.--> - [ ] 💪 Manual - [x] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
3c0179986b
commit
f0ff7ee982
@ -346,10 +346,15 @@ func (gc *GraphConnector) AwaitStatus() *support.ConnectorOperationStatus {
|
|||||||
|
|
||||||
// UpdateStatus is used by gc initiated tasks to indicate completion
|
// UpdateStatus is used by gc initiated tasks to indicate completion
|
||||||
func (gc *GraphConnector) UpdateStatus(status *support.ConnectorOperationStatus) {
|
func (gc *GraphConnector) UpdateStatus(status *support.ConnectorOperationStatus) {
|
||||||
|
defer gc.wg.Done()
|
||||||
|
|
||||||
|
if status == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
gc.mu.Lock()
|
gc.mu.Lock()
|
||||||
defer gc.mu.Unlock()
|
defer gc.mu.Unlock()
|
||||||
gc.status = support.MergeStatus(gc.status, *status)
|
gc.status = support.MergeStatus(gc.status, *status)
|
||||||
gc.wg.Done()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status returns the current status of the graphConnector operaion.
|
// Status returns the current status of the graphConnector operaion.
|
||||||
|
|||||||
@ -10,10 +10,13 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
|
"github.com/alcionai/corso/src/internal/common"
|
||||||
"github.com/alcionai/corso/src/internal/connector/support"
|
"github.com/alcionai/corso/src/internal/connector/support"
|
||||||
"github.com/alcionai/corso/src/internal/tester"
|
"github.com/alcionai/corso/src/internal/tester"
|
||||||
"github.com/alcionai/corso/src/pkg/account"
|
"github.com/alcionai/corso/src/pkg/account"
|
||||||
|
"github.com/alcionai/corso/src/pkg/control"
|
||||||
"github.com/alcionai/corso/src/pkg/credentials"
|
"github.com/alcionai/corso/src/pkg/credentials"
|
||||||
|
"github.com/alcionai/corso/src/pkg/selectors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
@ -172,3 +175,20 @@ func (suite *DisconnectedGraphConnectorSuite) TestGraphConnector_ErrorChecking()
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *DisconnectedGraphConnectorSuite) TestRestoreFailsBadService() {
|
||||||
|
t := suite.T()
|
||||||
|
ctx := context.Background()
|
||||||
|
gc := GraphConnector{wg: &sync.WaitGroup{}}
|
||||||
|
sel := selectors.Selector{
|
||||||
|
Service: selectors.ServiceUnknown,
|
||||||
|
}
|
||||||
|
dest := control.DefaultRestoreDestination(common.SimpleDateTimeFormatOneDrive)
|
||||||
|
|
||||||
|
assert.Error(t, gc.RestoreDataCollections(ctx, sel, dest, nil))
|
||||||
|
|
||||||
|
status := gc.AwaitStatus()
|
||||||
|
assert.Equal(t, 0, status.ObjectCount)
|
||||||
|
assert.Equal(t, 0, status.FolderCount)
|
||||||
|
assert.Equal(t, 0, status.Successful)
|
||||||
|
}
|
||||||
|
|||||||
@ -403,6 +403,58 @@ func (suite *GraphConnectorIntegrationSuite) TestRestoreContact() {
|
|||||||
suite.T().Log(value.String())
|
suite.T().Log(value.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *GraphConnectorIntegrationSuite) TestEmptyCollections() {
|
||||||
|
dest := control.DefaultRestoreDestination(common.SimpleDateTimeFormatOneDrive)
|
||||||
|
table := []struct {
|
||||||
|
name string
|
||||||
|
col []data.Collection
|
||||||
|
sel selectors.Selector
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "ExchangeNil",
|
||||||
|
col: nil,
|
||||||
|
sel: selectors.Selector{
|
||||||
|
Service: selectors.ServiceExchange,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ExchangeEmpty",
|
||||||
|
col: []data.Collection{},
|
||||||
|
sel: selectors.Selector{
|
||||||
|
Service: selectors.ServiceExchange,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "OneDriveNil",
|
||||||
|
col: nil,
|
||||||
|
sel: selectors.Selector{
|
||||||
|
Service: selectors.ServiceOneDrive,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "OneDriveEmpty",
|
||||||
|
col: []data.Collection{},
|
||||||
|
sel: selectors.Selector{
|
||||||
|
Service: selectors.ServiceOneDrive,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range table {
|
||||||
|
suite.T().Run(test.name, func(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
err := suite.connector.RestoreDataCollections(ctx, test.sel, dest, test.col)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
stats := suite.connector.AwaitStatus()
|
||||||
|
assert.Zero(t, stats.ObjectCount)
|
||||||
|
assert.Zero(t, stats.FolderCount)
|
||||||
|
assert.Zero(t, stats.Successful)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (suite *GraphConnectorIntegrationSuite) TestRestoreAndBackup() {
|
func (suite *GraphConnectorIntegrationSuite) TestRestoreAndBackup() {
|
||||||
bodyText := "This email has some text. However, all the text is on the same line."
|
bodyText := "This email has some text. However, all the text is on the same line."
|
||||||
subjectText := "Test message for restore"
|
subjectText := "Test message for restore"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user