diff --git a/src/internal/data/data_collection.go b/src/internal/data/data_collection.go index 0e3d492e0..8f5fb67cf 100644 --- a/src/internal/data/data_collection.go +++ b/src/internal/data/data_collection.go @@ -86,38 +86,3 @@ type StreamSize interface { type StreamModTime interface { ModTime() time.Time } - -// ------------------------------------------------------------------------------------------------ -// functionality -// ------------------------------------------------------------------------------------------------ - -// ResourceOwnerSet extracts the set of unique resource owners from the -// slice of Collections. -func ResourceOwnerSet(cs []Collection) []string { - rs := map[string]struct{}{} - - for _, c := range cs { - fp := c.FullPath() - if fp == nil { - // Deleted collections have their full path set to nil but the previous - // path will be populated. - fp = c.PreviousPath() - } - - if fp == nil { - // This should not happen, but keep us from hitting a nil pointer - // exception if it does somehow occur. Statistics will be off though. - continue - } - - rs[fp.ResourceOwner()] = struct{}{} - } - - rss := make([]string, 0, len(rs)) - - for k := range rs { - rss = append(rss, k) - } - - return rss -} diff --git a/src/internal/data/data_collection_test.go b/src/internal/data/data_collection_test.go deleted file mode 100644 index 82e34a79c..000000000 --- a/src/internal/data/data_collection_test.go +++ /dev/null @@ -1,98 +0,0 @@ -package data - -import ( - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" - - "github.com/alcionai/corso/src/pkg/path" -) - -type mockColl struct { - p path.Path - prevP path.Path -} - -func (mc mockColl) Items() <-chan Stream { - return nil -} - -func (mc mockColl) FullPath() path.Path { - return mc.p -} - -func (mc mockColl) PreviousPath() path.Path { - return mc.prevP -} - -func (mc mockColl) State() CollectionState { - return NewState -} - -func (mc mockColl) DoNotMergeItems() bool { - return false -} - -type CollectionSuite struct { - suite.Suite -} - -// ------------------------------------------------------------------------------------------------ -// tests -// ------------------------------------------------------------------------------------------------ - -func TestCollectionSuite(t *testing.T) { - suite.Run(t, new(CollectionSuite)) -} - -func (suite *CollectionSuite) TestResourceOwnerSet() { - t := suite.T() - toColl := func(t *testing.T, resource string) Collection { - p, err := path.Builder{}. - Append("foo"). - ToDataLayerExchangePathForCategory("tid", resource, path.EventsCategory, false) - require.NoError(t, err) - - return mockColl{p, nil} - } - - table := []struct { - name string - input []Collection - expect []string - }{ - { - name: "empty", - input: []Collection{}, - expect: []string{}, - }, - { - name: "nil", - input: nil, - expect: []string{}, - }, - { - name: "single resource", - input: []Collection{toColl(t, "fnords")}, - expect: []string{"fnords"}, - }, - { - name: "multiple resource", - input: []Collection{toColl(t, "fnords"), toColl(t, "smarfs")}, - expect: []string{"fnords", "smarfs"}, - }, - { - name: "duplciate resources", - input: []Collection{toColl(t, "fnords"), toColl(t, "smarfs"), toColl(t, "fnords")}, - expect: []string{"fnords", "smarfs"}, - }, - } - for _, test := range table { - suite.T().Run(test.name, func(t *testing.T) { - rs := ResourceOwnerSet(test.input) - assert.ElementsMatch(t, test.expect, rs) - }) - } -}