Add tests which were rolled back with 4456 (#4459)
<!-- PR description--> Recent PR #4456 rolled back some of newer test additions. This PR reintroduces these tests. --- #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [ ] 🕐 Yes, but in a later PR - [x] ⛔ No #### Type of change <!--- Please check the type of change your PR introduces: ---> - [ ] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [x] 🤖 Supportability/Tests - [ ] 💻 CI/Deployment - [ ] 🧹 Tech Debt/Cleanup #### Issue(s) <!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. --> * #<issue> #### Test Plan <!-- How will this be tested prior to merging.--> - [x] 💪 Manual - [ ] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
f3dfa1e46b
commit
d7b24f37ab
@ -16,11 +16,13 @@ import (
|
||||
|
||||
"github.com/alcionai/corso/src/internal/common/dttm"
|
||||
"github.com/alcionai/corso/src/internal/common/ptr"
|
||||
"github.com/alcionai/corso/src/internal/common/str"
|
||||
"github.com/alcionai/corso/src/internal/m365/graph"
|
||||
"github.com/alcionai/corso/src/internal/tester"
|
||||
"github.com/alcionai/corso/src/internal/tester/tconfig"
|
||||
"github.com/alcionai/corso/src/pkg/control"
|
||||
"github.com/alcionai/corso/src/pkg/control/testdata"
|
||||
"github.com/alcionai/corso/src/pkg/selectors"
|
||||
"github.com/alcionai/corso/src/pkg/services/m365/api"
|
||||
)
|
||||
|
||||
@ -61,6 +63,106 @@ func (suite *ItemIntegrationSuite) SetupSuite() {
|
||||
suite.userDriveID = ptr.Val(odDrives[0].GetId())
|
||||
}
|
||||
|
||||
func getOneDriveItem(
|
||||
ctx context.Context,
|
||||
t *testing.T,
|
||||
ac api.Client,
|
||||
driveID string,
|
||||
) models.DriveItemable {
|
||||
pager := ac.Drives().EnumerateDriveItemsDelta(
|
||||
ctx,
|
||||
driveID,
|
||||
"",
|
||||
api.CallConfig{
|
||||
Select: api.DefaultDriveItemProps(),
|
||||
})
|
||||
|
||||
// Get a file item
|
||||
for page, _, done := pager.NextPage(); !done; page, _, done = pager.NextPage() {
|
||||
for _, item := range page {
|
||||
if item.GetFile() != nil {
|
||||
return item
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// TestItemReader is an integration test that makes a few assumptions
|
||||
// about the test environment
|
||||
// 1) It assumes the test user has a drive
|
||||
// 2) It assumes the drive has a file it can use to test `driveItemReader`
|
||||
// The test checks these in below
|
||||
func (suite *ItemIntegrationSuite) TestItemReader_oneDrive() {
|
||||
t := suite.T()
|
||||
|
||||
ctx, flush := tester.NewContext(t)
|
||||
defer flush()
|
||||
|
||||
sc := selectors.
|
||||
NewOneDriveBackup([]string{suite.user}).
|
||||
AllData()[0]
|
||||
|
||||
driveItem := getOneDriveItem(ctx, t, suite.service.ac, suite.userDriveID)
|
||||
// Test Requirement 2: Need a file
|
||||
require.NotEmpty(
|
||||
t,
|
||||
driveItem,
|
||||
"no file item found for user %s drive %s",
|
||||
suite.user,
|
||||
suite.userDriveID)
|
||||
|
||||
bh := &userDriveBackupHandler{
|
||||
baseUserDriveHandler: baseUserDriveHandler{
|
||||
ac: suite.service.ac.Drives(),
|
||||
},
|
||||
userID: suite.user,
|
||||
scope: sc,
|
||||
}
|
||||
|
||||
// Read data for the file
|
||||
itemData, err := downloadItem(ctx, bh, driveItem)
|
||||
require.NoError(t, err, clues.ToCore(err))
|
||||
|
||||
size, err := io.Copy(io.Discard, itemData)
|
||||
require.NoError(t, err, clues.ToCore(err))
|
||||
require.NotZero(t, size)
|
||||
}
|
||||
|
||||
// In prod we consider any errors in isURLExpired as non-fatal and carry on
|
||||
// with the download. This is a regression test to make sure we keep track
|
||||
// of any graph changes to the download url scheme, including how graph
|
||||
// embeds the jwt token.
|
||||
func (suite *ItemIntegrationSuite) TestIsURLExpired() {
|
||||
t := suite.T()
|
||||
|
||||
ctx, flush := tester.NewContext(t)
|
||||
defer flush()
|
||||
|
||||
driveItem := getOneDriveItem(ctx, t, suite.service.ac, suite.userDriveID)
|
||||
require.NotEmpty(
|
||||
t,
|
||||
driveItem,
|
||||
"no file item found for user %s drive %s",
|
||||
suite.user,
|
||||
suite.userDriveID)
|
||||
|
||||
var url string
|
||||
|
||||
for _, key := range downloadURLKeys {
|
||||
if v, err := str.AnyValueToString(key, driveItem.GetAdditionalData()); err == nil {
|
||||
url = v
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
expired, err := isURLExpired(ctx, url)
|
||||
require.NoError(t, err, clues.ToCore(err))
|
||||
|
||||
require.False(t, expired)
|
||||
}
|
||||
|
||||
// TestItemWriter is an integration test for uploading data to OneDrive
|
||||
// It creates a new folder with a new item and writes data to it
|
||||
func (suite *ItemIntegrationSuite) TestItemWriter() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user