OneDrive restore/backup test (#1173)
## Description GraphConnector test for OneDrive backup and restore. Tests the following: * restore properly builds the hierarchy for items * items in folders that have the same name restore properly * backup properly selects subfolders * backup separates folders with same name in different parts of hierarchy * input data == backup(restore(input data)) ## 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
1f0338a80d
commit
86c2f2c284
9
.github/workflows/ci.yml
vendored
9
.github/workflows/ci.yml
vendored
@ -178,10 +178,11 @@ jobs:
|
|||||||
CORSO_PASSPHRASE: ${{ secrets.INTEGRATION_TEST_CORSO_PASSPHRASE }}
|
CORSO_PASSPHRASE: ${{ secrets.INTEGRATION_TEST_CORSO_PASSPHRASE }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
go test \
|
go test \
|
||||||
-json \
|
-tags testing \
|
||||||
-v \
|
-json \
|
||||||
-failfast \
|
-v \
|
||||||
|
-failfast \
|
||||||
./... 2>&1 | tee ./testlog/gotest.log | gotestfmt -hide successful-tests
|
./... 2>&1 | tee ./testlog/gotest.log | gotestfmt -hide successful-tests
|
||||||
|
|
||||||
# Upload the original go test log as an artifact for later review.
|
# Upload the original go test log as an artifact for later review.
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
run:
|
run:
|
||||||
timeout: 15m
|
timeout: 15m
|
||||||
|
build-tags:
|
||||||
|
- testing
|
||||||
|
|
||||||
linters:
|
linters:
|
||||||
enable:
|
enable:
|
||||||
|
|||||||
@ -603,6 +603,27 @@ func compareExchangeEvent(
|
|||||||
checkEvent(t, expectedEvent, itemEvent)
|
checkEvent(t, expectedEvent, itemEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func compareOneDriveItem(
|
||||||
|
t *testing.T,
|
||||||
|
expected map[string][]byte,
|
||||||
|
item data.Stream,
|
||||||
|
) {
|
||||||
|
expectedData := expected[item.UUID()]
|
||||||
|
if !assert.NotNil(t, expectedData, "unexpected file with name %s", item.UUID) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// OneDrive items are just byte buffers of the data. Nothing special to
|
||||||
|
// interpret. May need to do chunked comparisons in the future if we test
|
||||||
|
// large item equality.
|
||||||
|
buf, err := io.ReadAll(item.ToReader())
|
||||||
|
if !assert.NoError(t, err) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, expectedData, buf)
|
||||||
|
}
|
||||||
|
|
||||||
func compareItem(
|
func compareItem(
|
||||||
t *testing.T,
|
t *testing.T,
|
||||||
expected map[string][]byte,
|
expected map[string][]byte,
|
||||||
@ -622,6 +643,10 @@ func compareItem(
|
|||||||
default:
|
default:
|
||||||
assert.FailNowf(t, "unexpected Exchange category: %s", category.String())
|
assert.FailNowf(t, "unexpected Exchange category: %s", category.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case path.OneDriveService:
|
||||||
|
compareOneDriveItem(t, expected, item)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
assert.FailNowf(t, "unexpected service: %s", service.String())
|
assert.FailNowf(t, "unexpected service: %s", service.String())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,14 +1,19 @@
|
|||||||
package connector
|
package connector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
|
"github.com/alcionai/corso/src/internal/connector/graph"
|
||||||
"github.com/alcionai/corso/src/internal/connector/mockconnector"
|
"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/data"
|
||||||
"github.com/alcionai/corso/src/internal/tester"
|
"github.com/alcionai/corso/src/internal/tester"
|
||||||
"github.com/alcionai/corso/src/pkg/path"
|
"github.com/alcionai/corso/src/pkg/path"
|
||||||
@ -149,6 +154,31 @@ func (suite *GraphConnectorIntegrationSuite) TestEmptyCollections() {
|
|||||||
// Exchange Functions
|
// Exchange Functions
|
||||||
//-------------------------------------------------------------
|
//-------------------------------------------------------------
|
||||||
|
|
||||||
|
//revive:disable:context-as-argument
|
||||||
|
func mustGetDefaultDriveID(
|
||||||
|
t *testing.T,
|
||||||
|
ctx context.Context,
|
||||||
|
service graph.Service,
|
||||||
|
userID string,
|
||||||
|
) string {
|
||||||
|
//revive:enable:context-as-argument
|
||||||
|
d, err := service.Client().UsersById(userID).Drive().Get(ctx, nil)
|
||||||
|
if err != nil {
|
||||||
|
err = errors.Wrapf(
|
||||||
|
err,
|
||||||
|
"failed to retrieve default user drive. user: %s, details: %s",
|
||||||
|
userID,
|
||||||
|
support.ConnectorStackErrorTrace(err),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, d.GetId())
|
||||||
|
require.NotEmpty(t, *d.GetId())
|
||||||
|
|
||||||
|
return *d.GetId()
|
||||||
|
}
|
||||||
|
|
||||||
func runRestoreBackupTest(
|
func runRestoreBackupTest(
|
||||||
t *testing.T,
|
t *testing.T,
|
||||||
test restoreBackupInfo,
|
test restoreBackupInfo,
|
||||||
@ -249,6 +279,17 @@ 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"
|
||||||
|
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
|
// Get the default drive ID for the test user.
|
||||||
|
driveID := mustGetDefaultDriveID(
|
||||||
|
suite.T(),
|
||||||
|
ctx,
|
||||||
|
suite.connector.Service(),
|
||||||
|
suite.user,
|
||||||
|
)
|
||||||
|
|
||||||
table := []restoreBackupInfo{
|
table := []restoreBackupInfo{
|
||||||
{
|
{
|
||||||
name: "EmailsWithAttachments",
|
name: "EmailsWithAttachments",
|
||||||
@ -465,6 +506,95 @@ func (suite *GraphConnectorIntegrationSuite) TestRestoreAndBackup() {
|
|||||||
// },
|
// },
|
||||||
// },
|
// },
|
||||||
// },
|
// },
|
||||||
|
{
|
||||||
|
name: "OneDriveMultipleFoldersAndFiles",
|
||||||
|
service: path.OneDriveService,
|
||||||
|
resource: Users,
|
||||||
|
collections: []colInfo{
|
||||||
|
{
|
||||||
|
pathElements: []string{
|
||||||
|
"drives",
|
||||||
|
driveID,
|
||||||
|
"root:",
|
||||||
|
},
|
||||||
|
category: path.FilesCategory,
|
||||||
|
items: []itemInfo{
|
||||||
|
{
|
||||||
|
name: "test-file.txt",
|
||||||
|
data: []byte(strings.Repeat("a", 33)),
|
||||||
|
lookupKey: "test-file.txt",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pathElements: []string{
|
||||||
|
"drives",
|
||||||
|
driveID,
|
||||||
|
"root:",
|
||||||
|
"folder-a",
|
||||||
|
},
|
||||||
|
category: path.FilesCategory,
|
||||||
|
items: []itemInfo{
|
||||||
|
{
|
||||||
|
name: "test-file.txt",
|
||||||
|
data: []byte(strings.Repeat("b", 65)),
|
||||||
|
lookupKey: "test-file.txt",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pathElements: []string{
|
||||||
|
"drives",
|
||||||
|
driveID,
|
||||||
|
"root:",
|
||||||
|
"folder-a",
|
||||||
|
"b",
|
||||||
|
},
|
||||||
|
category: path.FilesCategory,
|
||||||
|
items: []itemInfo{
|
||||||
|
{
|
||||||
|
name: "test-file.txt",
|
||||||
|
data: []byte(strings.Repeat("c", 129)),
|
||||||
|
lookupKey: "test-file.txt",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pathElements: []string{
|
||||||
|
"drives",
|
||||||
|
driveID,
|
||||||
|
"root:",
|
||||||
|
"folder-a",
|
||||||
|
"b",
|
||||||
|
"folder-a",
|
||||||
|
},
|
||||||
|
category: path.FilesCategory,
|
||||||
|
items: []itemInfo{
|
||||||
|
{
|
||||||
|
name: "test-file.txt",
|
||||||
|
data: []byte(strings.Repeat("d", 257)),
|
||||||
|
lookupKey: "test-file.txt",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pathElements: []string{
|
||||||
|
"drives",
|
||||||
|
driveID,
|
||||||
|
"root:",
|
||||||
|
"b",
|
||||||
|
},
|
||||||
|
category: path.FilesCategory,
|
||||||
|
items: []itemInfo{
|
||||||
|
{
|
||||||
|
name: "test-file.txt",
|
||||||
|
data: []byte(strings.Repeat("e", 257)),
|
||||||
|
lookupKey: "test-file.txt",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range table {
|
for _, test := range table {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user