Sanity tests for SharePoint export (#3928)
This extends the existing export sanity tests to also cover SharePoint exports. <!-- PR description--> --- #### 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 - [ ] 🤖 Supportability/Tests - [ ] 💻 CI/Deployment - [x] 🧹 Tech Debt/Cleanup #### Issue(s) <!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. --> * closes https://github.com/alcionai/corso/issues/3889 #### Test Plan <!-- How will this be tested prior to merging.--> - [ ] 💪 Manual - [ ] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
2596fb9104
commit
5751163572
@ -89,7 +89,7 @@ runs:
|
|||||||
id: export
|
id: export
|
||||||
shell: bash
|
shell: bash
|
||||||
working-directory: src
|
working-directory: src
|
||||||
if: ${{ inputs.service == 'onedrive' }} # Export only available for OneDrive
|
if: ${{ inputs.service == 'onedrive' || inputs.service == 'sharepoint' }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
CORSO_LOG_FILE=${{ inputs.log-dir }}/gotest-restore-${{ inputs.service }}-${{inputs.kind }}.log
|
CORSO_LOG_FILE=${{ inputs.log-dir }}/gotest-restore-${{ inputs.service }}-${{inputs.kind }}.log
|
||||||
@ -105,7 +105,7 @@ runs:
|
|||||||
- name: Check export ${{ inputs.service }} ${{ inputs.kind }}
|
- name: Check export ${{ inputs.service }} ${{ inputs.kind }}
|
||||||
shell: bash
|
shell: bash
|
||||||
working-directory: src
|
working-directory: src
|
||||||
if: ${{ inputs.service == 'onedrive' }}
|
if: ${{ inputs.service == 'onedrive' || inputs.service == 'sharepoint' }}
|
||||||
env:
|
env:
|
||||||
SANITY_TEST_KIND: export
|
SANITY_TEST_KIND: export
|
||||||
SANITY_TEST_FOLDER: /tmp/export-${{ inputs.service }}-${{inputs.kind }}
|
SANITY_TEST_FOLDER: /tmp/export-${{ inputs.service }}-${{inputs.kind }}
|
||||||
|
|||||||
88
src/cmd/sanity_test/export/sharepoint.go
Normal file
88
src/cmd/sanity_test/export/sharepoint.go
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
package export
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/alcionai/clues"
|
||||||
|
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
|
||||||
|
|
||||||
|
"github.com/alcionai/corso/src/cmd/sanity_test/common"
|
||||||
|
"github.com/alcionai/corso/src/cmd/sanity_test/restore"
|
||||||
|
"github.com/alcionai/corso/src/internal/common/ptr"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CheckSharePointExport(
|
||||||
|
ctx context.Context,
|
||||||
|
client *msgraphsdk.GraphServiceClient,
|
||||||
|
siteID, folderName, dataFolder string,
|
||||||
|
) {
|
||||||
|
drive, err := client.
|
||||||
|
Sites().
|
||||||
|
BySiteId(siteID).
|
||||||
|
Drive().
|
||||||
|
Get(ctx, nil)
|
||||||
|
if err != nil {
|
||||||
|
common.Fatal(ctx, "getting the drive:", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// map itemID -> item size
|
||||||
|
var (
|
||||||
|
fileSizes = make(map[string]int64)
|
||||||
|
exportFileSizes = make(map[string]int64)
|
||||||
|
startTime = time.Now()
|
||||||
|
)
|
||||||
|
|
||||||
|
err = filepath.Walk(folderName, func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return clues.Stack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if info.IsDir() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
relPath, err := filepath.Rel(folderName, path)
|
||||||
|
if err != nil {
|
||||||
|
return clues.Stack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
exportFileSizes[relPath] = info.Size()
|
||||||
|
if startTime.After(info.ModTime()) {
|
||||||
|
startTime = info.ModTime()
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error walking the path:", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = restore.PopulateDriveDetails(
|
||||||
|
ctx,
|
||||||
|
client,
|
||||||
|
ptr.Val(drive.GetId()),
|
||||||
|
folderName,
|
||||||
|
dataFolder,
|
||||||
|
fileSizes,
|
||||||
|
map[string][]common.PermissionInfo{},
|
||||||
|
startTime)
|
||||||
|
|
||||||
|
for fileName, expected := range fileSizes {
|
||||||
|
common.LogAndPrint(ctx, "checking for file: %s", fileName)
|
||||||
|
|
||||||
|
got := exportFileSizes[fileName]
|
||||||
|
|
||||||
|
common.Assert(
|
||||||
|
ctx,
|
||||||
|
func() bool { return expected == got },
|
||||||
|
fmt.Sprintf("different file size: %s", fileName),
|
||||||
|
expected,
|
||||||
|
got)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("Success")
|
||||||
|
}
|
||||||
@ -77,6 +77,8 @@ func main() {
|
|||||||
switch testService {
|
switch testService {
|
||||||
case "onedrive":
|
case "onedrive":
|
||||||
export.CheckOneDriveExport(ctx, client, testUser, folder, dataFolder)
|
export.CheckOneDriveExport(ctx, client, testUser, folder, dataFolder)
|
||||||
|
case "sharepoint":
|
||||||
|
export.CheckSharePointExport(ctx, client, testSite, folder, dataFolder)
|
||||||
default:
|
default:
|
||||||
common.Fatal(ctx, "unknown service for export sanity tests", nil)
|
common.Fatal(ctx, "unknown service for export sanity tests", nil)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user