Compare commits

...

15 Commits

Author SHA1 Message Date
Danny Adams
4daa86fcc7 Merge branch 'main' into serialize-common 2023-01-18 16:17:22 -05:00
Danny
c0e1b3db7e
Merge branch 'main' into serialize-common 2023-01-10 18:53:26 -05:00
Danny Adams
a1e1ebb5c3 Mock Service added back to test. 2023-01-10 18:52:19 -05:00
Danny Adams
91f2556e4c removal of type identification. 2023-01-10 18:47:06 -05:00
Danny Adams
5ac97ec856 GOFMT: Added defer clause for writer.Close(). 2023-01-06 16:57:25 -05:00
Danny Adams
d2b7ac0d0c Merge branch 'main' into serialize-common 2023-01-06 16:32:39 -05:00
Danny Adams
9ab2d96451 Interface updated. MockGraphService struct removed from the helper_test.go 2023-01-06 16:18:56 -05:00
Danny Adams
886015126a Updates to add interface to onedrive package. 2023-01-06 16:13:44 -05:00
Danny Adams
dd42105b3e Interface updated to use servicer. 2023-01-06 16:11:44 -05:00
Danny Adams
8a919ead95 Move Serialize function to interface. 2023-01-06 16:06:10 -05:00
Danny Adams
5f3d9266a3 Update for comments. 2023-01-06 10:00:47 -05:00
Danny Adams
6dedf1807c Conversion change. 2023-01-06 09:55:03 -05:00
Danny Adams
105314d379 Refactor of serialization function applied to getItem.go 2023-01-06 09:54:42 -05:00
Danny Adams
d331ad8ecf Update to use internal fields rather than creating additional objects. 2023-01-06 09:38:26 -05:00
Danny Adams
9a872fd388 added defer to call to prevent failure. 2023-01-06 09:37:40 -05:00
7 changed files with 51 additions and 22 deletions

View File

@ -20,6 +20,7 @@ import (
"github.com/alcionai/corso/src/internal/connector" "github.com/alcionai/corso/src/internal/connector"
"github.com/alcionai/corso/src/internal/connector/exchange/api" "github.com/alcionai/corso/src/internal/connector/exchange/api"
"github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/graph"
"github.com/alcionai/corso/src/internal/connector/support"
"github.com/alcionai/corso/src/pkg/account" "github.com/alcionai/corso/src/pkg/account"
"github.com/alcionai/corso/src/pkg/backup/details" "github.com/alcionai/corso/src/pkg/backup/details"
"github.com/alcionai/corso/src/pkg/credentials" "github.com/alcionai/corso/src/pkg/credentials"
@ -117,7 +118,7 @@ func runDisplayM365JSON(
} }
if err != nil { if err != nil {
return err return errors.Wrap(err, support.ConnectorStackErrorTrace(err))
} }
str := string(bs) str := string(bs)

View File

@ -7,6 +7,7 @@ import (
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go" msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/alcionai/corso/src/internal/connector/support"
"github.com/alcionai/corso/src/pkg/account" "github.com/alcionai/corso/src/pkg/account"
"github.com/alcionai/corso/src/pkg/path" "github.com/alcionai/corso/src/pkg/path"
) )
@ -45,10 +46,15 @@ func (s Service) Client() *msgraphsdk.GraphServiceClient {
return s.client return s.client
} }
// Seraialize writes an M365 parsable object into a byte array using the built-in
// application/json writer within the adapter.
func (s Service) Serialize(object absser.Parsable) ([]byte, error) { func (s Service) Serialize(object absser.Parsable) ([]byte, error) {
writer, err := s.adapter.GetSerializationWriterFactory().GetSerializationWriter("application/json") writer, err := s.adapter.GetSerializationWriterFactory().GetSerializationWriter("application/json")
defer func() {
writerErr := writer.Close()
if writerErr != nil {
err = support.WrapAndAppend("failure during writer closer", writerErr, err)
}
}()
if err != nil || writer == nil { if err != nil || writer == nil {
return nil, errors.Wrap(err, "creating json serialization writer") return nil, errors.Wrap(err, "creating json serialization writer")
} }
@ -68,6 +74,10 @@ type Servicer interface {
// Adapter() returns GraphRequest adapter used to process large requests, create batches // Adapter() returns GraphRequest adapter used to process large requests, create batches
// and page iterators // and page iterators
Adapter() *msgraphsdk.GraphRequestAdapter Adapter() *msgraphsdk.GraphRequestAdapter
// Seraialize writes an M365 parsable object into a byte array using the built-in
// application/json writer within the adapter.
Serialize(object absser.Parsable) ([]byte, error)
} }
// Idable represents objects that implement msgraph-sdk-go/models.entityable // Idable represents objects that implement msgraph-sdk-go/models.entityable

View File

@ -9,6 +9,7 @@ import (
"testing" "testing"
"time" "time"
absser "github.com/microsoft/kiota-abstractions-go/serialization"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go" 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"
@ -37,6 +38,10 @@ func (suite *CollectionUnitTestSuite) Adapter() *msgraphsdk.GraphRequestAdapter
return nil return nil
} }
func (suite *CollectionUnitTestSuite) Serialize(object absser.Parsable) ([]byte, error) {
return nil, nil
}
func TestCollectionUnitTestSuite(t *testing.T) { func TestCollectionUnitTestSuite(t *testing.T) {
suite.Run(t, new(CollectionUnitTestSuite)) suite.Run(t, new(CollectionUnitTestSuite))
} }

View File

@ -6,6 +6,7 @@ import (
"io" "io"
"testing" "testing"
absser "github.com/microsoft/kiota-abstractions-go/serialization"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go" 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/require" "github.com/stretchr/testify/require"
@ -34,6 +35,10 @@ func (suite *ItemIntegrationSuite) Adapter() *msgraphsdk.GraphRequestAdapter {
return suite.adapter return suite.adapter
} }
func (suite *ItemIntegrationSuite) Serialize(object absser.Parsable) ([]byte, error) {
return nil, nil
}
func TestItemIntegrationSuite(t *testing.T) { func TestItemIntegrationSuite(t *testing.T) {
tester.RunOnAny( tester.RunOnAny(
t, t,

View File

@ -3,6 +3,7 @@ package onedrive
import ( import (
"testing" "testing"
absser "github.com/microsoft/kiota-abstractions-go/serialization"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go" msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -22,6 +23,10 @@ func (ms *MockGraphService) Adapter() *msgraphsdk.GraphRequestAdapter {
return nil return nil
} }
func (ms *MockGraphService) Serialize(object absser.Parsable) ([]byte, error) {
return nil, nil
}
// TODO(ashmrtn): Merge with similar structs in graph and exchange packages. // TODO(ashmrtn): Merge with similar structs in graph and exchange packages.
type oneDriveService struct { type oneDriveService struct {
client msgraphsdk.GraphServiceClient client msgraphsdk.GraphServiceClient
@ -38,6 +43,10 @@ func (ods *oneDriveService) Adapter() *msgraphsdk.GraphRequestAdapter {
return &ods.adapter return &ods.adapter
} }
func (ods *oneDriveService) Serialize(object absser.Parsable) ([]byte, error) {
return nil, nil
}
func NewOneDriveService(credentials account.M365Config) (*oneDriveService, error) { func NewOneDriveService(credentials account.M365Config) (*oneDriveService, error) {
adapter, err := graph.CreateAdapter( adapter, err := graph.CreateAdapter(
credentials.AzureTenantID, credentials.AzureTenantID,

View File

@ -3,6 +3,8 @@ package sharepoint
import ( import (
"testing" "testing"
absser "github.com/microsoft/kiota-abstractions-go/serialization"
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/suite" "github.com/stretchr/testify/suite"
@ -39,6 +41,21 @@ func (fm testFolderMatcher) Matches(path string) bool {
type SharePointLibrariesSuite struct { type SharePointLibrariesSuite struct {
suite.Suite suite.Suite
mockService mockServicer
}
type mockServicer struct{}
func (mock mockServicer) Client() *msgraphsdk.GraphServiceClient {
return nil
}
func (mock mockServicer) Adapter() *msgraphsdk.GraphRequestAdapter {
return nil
}
func (mock mockServicer) Serialize(object absser.Parsable) ([]byte, error) {
return nil, nil
} }
func TestSharePointLibrariesSuite(t *testing.T) { func TestSharePointLibrariesSuite(t *testing.T) {
@ -93,7 +110,7 @@ func (suite *SharePointLibrariesSuite) TestUpdateCollections() {
site, site,
onedrive.SharePointSource, onedrive.SharePointSource,
testFolderMatcher{test.scope}, testFolderMatcher{test.scope},
&MockGraphService{}, suite.mockService,
nil, nil,
control.Options{}) control.Options{})
err := c.UpdateCollections(ctx, "driveID", test.items, paths) err := c.UpdateCollections(ctx, "driveID", test.items, paths)

View File

@ -3,7 +3,6 @@ package sharepoint
import ( import (
"testing" "testing"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -12,23 +11,6 @@ import (
"github.com/alcionai/corso/src/pkg/account" "github.com/alcionai/corso/src/pkg/account"
) )
// ---------------------------------------------------------------------------
// SharePoint Test Services
// ---------------------------------------------------------------------------
type MockGraphService struct{}
//------------------------------------------------------------
// Interface Functions: @See graph.Service
//------------------------------------------------------------
func (ms *MockGraphService) Client() *msgraphsdk.GraphServiceClient {
return nil
}
func (ms *MockGraphService) Adapter() *msgraphsdk.GraphRequestAdapter {
return nil
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Helper Functions // Helper Functions
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------