SharePoint: Mock: Stream and Colleciton Mock Expansion (#1965)
## Description Mocks created for testing `SharePoint.List` restore operations <!-- Insert PR description--> ## Does this PR need a docs update or release note? - [x] ⛔ No ## Type of change <!--- Please check the type of change your PR introduces: ---> - [x] 💻 CI/Deployment - [x] 🐹 Trivial/Minor ## Issue(s) <!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. --> * related to #1935<issue> ## Test Plan <!-- How will this be tested prior to merging.--> - [x] 💪 Manual
This commit is contained in:
parent
c2eb796562
commit
43edf06db3
@ -1,16 +1,86 @@
|
||||
package mockconnector
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
kw "github.com/microsoft/kiota-serialization-json-go"
|
||||
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/alcionai/corso/src/internal/data"
|
||||
"github.com/alcionai/corso/src/pkg/path"
|
||||
)
|
||||
|
||||
var (
|
||||
_ data.Stream = &MockListData{}
|
||||
_ data.Collection = &MockListCollection{}
|
||||
)
|
||||
|
||||
type MockListCollection struct {
|
||||
fullPath path.Path
|
||||
Data []*MockListData
|
||||
Names []string
|
||||
}
|
||||
|
||||
func (mlc *MockListCollection) State() data.CollectionState {
|
||||
return data.NewState
|
||||
}
|
||||
|
||||
func (mlc *MockListCollection) FullPath() path.Path {
|
||||
return mlc.fullPath
|
||||
}
|
||||
|
||||
func (mlc *MockListCollection) DoNotMergeItems() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (mlc *MockListCollection) PreviousPath() path.Path {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mlc *MockListCollection) Items() <-chan data.Stream {
|
||||
res := make(chan data.Stream)
|
||||
|
||||
go func() {
|
||||
defer close(res)
|
||||
|
||||
for _, stream := range mlc.Data {
|
||||
res <- stream
|
||||
}
|
||||
}()
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
type MockListData struct {
|
||||
ID string
|
||||
Reader io.ReadCloser
|
||||
ReadErr error
|
||||
size int64
|
||||
deleted bool
|
||||
}
|
||||
|
||||
func (mld *MockListData) UUID() string {
|
||||
return mld.ID
|
||||
}
|
||||
|
||||
func (mld MockListData) Deleted() bool {
|
||||
return mld.deleted
|
||||
}
|
||||
|
||||
func (mld *MockListData) ToReader() io.ReadCloser {
|
||||
return mld.Reader
|
||||
}
|
||||
|
||||
// GetMockList returns a Listable object with generic
|
||||
// information.
|
||||
// Source: https://learn.microsoft.com/en-us/graph/api/list-create?view=graph-rest-1.0&tabs=go
|
||||
func GetMockList(title string) models.Listable {
|
||||
requestBody := models.NewList()
|
||||
requestBody.SetDisplayName(&title)
|
||||
requestBody.SetName(&title)
|
||||
|
||||
columnDef := models.NewColumnDefinition()
|
||||
name := "Author"
|
||||
@ -54,3 +124,18 @@ func GetMockListBytes(title string) ([]byte, error) {
|
||||
|
||||
return objectWriter.GetSerializedContent()
|
||||
}
|
||||
|
||||
// GetMockListStream returns the data.Stream representation
|
||||
// of the Mocked SharePoint List
|
||||
func GetMockListStream(t *testing.T, title string) *MockListData {
|
||||
byteArray, err := GetMockListBytes(title)
|
||||
require.NoError(t, err)
|
||||
|
||||
listData := &MockListData{
|
||||
ID: title,
|
||||
Reader: io.NopCloser(bytes.NewReader(byteArray)),
|
||||
size: int64(len(byteArray)),
|
||||
}
|
||||
|
||||
return listData
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user