-
Notifications
You must be signed in to change notification settings - Fork 9
/
collections_test.go
136 lines (104 loc) · 3.66 KB
/
collections_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package rockset_test
import (
"fmt"
"testing"
"github.com/stretchr/testify/suite"
"github.com/rockset/rockset-go-client"
"github.com/rockset/rockset-go-client/dataset"
"github.com/rockset/rockset-go-client/internal/test"
"github.com/rockset/rockset-go-client/option"
)
type CollectionTestSuite struct {
suite.Suite
rc *rockset.RockClient
ws string
collections []string
}
func TestCollectionIntegrationSuite(t *testing.T) {
rc, randomName := vcrTestClient(t, t.Name())
suite.Run(t, &CollectionTestSuite{rc: rc, ws: randomName("collection")})
}
func (s *CollectionTestSuite) SetupSuite() {
ctx := test.Context()
_, err := s.rc.CreateWorkspace(ctx, s.ws)
s.Require().NoError(err)
err = s.rc.Wait.UntilWorkspaceAvailable(ctx, s.ws)
s.Require().NoError(err)
}
func (s *CollectionTestSuite) TearDownSuite() {
ctx := test.Context()
var deleted []string
for _, c := range s.collections {
err := s.rc.DeleteCollection(ctx, s.ws, c)
if s.NoError(err) {
deleted = append(deleted, c)
}
}
for _, c := range deleted {
err := s.rc.Wait.UntilCollectionGone(ctx, s.ws, c)
s.NoError(err)
}
err := s.rc.DeleteWorkspace(ctx, s.ws)
s.NoError(err)
}
func (s *CollectionTestSuite) BeforeTest(suiteName, testName string) {
s.rc, _ = vcrTestClient(s.T(), fmt.Sprintf("%s/%s", suiteName, testName))
}
func (s *CollectionTestSuite) TestGetCollection() {
ctx := test.Context()
collection, err := s.rc.GetCollection(ctx, test.PersistentWorkspace, test.PersistentCollection)
s.NoError(err)
s.Equal(test.PersistentCollection, collection.GetName())
}
func (s *CollectionTestSuite) TestListAllCollections() {
ctx := test.Context()
collections, err := s.rc.ListCollections(ctx)
s.NoError(err)
s.T().Logf("collections: %d", len(collections))
}
func (s *CollectionTestSuite) TestListCollectionsInWorkspace() {
ctx := test.Context()
collections, err := s.rc.ListCollections(ctx, option.WithWorkspace(test.PersistentWorkspace))
s.NoError(err)
s.T().Logf("collections in %s: %d", test.PersistentWorkspace, len(collections))
}
func (s *CollectionTestSuite) TestCreateSampleCitiesCollection() {
ctx := test.Context()
name := test.RandomName("cities")
_, err := s.rc.CreateCollection(ctx, s.ws, name,
option.WithSampleDataset(dataset.Cities))
s.Require().NoError(err)
s.collections = append(s.collections, name)
err = s.rc.Wait.UntilCollectionHasDocuments(ctx, s.ws, name, int64(145_658))
s.NoError(err)
}
func (s *CollectionTestSuite) TestCreateSampleMoviesCollection() {
ctx := test.Context()
name := test.RandomName("movies")
_, err := s.rc.CreateCollection(ctx, s.ws, name,
option.WithStorageCompressionType(option.StorageCompressionLZ4),
option.WithSampleDatasetPattern("movies/*"))
s.Require().NoError(err)
s.collections = append(s.collections, name)
err = s.rc.Wait.UntilCollectionHasDocuments(ctx, s.ws, name, int64(2_830))
s.NoError(err)
}
func (s *CollectionTestSuite) TestUpdateCollection() {
ctx := test.Context()
name := test.RandomName("update")
_, err := s.rc.CreateCollection(ctx, s.ws, name,
option.WithStorageCompressionType(option.StorageCompressionZSTD),
option.WithCollectionDescription("initial"),
option.WithIngestTransformation("SELECT * FROM _input"))
s.Require().NoError(err)
s.collections = append(s.collections, name)
err = s.rc.Wait.UntilCollectionReady(ctx, s.ws, name)
s.Require().NoError(err)
_, err = s.rc.UpdateCollection(ctx, s.ws, name,
option.WithStorageCompressionType(option.StorageCompressionLZ4))
s.Error(err)
_, err = s.rc.UpdateCollection(ctx, s.ws, name,
option.WithCollectionDescription("updated"),
option.WithIngestTransformation("SELECT * FROM _input WHERE _input.foo != 'bar'"))
s.NoError(err)
}