GC: SharePoint: Helper function consolidation. (#1782)
## Description Move helper functions & test structs to `helper_test.go` <!-- Insert PR description--> ## Type of change - [x] 🐹 Trivial/Minor ## Test Plan - [x] ⚡ Unit test
This commit is contained in:
parent
84a781694c
commit
dd96a87611
@ -1,12 +1,10 @@
|
||||
package sharepoint_test
|
||||
package sharepoint
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
|
||||
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/alcionai/corso/src/internal/connector/onedrive"
|
||||
@ -15,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// consts, mocks
|
||||
// consts
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const (
|
||||
@ -34,20 +32,6 @@ func (fm testFolderMatcher) Matches(path string) bool {
|
||||
return fm.scope.Matches(selectors.SharePointLibrary, path)
|
||||
}
|
||||
|
||||
type MockGraphService struct{}
|
||||
|
||||
func (ms *MockGraphService) Client() *msgraphsdk.GraphServiceClient {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ms *MockGraphService) Adapter() *msgraphsdk.GraphRequestAdapter {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ms *MockGraphService) ErrPolicy() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// tests
|
||||
// ---------------------------------------------------------------------------
|
||||
@ -137,20 +121,3 @@ func driveItem(name string, path string, isFile bool) models.DriveItemable {
|
||||
|
||||
return item
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
func expectedPathAsSlice(t *testing.T, tenant, user string, rest ...string) []string {
|
||||
res := make([]string, 0, len(rest))
|
||||
|
||||
for _, r := range rest {
|
||||
p, err := onedrive.GetCanonicalPath(r, tenant, user, onedrive.SharePointSource)
|
||||
require.NoError(t, err)
|
||||
|
||||
res = append(res, p.String())
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
@ -1,13 +1,22 @@
|
||||
package sharepoint
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/alcionai/corso/src/internal/connector/graph"
|
||||
"github.com/alcionai/corso/src/internal/connector/onedrive"
|
||||
"github.com/alcionai/corso/src/pkg/account"
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SharePoint Test Services
|
||||
// ---------------------------------------------------------------------------
|
||||
type MockGraphService struct{}
|
||||
|
||||
type testService struct {
|
||||
client msgraphsdk.GraphServiceClient
|
||||
adapter msgraphsdk.GraphRequestAdapter
|
||||
@ -15,9 +24,21 @@ type testService struct {
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
// Functions to comply with graph.Service Interface
|
||||
// Interface Functions: @See graph.Service
|
||||
//------------------------------------------------------------
|
||||
|
||||
func (ms *MockGraphService) Client() *msgraphsdk.GraphServiceClient {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ms *MockGraphService) Adapter() *msgraphsdk.GraphRequestAdapter {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ms *MockGraphService) ErrPolicy() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (ts *testService) Client() *msgraphsdk.GraphServiceClient {
|
||||
return &ts.client
|
||||
}
|
||||
@ -30,6 +51,10 @@ func (ts *testService) ErrPolicy() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Helper Functions
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
func createTestService(credentials account.M365Config) (*testService, error) {
|
||||
{
|
||||
adapter, err := graph.CreateAdapter(
|
||||
@ -50,3 +75,16 @@ func createTestService(credentials account.M365Config) (*testService, error) {
|
||||
return &service, nil
|
||||
}
|
||||
}
|
||||
|
||||
func expectedPathAsSlice(t *testing.T, tenant, user string, rest ...string) []string {
|
||||
res := make([]string, 0, len(rest))
|
||||
|
||||
for _, r := range rest {
|
||||
p, err := onedrive.GetCanonicalPath(r, tenant, user, onedrive.SharePointSource)
|
||||
require.NoError(t, err)
|
||||
|
||||
res = append(res, p.String())
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user