diff --git a/src/internal/connector/mockconnector/mock_data_collection.go b/src/internal/connector/mockconnector/mock_data_collection.go index b8086b93e..568f09cde 100644 --- a/src/internal/connector/mockconnector/mock_data_collection.go +++ b/src/internal/connector/mockconnector/mock_data_collection.go @@ -26,6 +26,7 @@ var ( _ data.Collection = &MockExchangeDataCollection{} _ data.Stream = &MockExchangeData{} _ data.StreamInfo = &MockExchangeData{} + _ data.StreamSize = &MockExchangeData{} ) // NewMockExchangeDataCollection creates an data collection that will return the specified number of @@ -63,6 +64,7 @@ func (medc *MockExchangeDataCollection) Items() <-chan data.Stream { res <- &MockExchangeData{ ID: medc.Names[i], Reader: io.NopCloser(bytes.NewReader(medc.Data[i])), + size: int64(len(medc.Data[i])), } } }() @@ -75,6 +77,7 @@ type MockExchangeData struct { ID string Reader io.ReadCloser ReadErr error + size int64 } func (med *MockExchangeData) UUID() string { @@ -99,6 +102,10 @@ func (med *MockExchangeData) Info() details.ItemInfo { } } +func (med *MockExchangeData) Size() int64 { + return med.size +} + // GetMockMessageBytes returns bytes for Messageable item. // Contents verified as working with sample data from kiota-serialization-json-go v0.5.5 func GetMockMessageBytes(subject string) []byte { diff --git a/src/internal/connector/mockconnector/mock_data_collection_test.go b/src/internal/connector/mockconnector/mock_data_collection_test.go index c13990432..013763ea2 100644 --- a/src/internal/connector/mockconnector/mock_data_collection_test.go +++ b/src/internal/connector/mockconnector/mock_data_collection_test.go @@ -13,6 +13,7 @@ import ( "github.com/alcionai/corso/src/internal/connector/mockconnector" "github.com/alcionai/corso/src/internal/connector/support" + "github.com/alcionai/corso/src/internal/data" ) type MockExchangeCollectionSuite struct { @@ -37,6 +38,22 @@ func (suite *MockExchangeCollectionSuite) TestMockExchangeCollection() { assert.Equal(suite.T(), 2, messagesRead) } +func (suite *MockExchangeCollectionSuite) TestMockExchangeCollectionItemSize() { + t := suite.T() + mdc := mockconnector.NewMockExchangeCollection(nil, 2) + + mdc.Data[1] = []byte("This is some buffer of data so that the size is different than the default") + + for item := range mdc.Items() { + buf, err := ioutil.ReadAll(item.ToReader()) + assert.NoError(t, err) + + assert.Implements(t, (*data.StreamSize)(nil), item) + s := item.(data.StreamSize) + assert.Equal(t, int64(len(buf)), s.Size()) + } +} + // NewExchangeCollectionMail_Hydration tests that mock exchange mail data collection can be used for restoration // functions by verifying no failures on (de)serializing steps using kiota serialization library func (suite *MockExchangeCollectionSuite) TestMockExchangeCollection_NewExchangeCollectionMail_Hydration() { @@ -64,7 +81,7 @@ func TestMockExchangeDataSuite(t *testing.T) { } func (suite *MockExchangeDataSuite) TestMockExchangeData() { - data := []byte("foo") + itemData := []byte("foo") id := "bar" table := []struct { @@ -76,7 +93,7 @@ func (suite *MockExchangeDataSuite) TestMockExchangeData() { name: "NoError", reader: &mockconnector.MockExchangeData{ ID: id, - Reader: io.NopCloser(bytes.NewReader(data)), + Reader: io.NopCloser(bytes.NewReader(itemData)), }, check: require.NoError, }, @@ -100,7 +117,7 @@ func (suite *MockExchangeDataSuite) TestMockExchangeData() { return } - assert.Equal(t, data, buf) + assert.Equal(t, itemData, buf) }) } }