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:
Danny 2022-12-12 13:14:37 -07:00 committed by GitHub
parent 84a781694c
commit dd96a87611
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 36 deletions

View File

@ -1,12 +1,10 @@
package sharepoint_test package sharepoint
import ( import (
"testing" "testing"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
"github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/microsoftgraph/msgraph-sdk-go/models"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/alcionai/corso/src/internal/connector/onedrive" "github.com/alcionai/corso/src/internal/connector/onedrive"
@ -15,7 +13,7 @@ import (
) )
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// consts, mocks // consts
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
const ( const (
@ -34,20 +32,6 @@ func (fm testFolderMatcher) Matches(path string) bool {
return fm.scope.Matches(selectors.SharePointLibrary, path) 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 // tests
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -137,20 +121,3 @@ func driveItem(name string, path string, isFile bool) models.DriveItemable {
return item 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
}

View File

@ -1,13 +1,22 @@
package sharepoint package sharepoint
import ( import (
"testing"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go" msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/require"
"github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/graph"
"github.com/alcionai/corso/src/internal/connector/onedrive"
"github.com/alcionai/corso/src/pkg/account" "github.com/alcionai/corso/src/pkg/account"
) )
// ---------------------------------------------------------------------------
// SharePoint Test Services
// ---------------------------------------------------------------------------
type MockGraphService struct{}
type testService struct { type testService struct {
client msgraphsdk.GraphServiceClient client msgraphsdk.GraphServiceClient
adapter msgraphsdk.GraphRequestAdapter 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 { func (ts *testService) Client() *msgraphsdk.GraphServiceClient {
return &ts.client return &ts.client
} }
@ -30,6 +51,10 @@ func (ts *testService) ErrPolicy() bool {
return false return false
} }
// ---------------------------------------------------------------------------
// Helper Functions
// ---------------------------------------------------------------------------
func createTestService(credentials account.M365Config) (*testService, error) { func createTestService(credentials account.M365Config) (*testService, error) {
{ {
adapter, err := graph.CreateAdapter( adapter, err := graph.CreateAdapter(
@ -50,3 +75,16 @@ func createTestService(credentials account.M365Config) (*testService, error) {
return &service, nil 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
}