ADAPT-Chase commited on
Commit
5be045b
·
verified ·
1 Parent(s): 344d241

Add files using upload-large-folder tool

Browse files
Files changed (20) hide show
  1. platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/slow/slow_file_copy_test.go +285 -0
  2. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/auth_tests/auth_setup_test.go +43 -0
  3. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/auth_tests/auth_test.go +100 -0
  4. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/compression/compression_test.go +368 -0
  5. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/filters_tests/contains_test.go +1049 -0
  6. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/filters_tests/contains_text_test.go +472 -0
  7. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/filters_tests/numerical_filters_test.go +442 -0
  8. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/filters_tests/regex_test.go +136 -0
  9. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/filters_tests/where_test.go +78 -0
  10. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/fixtures/allproperties.go +186 -0
  11. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/fixtures/books.go +106 -0
  12. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/fixtures/colbert.go +124 -0
  13. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/fixtures/food.go +545 -0
  14. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/fixtures/vector_index_configs.go +12 -0
  15. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/grpc_tests/batch_grpc_test.go +163 -0
  16. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/multi_tenancy_tests/activation_deactivation_test.go +664 -0
  17. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/multi_tenancy_tests/batch_reference_test.go +1589 -0
  18. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/multi_tenancy_tests/batch_test.go +729 -0
  19. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/multi_tenancy_tests/data_test.go +1382 -0
  20. platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/multi_tenancy_tests/graphql_test.go +514 -0
platform/dbops/binaries/weaviate-src/test/acceptance/replication/replica_replication/slow/slow_file_copy_test.go ADDED
@@ -0,0 +1,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package slow
13
+
14
+ import (
15
+ "bytes"
16
+ "context"
17
+ "encoding/json"
18
+ "fmt"
19
+ "net/http"
20
+ "sync"
21
+ "testing"
22
+ "time"
23
+
24
+ "github.com/go-openapi/strfmt"
25
+ "github.com/google/uuid"
26
+ logrustest "github.com/sirupsen/logrus/hooks/test"
27
+ "github.com/stretchr/testify/assert"
28
+ "github.com/stretchr/testify/require"
29
+ "github.com/stretchr/testify/suite"
30
+ "github.com/weaviate/weaviate/client/nodes"
31
+ "github.com/weaviate/weaviate/client/replication"
32
+ enterrors "github.com/weaviate/weaviate/entities/errors"
33
+ "github.com/weaviate/weaviate/entities/models"
34
+ "github.com/weaviate/weaviate/entities/verbosity"
35
+ "github.com/weaviate/weaviate/test/acceptance/replication/common"
36
+ "github.com/weaviate/weaviate/test/docker"
37
+ "github.com/weaviate/weaviate/test/helper"
38
+ "github.com/weaviate/weaviate/test/helper/sample-schema/articles"
39
+ )
40
+
41
+ type ReplicationTestSuite struct {
42
+ suite.Suite
43
+ }
44
+
45
+ func (suite *ReplicationTestSuite) SetupTest() {
46
+ suite.T().Setenv("TEST_WEAVIATE_IMAGE", "weaviate/test-server")
47
+ }
48
+
49
+ func TestReplicationTestSuite(t *testing.T) {
50
+ suite.Run(t, new(ReplicationTestSuite))
51
+ }
52
+
53
+ func (suite *ReplicationTestSuite) TestReplicaMovementOneWriteExtraSlowFileCopy() {
54
+ t := suite.T()
55
+ mainCtx := context.Background()
56
+ logger, _ := logrustest.NewNullLogger()
57
+
58
+ compose, err := docker.New().
59
+ WithWeaviateCluster(3).
60
+ WithText2VecContextionary().
61
+ WithWeaviateEnv("WEAVIATE_TEST_COPY_REPLICA_SLEEP", "20s").
62
+ Start(mainCtx)
63
+ require.Nil(t, err)
64
+ defer func() {
65
+ if err := compose.Terminate(mainCtx); err != nil {
66
+ t.Fatalf("failed to terminate test containers: %s", err.Error())
67
+ }
68
+ }()
69
+
70
+ ctx, cancel := context.WithTimeout(mainCtx, 10*time.Minute)
71
+ defer cancel()
72
+
73
+ helper.SetupClient(compose.GetWeaviate().URI())
74
+ paragraphClass := articles.ParagraphsClass()
75
+
76
+ t.Run("stop node 3", func(t *testing.T) {
77
+ common.StopNodeAt(ctx, t, compose, 3)
78
+ })
79
+
80
+ t.Run("create schema", func(t *testing.T) {
81
+ paragraphClass.ShardingConfig = map[string]interface{}{"desiredCount": 1}
82
+ paragraphClass.ReplicationConfig = &models.ReplicationConfig{
83
+ Factor: 1,
84
+ AsyncEnabled: false,
85
+ }
86
+ paragraphClass.Vectorizer = "text2vec-contextionary"
87
+ helper.CreateClass(t, paragraphClass)
88
+ })
89
+
90
+ t.Run("restart node 3", func(t *testing.T) {
91
+ common.StartNodeAt(ctx, t, compose, 3)
92
+ })
93
+
94
+ // Setup client again after restart to avoid HTTP error if client setup to container that now has a changed port
95
+ helper.SetupClient(compose.GetWeaviate().URI())
96
+
97
+ numParagraphsInsertedBeforeStart := 10
98
+ t.Run("insert paragraphs", func(t *testing.T) {
99
+ // Create and insert each object individually
100
+ for i := 0; i < numParagraphsInsertedBeforeStart; i++ {
101
+ obj := articles.NewParagraph().
102
+ WithID(strfmt.UUID(uuid.New().String())).
103
+ WithContents(fmt.Sprintf("paragraph#%d", i)).
104
+ Object()
105
+
106
+ // Insert the object individually
107
+ common.CreateObjects(t, compose.GetWeaviate().URI(), []*models.Object{obj})
108
+ }
109
+ })
110
+
111
+ t.Run("verify that all nodes are running", func(t *testing.T) {
112
+ assert.EventuallyWithT(t, func(ct *assert.CollectT) {
113
+ verbose := verbosity.OutputVerbose
114
+ params := nodes.NewNodesGetClassParams().WithOutput(&verbose)
115
+ body, clientErr := helper.Client(t).Nodes.NodesGetClass(params, nil)
116
+ require.NoError(ct, clientErr)
117
+ require.NotNil(ct, body.Payload)
118
+
119
+ resp := body.Payload
120
+ require.Len(ct, resp.Nodes, 3)
121
+ for _, n := range resp.Nodes {
122
+ require.NotNil(ct, n.Status)
123
+ assert.Equal(ct, "HEALTHY", *n.Status)
124
+ }
125
+ }, 15*time.Second, 500*time.Millisecond)
126
+ })
127
+
128
+ var opId strfmt.UUID
129
+ sourceNode := -1
130
+ numParagraphsInsertedWhileStarting := 1
131
+ t.Run("start replica replication to node3 for paragraph", func(t *testing.T) {
132
+ verbose := verbosity.OutputVerbose
133
+ params := nodes.NewNodesGetClassParams().WithOutput(&verbose).WithClassName(paragraphClass.Class)
134
+ body, clientErr := helper.Client(t).Nodes.NodesGetClass(params, nil)
135
+ require.NoError(t, clientErr)
136
+ require.NotNil(t, body.Payload)
137
+ targetNode := "node3"
138
+ hasFoundNode := false
139
+ hasFoundShard := false
140
+
141
+ for i, node := range body.Payload.Nodes {
142
+ if node.Name == targetNode {
143
+ continue
144
+ }
145
+
146
+ if len(node.Shards) >= 1 {
147
+ hasFoundNode = true
148
+ } else {
149
+ continue
150
+ }
151
+
152
+ for _, shard := range node.Shards {
153
+ if shard.Class != paragraphClass.Class {
154
+ continue
155
+ }
156
+ hasFoundShard = true
157
+
158
+ t.Logf("Starting replica replication from %s to %s for shard %s", node.Name, targetNode, shard.Name)
159
+ // i + 1 because stop/start routine are 1 based not 0
160
+ sourceNode = i + 1
161
+ // start replication in parallel with inserting new paragraphs
162
+ wg := sync.WaitGroup{}
163
+ wg.Add(1)
164
+ enterrors.GoWrapper(func() {
165
+ defer wg.Done()
166
+ // sleep 20s so that the source node has paused compaction but not resumed yet
167
+ time.Sleep(20 * time.Second)
168
+ for i := 0; i < numParagraphsInsertedWhileStarting; i++ {
169
+ err := createObjectThreadSafe(
170
+ compose.ContainerURI(sourceNode),
171
+ paragraphClass.Class,
172
+ map[string]interface{}{
173
+ "contents": fmt.Sprintf("paragraph#%d", numParagraphsInsertedBeforeStart+i),
174
+ },
175
+ uuid.New().String(),
176
+ "",
177
+ )
178
+ require.NoError(t, err)
179
+ time.Sleep(time.Millisecond)
180
+
181
+ }
182
+ }, logger)
183
+
184
+ wg.Add(1)
185
+ enterrors.GoWrapper(func() {
186
+ defer wg.Done()
187
+ resp, err := helper.Client(t).Replication.Replicate(
188
+ replication.NewReplicateParams().WithBody(
189
+ &models.ReplicationReplicateReplicaRequest{
190
+ Collection: &paragraphClass.Class,
191
+ SourceNode: &node.Name,
192
+ TargetNode: &targetNode,
193
+ Shard: &shard.Name,
194
+ },
195
+ ),
196
+ nil,
197
+ )
198
+ require.NoError(t, err)
199
+ require.Equal(t, http.StatusOK, resp.Code(), "replication replicate operation didn't return 200 OK")
200
+ opId = *resp.Payload.ID
201
+ }, logger)
202
+ wg.Wait()
203
+ }
204
+ }
205
+ require.True(t, hasFoundShard, "could not find shard for class %s", paragraphClass.Class)
206
+ require.True(t, hasFoundNode, "could not find node with shards for paragraph")
207
+ })
208
+
209
+ // If no node was found fail now
210
+ if sourceNode == -1 {
211
+ t.FailNow()
212
+ }
213
+
214
+ // Wait for the replication to finish
215
+ t.Run("waiting for replication to finish", func(t *testing.T) {
216
+ assert.EventuallyWithT(t, func(ct *assert.CollectT) {
217
+ details, err := helper.Client(t).Replication.ReplicationDetails(
218
+ replication.NewReplicationDetailsParams().WithID(opId), nil,
219
+ )
220
+ assert.Nil(t, err, "failed to get replication details %s", err)
221
+ assert.NotNil(t, details, "expected replication details to be not nil")
222
+ assert.NotNil(t, details.Payload, "expected replication details payload to be not nil")
223
+ assert.NotNil(t, details.Payload.Status, "expected replication status to be not nil")
224
+ assert.Equal(ct, "READY", details.Payload.Status.State, "expected replication status to be READY")
225
+ }, 360*time.Second, 3*time.Second, "replication operation %s not finished in time", opId)
226
+ })
227
+
228
+ // Kills the original node with the data to ensure we have only one replica available (the new one)
229
+ t.Run(fmt.Sprintf("stop node %d", sourceNode), func(t *testing.T) {
230
+ common.StopNodeAt(ctx, t, compose, sourceNode)
231
+ })
232
+
233
+ t.Run("assert correct number of objects on node3", func(t *testing.T) {
234
+ numObjectsFound := common.CountObjects(t, compose.ContainerURI(3), paragraphClass.Class)
235
+ assert.Equal(t, numParagraphsInsertedBeforeStart+numParagraphsInsertedWhileStarting, int(numObjectsFound))
236
+ })
237
+ }
238
+
239
+ func createObjectThreadSafe(uri string, class string, properties map[string]interface{}, id string, tenant string) error {
240
+ // Define the data structure for the request body
241
+ type Object struct {
242
+ Class string `json:"class"`
243
+ Properties map[string]interface{} `json:"properties"`
244
+ ID string `json:"id"`
245
+ Tenant string `json:"tenant,omitempty"`
246
+ }
247
+
248
+ // Create an instance of the object with sample data
249
+ obj := Object{
250
+ Class: class,
251
+ Properties: properties,
252
+ ID: id,
253
+ Tenant: tenant,
254
+ }
255
+
256
+ // Marshal the object to JSON
257
+ jsonData, err := json.Marshal(obj)
258
+ if err != nil {
259
+ return fmt.Errorf("error marshalling JSON: %w", err)
260
+ }
261
+
262
+ // Create a new POST request
263
+ req, err := http.NewRequest("POST", "http://"+uri+"/v1/objects", bytes.NewBuffer(jsonData))
264
+ if err != nil {
265
+ return fmt.Errorf("error creating request: %w", err)
266
+ }
267
+
268
+ // Set the appropriate headers
269
+ req.Header.Set("Content-Type", "application/json")
270
+
271
+ // Send the request using http.DefaultClient
272
+ client := &http.Client{}
273
+ resp, err := client.Do(req)
274
+ if err != nil {
275
+ return fmt.Errorf("error sending request: %w", err)
276
+ }
277
+ defer resp.Body.Close()
278
+
279
+ // Check the response status
280
+ if resp.StatusCode != http.StatusOK {
281
+ return fmt.Errorf("request failed with status: %s", resp.Status)
282
+ }
283
+
284
+ return nil
285
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/auth_tests/auth_setup_test.go ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package auth_tests
13
+
14
+ import (
15
+ "context"
16
+ "os"
17
+ "testing"
18
+
19
+ "github.com/pkg/errors"
20
+ "github.com/weaviate/weaviate/test/docker"
21
+ )
22
+
23
+ const weaviateEndpoint = "WEAVIATE_ENDPOINT"
24
+
25
+ func TestMain(m *testing.M) {
26
+ ctx := context.Background()
27
+ compose, err := docker.New().
28
+ WithWeaviate().
29
+ WithWeaviateAuth().
30
+ Start(ctx)
31
+ if err != nil {
32
+ panic(errors.Wrapf(err, "cannot start"))
33
+ }
34
+
35
+ os.Setenv(weaviateEndpoint, compose.GetWeaviate().URI())
36
+ code := m.Run()
37
+
38
+ if err := compose.Terminate(ctx); err != nil {
39
+ panic(errors.Wrapf(err, "cannot terminate"))
40
+ }
41
+
42
+ os.Exit(code)
43
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/auth_tests/auth_test.go ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package auth_tests
13
+
14
+ import (
15
+ "context"
16
+ "os"
17
+ "testing"
18
+
19
+ "github.com/stretchr/testify/require"
20
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/auth"
21
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/fault"
22
+ "github.com/weaviate/weaviate/entities/models"
23
+
24
+ client "github.com/weaviate/weaviate-go-client/v5/weaviate"
25
+ )
26
+
27
+ const (
28
+ wcsUserOnAdmin = "oidc-test-user@weaviate.io"
29
+ wcsUserNotOnAdmin = "oidc-test-user2@weaviate.io"
30
+ )
31
+
32
+ func TestAuthGraphQLUnauthenticated(t *testing.T) {
33
+ ctx := context.Background()
34
+ c := client.New(client.Config{Scheme: "http", Host: os.Getenv(weaviateEndpoint)})
35
+ _, err := c.GraphQL().Raw().WithQuery("{__schema {queryType {fields {name}}}}").Do(ctx)
36
+ require.NotNil(t, err)
37
+ }
38
+
39
+ func TestAuthGraphQLValidUserNotOnAdminlist(t *testing.T) {
40
+ pw := os.Getenv("WCS_DUMMY_CI_PW_2")
41
+ if pw == "" {
42
+ t.Skip("No password supplied")
43
+ }
44
+
45
+ ctx := context.Background()
46
+
47
+ conf := client.Config{
48
+ Scheme: "http",
49
+ Host: os.Getenv(weaviateEndpoint),
50
+ AuthConfig: auth.ResourceOwnerPasswordFlow{Username: wcsUserNotOnAdmin, Password: pw},
51
+ }
52
+ c, err := client.NewClient(conf)
53
+ require.Nil(t, err)
54
+
55
+ _, err = c.GraphQL().Raw().WithQuery("{__schema {queryType {fields {name}}}}").Do(ctx)
56
+ require.NotNil(t, err)
57
+ }
58
+
59
+ func TestAuthGraphQLValidUser(t *testing.T) {
60
+ pwAdminUser := os.Getenv("WCS_DUMMY_CI_PW")
61
+ pwNoAdminUser := os.Getenv("WCS_DUMMY_CI_PW_2")
62
+ if pwAdminUser == "" || pwNoAdminUser == "" {
63
+ t.Skip("No password supplied")
64
+ }
65
+
66
+ ctx := context.Background()
67
+ conf := client.Config{
68
+ Scheme: "http",
69
+ Host: os.Getenv(weaviateEndpoint),
70
+ AuthConfig: auth.ResourceOwnerPasswordFlow{Username: wcsUserOnAdmin, Password: pwAdminUser},
71
+ }
72
+ c, err := client.NewClient(conf)
73
+ require.Nil(t, err)
74
+
75
+ // add a class so schema is not empty
76
+ require.Nil(t, c.Schema().AllDeleter().Do(ctx))
77
+ require.Nil(t, c.Schema().ClassCreator().WithClass(&models.Class{Class: "Pizza"}).Do(ctx))
78
+
79
+ t.Run("returns schema without error for admin", func(t *testing.T) {
80
+ _, err = c.GraphQL().Raw().WithQuery("{__schema {queryType {fields {name}}}}").Do(ctx)
81
+ require.Nil(t, err)
82
+ })
83
+
84
+ t.Run("returns auth error for non-admin", func(t *testing.T) {
85
+ conf2 := client.Config{
86
+ Scheme: "http",
87
+ Host: os.Getenv(weaviateEndpoint),
88
+ AuthConfig: auth.ResourceOwnerPasswordFlow{Username: wcsUserNotOnAdmin, Password: pwNoAdminUser},
89
+ }
90
+ cNoAdmin, err := client.NewClient(conf2)
91
+ require.Nil(t, err)
92
+
93
+ _, err = cNoAdmin.GraphQL().Raw().WithQuery("{__schema {queryType {fields {name}}}}").Do(ctx)
94
+ require.NotNil(t, err)
95
+ wErr, ok := err.(*fault.WeaviateClientError)
96
+ require.True(t, ok)
97
+
98
+ require.Contains(t, wErr.DerivedFromError.Error(), "forbidden")
99
+ })
100
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/compression/compression_test.go ADDED
@@ -0,0 +1,368 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package compression_test
13
+
14
+ import (
15
+ "context"
16
+ "fmt"
17
+ "math/rand"
18
+ "testing"
19
+ "time"
20
+
21
+ "github.com/stretchr/testify/require"
22
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
23
+ "github.com/weaviate/weaviate/entities/models"
24
+ "github.com/weaviate/weaviate/entities/schema"
25
+ "github.com/weaviate/weaviate/entities/vectorindex/hnsw"
26
+ "github.com/weaviate/weaviate/test/docker"
27
+ )
28
+
29
+ func TestCompression_AdaptSegments(t *testing.T) {
30
+ type dimensionTestCase struct {
31
+ vectors [][]float32
32
+ }
33
+ type vectorTypeTestCase struct {
34
+ name string
35
+ createClassFn func(t *testing.T, client *wvt.Client, className string) *models.Class
36
+ populateFn func(t *testing.T, client *wvt.Client, className string, vectors [][]float32)
37
+ compressFn func(t *testing.T, client *wvt.Client, class *models.Class)
38
+ }
39
+
40
+ ctx := context.Background()
41
+ className := "Compressed"
42
+ vectorsCount := 1000
43
+
44
+ dimensionTestCases := []dimensionTestCase{
45
+ {vectors: randomVecs(vectorsCount, 768)},
46
+ {vectors: randomVecs(vectorsCount, 4)},
47
+ }
48
+
49
+ t.Run("async indexing", func(t *testing.T) {
50
+ vectorTypeTestCases := []vectorTypeTestCase{
51
+ {
52
+ name: "legacy vector",
53
+ createClassFn: createClassLegacyVector,
54
+ populateFn: populateLegacyVector,
55
+ compressFn: compressLegacyVectorAsync,
56
+ },
57
+ {
58
+ name: "target vectors",
59
+ createClassFn: createClassTargetVectors,
60
+ populateFn: populateTargetVectors,
61
+ compressFn: compressTargetVectorsAsync,
62
+ },
63
+ }
64
+
65
+ compose, err := docker.New().
66
+ WithWeaviate().
67
+ WithWeaviateEnv("ASYNC_INDEXING", "true").
68
+ WithWeaviateEnv("ASYNC_INDEXING_STALE_TIMEOUT", "1s").
69
+ Start(ctx)
70
+ require.NoError(t, err)
71
+ defer func() {
72
+ require.NoError(t, compose.Terminate(ctx))
73
+ }()
74
+
75
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: compose.GetWeaviate().URI()})
76
+ require.NoError(t, err)
77
+ cleanup := func() {
78
+ err := client.Schema().AllDeleter().Do(ctx)
79
+ require.NoError(t, err)
80
+ }
81
+
82
+ for _, dtc := range dimensionTestCases {
83
+ t.Run(fmt.Sprintf("dimensions %d", len(dtc.vectors[0])), func(t *testing.T) {
84
+ for _, vttc := range vectorTypeTestCases {
85
+ t.Run(vttc.name, func(t *testing.T) {
86
+ defer cleanup()
87
+
88
+ var class *models.Class
89
+
90
+ t.Run("create class", func(t *testing.T) {
91
+ class = vttc.createClassFn(t, client, className)
92
+ })
93
+
94
+ t.Run("compress", func(t *testing.T) {
95
+ vttc.compressFn(t, client, class)
96
+ })
97
+
98
+ t.Run("populate", func(t *testing.T) {
99
+ vttc.populateFn(t, client, className, dtc.vectors)
100
+ })
101
+
102
+ t.Run("check eventually compressed", func(t *testing.T) {
103
+ checkEventuallyCompressed(t, client, className)
104
+ })
105
+ })
106
+ }
107
+ })
108
+ }
109
+ })
110
+
111
+ t.Run("sync indexing", func(t *testing.T) {
112
+ vectorTypeTestCases := []vectorTypeTestCase{
113
+ {
114
+ name: "legacy vector",
115
+ createClassFn: createClassLegacyVector,
116
+ populateFn: populateLegacyVector,
117
+ compressFn: compressLegacyVectorSync,
118
+ },
119
+ {
120
+ name: "target vectors",
121
+ createClassFn: createClassTargetVectors,
122
+ populateFn: populateTargetVectors,
123
+ compressFn: compressTargetVectorsSync,
124
+ },
125
+ }
126
+
127
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: "localhost:8080"})
128
+ require.NoError(t, err)
129
+ cleanup := func() {
130
+ err := client.Schema().AllDeleter().Do(ctx)
131
+ require.NoError(t, err)
132
+ }
133
+
134
+ for _, dtc := range dimensionTestCases {
135
+ t.Run(fmt.Sprintf("dimensions %d", len(dtc.vectors[0])), func(t *testing.T) {
136
+ for _, vttc := range vectorTypeTestCases {
137
+ t.Run(vttc.name, func(t *testing.T) {
138
+ defer cleanup()
139
+
140
+ var class *models.Class
141
+
142
+ t.Run("create class", func(t *testing.T) {
143
+ class = vttc.createClassFn(t, client, className)
144
+ })
145
+
146
+ t.Run("populate", func(t *testing.T) {
147
+ vttc.populateFn(t, client, className, dtc.vectors)
148
+ })
149
+
150
+ t.Run("compress", func(t *testing.T) {
151
+ vttc.compressFn(t, client, class)
152
+ })
153
+
154
+ t.Run("check eventually compressed", func(t *testing.T) {
155
+ checkEventuallyCompressed(t, client, className)
156
+ })
157
+ })
158
+ }
159
+ })
160
+ }
161
+ })
162
+ }
163
+
164
+ func createClassLegacyVector(t *testing.T, client *wvt.Client, className string) *models.Class {
165
+ class := &models.Class{
166
+ Class: className,
167
+ Properties: []*models.Property{{
168
+ Name: "int",
169
+ DataType: schema.DataTypeInt.PropString(),
170
+ }},
171
+ Vectorizer: "none",
172
+ VectorIndexConfig: hnswCompressVectorIndexConfig(),
173
+ }
174
+
175
+ createClass(t, client, class)
176
+ return class
177
+ }
178
+
179
+ func createClassTargetVectors(t *testing.T, client *wvt.Client, className string) *models.Class {
180
+ class := &models.Class{
181
+ Class: className,
182
+ Properties: []*models.Property{{
183
+ Name: "int",
184
+ DataType: schema.DataTypeInt.PropString(),
185
+ }},
186
+ VectorConfig: map[string]models.VectorConfig{
187
+ "vectorFlat": {
188
+ VectorIndexType: "flat",
189
+ Vectorizer: map[string]interface{}{
190
+ "none": struct{}{},
191
+ },
192
+ },
193
+ "vectorHnswCompress": {
194
+ VectorIndexType: "hnsw",
195
+ Vectorizer: map[string]interface{}{
196
+ "none": struct{}{},
197
+ },
198
+ VectorIndexConfig: hnswCompressVectorIndexConfig(),
199
+ },
200
+ },
201
+ }
202
+
203
+ err := client.Schema().ClassCreator().
204
+ WithClass(class).
205
+ Do(context.Background())
206
+ if err != nil {
207
+ require.NoError(t, err)
208
+ }
209
+
210
+ return class
211
+ }
212
+
213
+ func createClass(t *testing.T, client *wvt.Client, class *models.Class) {
214
+ err := client.Schema().ClassCreator().
215
+ WithClass(class).
216
+ Do(context.Background())
217
+ require.NoError(t, err)
218
+ }
219
+
220
+ func hnswCompressVectorIndexConfig() map[string]interface{} {
221
+ return map[string]interface{}{
222
+ "maxConnections": 32,
223
+ "efConstruction": 64,
224
+ "ef": 32,
225
+ "vectorCacheMaxObjects": 10e12,
226
+ "distance": "l2-squared",
227
+ "pq": map[string]interface{}{
228
+ "enabled": true,
229
+ "encoder": map[string]interface{}{
230
+ "distribution": hnsw.PQEncoderDistributionNormal,
231
+ "type": hnsw.PQEncoderTypeKMeans,
232
+ },
233
+ },
234
+ }
235
+ }
236
+
237
+ func populateLegacyVector(t *testing.T, client *wvt.Client, className string, vectors [][]float32) {
238
+ objects := make([]*models.Object, len(vectors))
239
+ for i, vector := range vectors {
240
+ objects[i] = &models.Object{
241
+ Class: className,
242
+ Properties: map[string]interface{}{
243
+ "int": i,
244
+ },
245
+ Vector: vector,
246
+ }
247
+ }
248
+
249
+ populate(t, client, objects)
250
+ }
251
+
252
+ func populateTargetVectors(t *testing.T, client *wvt.Client, className string, vectors [][]float32) {
253
+ objects := make([]*models.Object, len(vectors))
254
+ for i, vector := range vectors {
255
+ objects[i] = &models.Object{
256
+ Class: className,
257
+ Properties: map[string]interface{}{
258
+ "int": i,
259
+ },
260
+ Vectors: models.Vectors{
261
+ "vectorFlat": vector,
262
+ "vectorHnswCompress": vector,
263
+ },
264
+ }
265
+ }
266
+
267
+ populate(t, client, objects)
268
+ }
269
+
270
+ func populate(t *testing.T, client *wvt.Client, objects []*models.Object) {
271
+ resps, err := client.Batch().ObjectsBatcher().
272
+ WithObjects(objects...).
273
+ Do(context.Background())
274
+ require.NoError(t, err)
275
+ require.Len(t, resps, len(objects))
276
+ for _, resp := range resps {
277
+ require.NotNil(t, resp.Result.Status)
278
+ require.Equal(t, models.ObjectsGetResponseAO2ResultStatusSUCCESS, *resp.Result.Status)
279
+ }
280
+ }
281
+
282
+ func compressLegacyVectorAsync(t *testing.T, client *wvt.Client, class *models.Class) {
283
+ updateConfigAsync(class.VectorIndexConfig.(map[string]interface{})["pq"].(map[string]interface{}))
284
+ compress(t, client, class)
285
+ }
286
+
287
+ func compressLegacyVectorSync(t *testing.T, client *wvt.Client, class *models.Class) {
288
+ updateConfigSync(class.VectorIndexConfig.(map[string]interface{})["pq"].(map[string]interface{}))
289
+ compress(t, client, class)
290
+ }
291
+
292
+ func compressTargetVectorsAsync(t *testing.T, client *wvt.Client, class *models.Class) {
293
+ updateConfigAsync(class.VectorConfig["vectorHnswCompress"].
294
+ VectorIndexConfig.(map[string]interface{})["pq"].(map[string]interface{}))
295
+ compress(t, client, class)
296
+ }
297
+
298
+ func compressTargetVectorsSync(t *testing.T, client *wvt.Client, class *models.Class) {
299
+ updateConfigSync(class.VectorConfig["vectorHnswCompress"].
300
+ VectorIndexConfig.(map[string]interface{})["pq"].(map[string]interface{}))
301
+ compress(t, client, class)
302
+ }
303
+
304
+ func updateConfigAsync(pq map[string]interface{}) {
305
+ pq["segments"] = 0
306
+ pq["centroids"] = 256
307
+ pq["trainingLimit"] = 999
308
+ }
309
+
310
+ func updateConfigSync(pq map[string]interface{}) {
311
+ pq["segments"] = 0
312
+ pq["centroids"] = 256
313
+ }
314
+
315
+ func compress(t *testing.T, client *wvt.Client, class *models.Class) {
316
+ err := client.Schema().ClassUpdater().
317
+ WithClass(class).
318
+ Do(context.Background())
319
+ require.NoError(t, err)
320
+ }
321
+
322
+ func checkEventuallyCompressed(t *testing.T, client *wvt.Client, className string) {
323
+ ctx := context.Background()
324
+ timeout := 15 * time.Minute
325
+ interval := 1 * time.Second
326
+
327
+ var compressed bool
328
+ end := time.Now().Add(timeout)
329
+ for time.Now().Before(end) {
330
+ resp, err := client.Cluster().NodesStatusGetter().
331
+ WithClass(className).
332
+ WithOutput("verbose").
333
+ Do(ctx)
334
+ require.NoError(t, err)
335
+ require.NotNil(t, resp)
336
+ require.Len(t, resp.Nodes, 1)
337
+ require.Len(t, resp.Nodes[0].Shards, 1)
338
+
339
+ compressed = resp.Nodes[0].Shards[0].Compressed
340
+ fmt.Printf(" ==> compressed %v\n", compressed)
341
+ if compressed {
342
+ break
343
+ }
344
+ time.Sleep(interval)
345
+ }
346
+
347
+ require.True(t, compressed)
348
+ }
349
+
350
+ func randomVecs(count int, dimensions int) [][]float32 {
351
+ r := rand.New(rand.NewSource(time.Now().UnixNano()))
352
+ vectors := make([][]float32, count)
353
+ for i := range vectors {
354
+ vectors[i] = genVector(r, dimensions)
355
+ }
356
+ return vectors
357
+ }
358
+
359
+ func genVector(r *rand.Rand, dimensions int) []float32 {
360
+ vector := make([]float32, dimensions)
361
+ for i := range vector {
362
+ // Some distances like dot could produce negative values when the vectors have negative values
363
+ // This change will not affect anything when using a distance like l2, but will cover some bugs
364
+ // when using distances like dot
365
+ vector[i] = r.Float32()*2 - 1
366
+ }
367
+ return vector
368
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/filters_tests/contains_test.go ADDED
@@ -0,0 +1,1049 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package filters_tests
13
+
14
+ import (
15
+ "context"
16
+ "fmt"
17
+ "testing"
18
+ "time"
19
+
20
+ acceptance_with_go_client "acceptance_tests_with_client"
21
+
22
+ "github.com/stretchr/testify/assert"
23
+ "github.com/stretchr/testify/require"
24
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
25
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/filters"
26
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/graphql"
27
+ "github.com/weaviate/weaviate/entities/models"
28
+ "github.com/weaviate/weaviate/entities/schema"
29
+ )
30
+
31
+ func testContains(host string) func(t *testing.T) {
32
+ return func(t *testing.T) {
33
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: host})
34
+ require.Nil(t, err)
35
+
36
+ className := "WhereTest"
37
+ id1 := "00000000-0000-0000-0000-000000000001"
38
+ id2 := "00000000-0000-0000-0000-000000000002"
39
+ id3 := "00000000-0000-0000-0000-000000000003"
40
+ ids := []string{id1, id2, id3}
41
+
42
+ cleanup := func() {
43
+ err := client.Schema().AllDeleter().Do(context.Background())
44
+ require.Nil(t, err)
45
+ }
46
+
47
+ t.Run("create class", func(t *testing.T) {
48
+ cleanup()
49
+ class := &models.Class{
50
+ Class: className,
51
+ Properties: []*models.Property{
52
+ {
53
+ Name: "color",
54
+ DataType: schema.DataTypeText.PropString(),
55
+ },
56
+ {
57
+ Name: "colors",
58
+ DataType: schema.DataTypeTextArray.PropString(),
59
+ },
60
+ {
61
+ Name: "author",
62
+ DataType: schema.DataTypeString.PropString(),
63
+ },
64
+ {
65
+ Name: "authors",
66
+ DataType: schema.DataTypeStringArray.PropString(),
67
+ },
68
+ {
69
+ Name: "number",
70
+ DataType: schema.DataTypeNumber.PropString(),
71
+ },
72
+ {
73
+ Name: "numbers",
74
+ DataType: schema.DataTypeNumberArray.PropString(),
75
+ },
76
+ {
77
+ Name: "int",
78
+ DataType: schema.DataTypeInt.PropString(),
79
+ },
80
+ {
81
+ Name: "ints",
82
+ DataType: schema.DataTypeIntArray.PropString(),
83
+ },
84
+ {
85
+ Name: "date",
86
+ DataType: schema.DataTypeDate.PropString(),
87
+ },
88
+ {
89
+ Name: "dates",
90
+ DataType: schema.DataTypeDateArray.PropString(),
91
+ },
92
+ {
93
+ Name: "bool",
94
+ DataType: schema.DataTypeBoolean.PropString(),
95
+ },
96
+ {
97
+ Name: "bools",
98
+ DataType: schema.DataTypeBooleanArray.PropString(),
99
+ },
100
+ {
101
+ Name: "uuid",
102
+ DataType: schema.DataTypeUUID.PropString(),
103
+ },
104
+ {
105
+ Name: "uuids",
106
+ DataType: schema.DataTypeUUIDArray.PropString(),
107
+ },
108
+ },
109
+ }
110
+ err := client.Schema().ClassCreator().WithClass(class).Do(context.TODO())
111
+ require.Nil(t, err)
112
+ // Give time for the schema to replicate and graphql to rebuild it for it's queries
113
+ time.Sleep(3 * time.Second)
114
+ })
115
+
116
+ t.Run("where with bm25 without data", func(t *testing.T) {
117
+ mustGetTime := func(date string) time.Time {
118
+ result, err := time.Parse(time.RFC3339Nano, date)
119
+ if err != nil {
120
+ panic(fmt.Sprintf("can't parse date: %v", date))
121
+ }
122
+ return result
123
+ }
124
+ tests := []struct {
125
+ name string
126
+ where *filters.WhereBuilder
127
+ property string
128
+ }{
129
+ // Contains operator with array types
130
+ {
131
+ name: "contains any authors with string array",
132
+ where: filters.Where().
133
+ WithPath([]string{"authors"}).
134
+ WithOperator(filters.ContainsAny).
135
+ WithValueString("John", "Jenny", "Joseph"),
136
+ property: "authors",
137
+ },
138
+ {
139
+ name: "contains any colors with text array",
140
+ where: filters.Where().
141
+ WithPath([]string{"colors"}).
142
+ WithOperator(filters.ContainsAny).
143
+ WithValueText("red", "blue", "green"),
144
+ property: "colors",
145
+ },
146
+ {
147
+ name: "contains any numbers with number array",
148
+ where: filters.Where().
149
+ WithPath([]string{"numbers"}).
150
+ WithOperator(filters.ContainsAny).
151
+ WithValueNumber(1.1, 2.2, 3.3),
152
+ property: "numbers",
153
+ },
154
+ {
155
+ name: "contains any ints with int array",
156
+ where: filters.Where().
157
+ WithPath([]string{"ints"}).
158
+ WithOperator(filters.ContainsAny).
159
+ WithValueInt(1, 2, 3),
160
+ property: "ints",
161
+ },
162
+ {
163
+ name: "contains any bools with bool array",
164
+ where: filters.Where().
165
+ WithPath([]string{"bools"}).
166
+ WithOperator(filters.ContainsAny).
167
+ WithValueBoolean(true, false),
168
+ property: "bools",
169
+ },
170
+ {
171
+ name: "contains any uuids with uuid array",
172
+ where: filters.Where().
173
+ WithPath([]string{"uuids"}).
174
+ WithOperator(filters.ContainsAny).
175
+ WithValueText(id1, id2, id3),
176
+ property: "uuids",
177
+ },
178
+ {
179
+ name: "contains any dates with dates array",
180
+ where: filters.Where().
181
+ WithPath([]string{"dates"}).
182
+ WithOperator(filters.ContainsAny).
183
+ WithValueDate(
184
+ mustGetTime("2009-11-01T23:00:00Z"), mustGetTime("2009-11-02T23:00:00Z"), mustGetTime("2009-11-03T23:00:00Z"),
185
+ ),
186
+ property: "dates",
187
+ },
188
+ // Contains operator with primitives
189
+ {
190
+ name: "contains any author with string",
191
+ where: filters.Where().
192
+ WithPath([]string{"author"}).
193
+ WithOperator(filters.ContainsAny).
194
+ WithValueString("John", "Jenny", "Joseph"),
195
+ property: "author",
196
+ },
197
+ {
198
+ name: "contains any color with text",
199
+ where: filters.Where().
200
+ WithPath([]string{"color"}).
201
+ WithOperator(filters.ContainsAny).
202
+ WithValueText("red", "blue", "green"),
203
+ property: "color",
204
+ },
205
+ {
206
+ name: "contains any number with number",
207
+ where: filters.Where().
208
+ WithPath([]string{"number"}).
209
+ WithOperator(filters.ContainsAny).
210
+ WithValueNumber(1.1, 2.2, 3.3),
211
+ property: "number",
212
+ },
213
+ {
214
+ name: "contains any int with int",
215
+ where: filters.Where().
216
+ WithPath([]string{"int"}).
217
+ WithOperator(filters.ContainsAny).
218
+ WithValueInt(1, 2, 3),
219
+ property: "int",
220
+ },
221
+ {
222
+ name: "contains any bool with bool",
223
+ where: filters.Where().
224
+ WithPath([]string{"bool"}).
225
+ WithOperator(filters.ContainsAny).
226
+ WithValueBoolean(true, false, true),
227
+ property: "bool",
228
+ },
229
+ {
230
+ name: "contains any uuid with uuid",
231
+ where: filters.Where().
232
+ WithPath([]string{"uuid"}).
233
+ WithOperator(filters.ContainsAny).
234
+ WithValueText(id1, id2, id3),
235
+ property: "uuid",
236
+ },
237
+ {
238
+ name: "contains any uuid with id",
239
+ where: filters.Where().
240
+ WithPath([]string{"id"}).
241
+ WithOperator(filters.ContainsAny).
242
+ WithValueText(id1, id2, id3),
243
+ property: "uuid",
244
+ },
245
+ {
246
+ name: "contains any date with date",
247
+ where: filters.Where().
248
+ WithPath([]string{"date"}).
249
+ WithOperator(filters.ContainsAny).
250
+ WithValueDate(
251
+ mustGetTime("2009-11-01T23:00:00Z"), mustGetTime("2009-11-02T23:00:00Z"), mustGetTime("2009-11-03T23:00:00Z"),
252
+ ),
253
+ property: "date",
254
+ },
255
+ }
256
+ for _, tt := range tests {
257
+ t.Run(tt.name, func(t *testing.T) {
258
+ fields := []graphql.Field{
259
+ {Name: tt.property},
260
+ {Name: "_additional", Fields: []graphql.Field{{Name: "id"}}},
261
+ }
262
+ resp, err := client.GraphQL().Get().
263
+ WithClassName(className).
264
+ WithWhere(tt.where).
265
+ WithBM25(client.GraphQL().
266
+ Bm25ArgBuilder().
267
+ WithQuery(tt.property),
268
+ ).
269
+ WithFields(fields...).
270
+ Do(context.TODO())
271
+ require.Nil(t, err)
272
+ require.Empty(t, resp.Errors)
273
+ })
274
+ }
275
+ })
276
+
277
+ t.Run("with data", func(t *testing.T) {
278
+ t.Run("insert data", func(t *testing.T) {
279
+ authors := []string{"John", "Jenny", "Joseph"}
280
+ authorsArray := [][]string{
281
+ {"John", "Jenny", "Joseph"},
282
+ {"John", "Jenny"},
283
+ {"John"},
284
+ }
285
+ colors := []string{"red", "blue", "green"}
286
+ colorsArray := [][]string{
287
+ {"red", "blue", "green"},
288
+ {"red", "blue"},
289
+ {"red"},
290
+ }
291
+ numbers := []float64{1.1, 2.2, 3.3}
292
+ numbersArray := [][]float64{
293
+ {1.1, 2.2, 3.3},
294
+ {1.1, 2.2},
295
+ {1.1},
296
+ }
297
+ ints := []int64{1, 2, 3}
298
+ intsArray := [][]int64{
299
+ {1, 2, 3},
300
+ {1, 2},
301
+ {1},
302
+ }
303
+ uuids := []string{id1, id2, id3}
304
+ uuidsArray := [][]string{
305
+ {id1, id2, id3},
306
+ {id1, id2},
307
+ {id1},
308
+ }
309
+ dates := []string{"2009-11-01T23:00:00Z", "2009-11-02T23:00:00Z", "2009-11-03T23:00:00Z"}
310
+ datesArray := [][]string{
311
+ {"2009-11-01T23:00:00Z", "2009-11-02T23:00:00Z", "2009-11-03T23:00:00Z"},
312
+ {"2009-11-01T23:00:00Z", "2009-11-02T23:00:00Z"},
313
+ {"2009-11-01T23:00:00Z"},
314
+ }
315
+ bools := []bool{true, false, true}
316
+ boolsArray := [][]bool{
317
+ {true, false, true},
318
+ {true, false},
319
+ {true},
320
+ }
321
+ for i, id := range ids {
322
+ _, err := client.Data().Creator().
323
+ WithClassName(className).
324
+ WithID(id).
325
+ WithProperties(map[string]interface{}{
326
+ "color": colors[i],
327
+ "colors": colorsArray[i],
328
+ "author": authors[i],
329
+ "authors": authorsArray[i],
330
+ "number": numbers[i],
331
+ "numbers": numbersArray[i],
332
+ "int": ints[i],
333
+ "ints": intsArray[i],
334
+ "uuid": uuids[i],
335
+ "uuids": uuidsArray[i],
336
+ "date": dates[i],
337
+ "dates": datesArray[i],
338
+ "bool": bools[i],
339
+ "bools": boolsArray[i],
340
+ }).
341
+ Do(context.TODO())
342
+ require.Nil(t, err)
343
+ }
344
+ })
345
+
346
+ t.Run("where", func(t *testing.T) {
347
+ mustGetTime := func(date string) time.Time {
348
+ result, err := time.Parse(time.RFC3339Nano, date)
349
+ if err != nil {
350
+ panic(fmt.Sprintf("can't parse date: %v", date))
351
+ }
352
+ return result
353
+ }
354
+ tests := []struct {
355
+ name string
356
+ where *filters.WhereBuilder
357
+ property string
358
+ nearText *graphql.NearTextArgumentBuilder
359
+ expectedIds []string
360
+ }{
361
+ // Contains operator with array types
362
+ {
363
+ name: "contains all authors with string array",
364
+ where: filters.Where().
365
+ WithPath([]string{"authors"}).
366
+ WithOperator(filters.ContainsAll).
367
+ WithValueString("John", "Jenny", "Joseph"),
368
+ property: "authors",
369
+ expectedIds: []string{id1},
370
+ },
371
+ {
372
+ name: "contains any authors with string array",
373
+ where: filters.Where().
374
+ WithPath([]string{"authors"}).
375
+ WithOperator(filters.ContainsAny).
376
+ WithValueString("John", "Jenny", "Joseph"),
377
+ property: "authors",
378
+ expectedIds: []string{id1, id2, id3},
379
+ },
380
+ {
381
+ name: "contains none authors with string array",
382
+ where: filters.Where().
383
+ WithPath([]string{"authors"}).
384
+ WithOperator(filters.ContainsNone).
385
+ WithValueString("Joseph", "Missing"),
386
+ property: "authors",
387
+ expectedIds: []string{id2, id3},
388
+ },
389
+ {
390
+ name: "contains all colors with text array",
391
+ where: filters.Where().
392
+ WithPath([]string{"colors"}).
393
+ WithOperator(filters.ContainsAll).
394
+ WithValueText("red", "blue", "green"),
395
+ property: "colors",
396
+ expectedIds: []string{id1},
397
+ },
398
+ {
399
+ name: "contains any colors with text array",
400
+ where: filters.Where().
401
+ WithPath([]string{"colors"}).
402
+ WithOperator(filters.ContainsAny).
403
+ WithValueText("red", "blue", "green"),
404
+ property: "colors",
405
+ expectedIds: []string{id1, id2, id3},
406
+ },
407
+ {
408
+ name: "contains none colors with text array",
409
+ where: filters.Where().
410
+ WithPath([]string{"colors"}).
411
+ WithOperator(filters.ContainsNone).
412
+ WithValueText("green", "missing"),
413
+ property: "colors",
414
+ expectedIds: []string{id2, id3},
415
+ },
416
+ {
417
+ name: "contains all numbers with number array",
418
+ where: filters.Where().
419
+ WithPath([]string{"numbers"}).
420
+ WithOperator(filters.ContainsAll).
421
+ WithValueNumber(1.1, 2.2, 3.3),
422
+ property: "numbers",
423
+ expectedIds: []string{id1},
424
+ },
425
+ {
426
+ name: "contains any numbers with number array",
427
+ where: filters.Where().
428
+ WithPath([]string{"numbers"}).
429
+ WithOperator(filters.ContainsAny).
430
+ WithValueNumber(1.1, 2.2, 3.3),
431
+ property: "numbers",
432
+ expectedIds: []string{id1, id2, id3},
433
+ },
434
+ {
435
+ name: "contains none numbers with number array",
436
+ where: filters.Where().
437
+ WithPath([]string{"numbers"}).
438
+ WithOperator(filters.ContainsNone).
439
+ WithValueNumber(3.3, 0),
440
+ property: "numbers",
441
+ expectedIds: []string{id2, id3},
442
+ },
443
+ {
444
+ name: "contains all ints with int array",
445
+ where: filters.Where().
446
+ WithPath([]string{"ints"}).
447
+ WithOperator(filters.ContainsAll).
448
+ WithValueInt(1, 2, 3),
449
+ property: "ints",
450
+ expectedIds: []string{id1},
451
+ },
452
+ {
453
+ name: "contains any ints with int array",
454
+ where: filters.Where().
455
+ WithPath([]string{"ints"}).
456
+ WithOperator(filters.ContainsAny).
457
+ WithValueInt(1, 2, 3),
458
+ property: "ints",
459
+ expectedIds: []string{id1, id2, id3},
460
+ },
461
+ {
462
+ name: "contains none ints with int array",
463
+ where: filters.Where().
464
+ WithPath([]string{"ints"}).
465
+ WithOperator(filters.ContainsNone).
466
+ WithValueInt(3, 0),
467
+ property: "ints",
468
+ expectedIds: []string{id2, id3},
469
+ },
470
+ {
471
+ name: "contains all bools with bool array",
472
+ where: filters.Where().
473
+ WithPath([]string{"bools"}).
474
+ WithOperator(filters.ContainsAll).
475
+ WithValueBoolean(true, false, true),
476
+ property: "bools",
477
+ expectedIds: []string{id1, id2},
478
+ },
479
+ {
480
+ name: "contains any bools with bool array",
481
+ where: filters.Where().
482
+ WithPath([]string{"bools"}).
483
+ WithOperator(filters.ContainsAny).
484
+ WithValueBoolean(true, false),
485
+ property: "bools",
486
+ expectedIds: []string{id1, id2, id3},
487
+ },
488
+ {
489
+ name: "contains none bools with bool array",
490
+ where: filters.Where().
491
+ WithPath([]string{"bools"}).
492
+ WithOperator(filters.ContainsNone).
493
+ WithValueBoolean(false),
494
+ property: "bools",
495
+ expectedIds: []string{id3},
496
+ },
497
+ {
498
+ name: "contains all uuids with uuid array",
499
+ where: filters.Where().
500
+ WithPath([]string{"uuids"}).
501
+ WithOperator(filters.ContainsAll).
502
+ WithValueText(id1, id2, id3),
503
+ property: "uuids",
504
+ expectedIds: []string{id1},
505
+ },
506
+ {
507
+ name: "contains any uuids with uuid array",
508
+ where: filters.Where().
509
+ WithPath([]string{"uuids"}).
510
+ WithOperator(filters.ContainsAny).
511
+ WithValueText(id1, id2, id3),
512
+ property: "uuids",
513
+ expectedIds: []string{id1, id2, id3},
514
+ },
515
+ {
516
+ name: "contains none uuids with uuid array",
517
+ where: filters.Where().
518
+ WithPath([]string{"uuids"}).
519
+ WithOperator(filters.ContainsNone).
520
+ WithValueText(id3, "FFFFFFFF-FFFF-0000-0000-000000000000"),
521
+ property: "uuids",
522
+ expectedIds: []string{id2, id3},
523
+ },
524
+ {
525
+ name: "contains all dates with dates array",
526
+ where: filters.Where().
527
+ WithPath([]string{"dates"}).
528
+ WithOperator(filters.ContainsAll).
529
+ WithValueDate(
530
+ mustGetTime("2009-11-01T23:00:00Z"),
531
+ mustGetTime("2009-11-02T23:00:00Z"),
532
+ mustGetTime("2009-11-03T23:00:00Z"),
533
+ ),
534
+ property: "dates",
535
+ expectedIds: []string{id1},
536
+ },
537
+ {
538
+ name: "contains any dates with dates array",
539
+ where: filters.Where().
540
+ WithPath([]string{"dates"}).
541
+ WithOperator(filters.ContainsAny).
542
+ WithValueDate(
543
+ mustGetTime("2009-11-01T23:00:00Z"),
544
+ mustGetTime("2009-11-02T23:00:00Z"),
545
+ mustGetTime("2009-11-03T23:00:00Z"),
546
+ ),
547
+ property: "dates",
548
+ expectedIds: []string{id1, id2, id3},
549
+ },
550
+ {
551
+ name: "contains none dates with dates array",
552
+ where: filters.Where().
553
+ WithPath([]string{"dates"}).
554
+ WithOperator(filters.ContainsNone).
555
+ WithValueDate(
556
+ mustGetTime("2009-11-03T23:00:00Z"),
557
+ mustGetTime("1970-01-01T00:00:00Z"),
558
+ ),
559
+ property: "dates",
560
+ expectedIds: []string{id2, id3},
561
+ },
562
+ {
563
+ name: "complex contains all ints and all numbers with AND on int array",
564
+ where: filters.Where().
565
+ WithOperator(filters.And).
566
+ WithOperands([]*filters.WhereBuilder{
567
+ filters.Where().
568
+ WithPath([]string{"numbers"}).
569
+ WithOperator(filters.ContainsAll).
570
+ WithValueNumber(1.1, 2.2, 3.3),
571
+ filters.Where().
572
+ WithPath([]string{"ints"}).
573
+ WithOperator(filters.ContainsAll).
574
+ WithValueInt(1, 2, 3),
575
+ }),
576
+ property: "ints",
577
+ expectedIds: []string{id1},
578
+ },
579
+ {
580
+ name: "complex contains any ints and all numbers and none texts with OR",
581
+ where: filters.Where().
582
+ WithOperator(filters.Or).
583
+ WithOperands([]*filters.WhereBuilder{
584
+ filters.Where().
585
+ WithPath([]string{"numbers"}).
586
+ WithOperator(filters.ContainsAll).
587
+ WithValueNumber(1.1, 2.2, 3.3),
588
+ filters.Where().
589
+ WithPath([]string{"ints"}).
590
+ WithOperator(filters.ContainsAny).
591
+ WithValueInt(3),
592
+ filters.Where().
593
+ WithPath([]string{"authors"}).
594
+ WithOperator(filters.ContainsNone).
595
+ WithValueString("Jenny", "Missing"),
596
+ }),
597
+ property: "ints",
598
+ expectedIds: []string{id1, id3},
599
+ },
600
+ // Contains operator with primitives
601
+ {
602
+ name: "contains any author with string",
603
+ where: filters.Where().
604
+ WithPath([]string{"author"}).
605
+ WithOperator(filters.ContainsAny).
606
+ WithValueString("John", "Jenny", "Joseph"),
607
+ property: "author",
608
+ expectedIds: []string{id1, id2, id3},
609
+ },
610
+ {
611
+ name: "contains any color with text",
612
+ where: filters.Where().
613
+ WithPath([]string{"color"}).
614
+ WithOperator(filters.ContainsAny).
615
+ WithValueText("red", "blue", "green"),
616
+ property: "color",
617
+ expectedIds: []string{id1, id2, id3},
618
+ },
619
+ {
620
+ name: "contains any number with number",
621
+ where: filters.Where().
622
+ WithPath([]string{"number"}).
623
+ WithOperator(filters.ContainsAny).
624
+ WithValueNumber(1.1, 2.2, 3.3),
625
+ property: "number",
626
+ expectedIds: []string{id1, id2, id3},
627
+ },
628
+ {
629
+ name: "contains any int with int",
630
+ where: filters.Where().
631
+ WithPath([]string{"int"}).
632
+ WithOperator(filters.ContainsAny).
633
+ WithValueInt(1, 2, 3),
634
+ property: "int",
635
+ expectedIds: []string{id1, id2, id3},
636
+ },
637
+ {
638
+ name: "contains any bool with bool",
639
+ where: filters.Where().
640
+ WithPath([]string{"bool"}).
641
+ WithOperator(filters.ContainsAny).
642
+ WithValueBoolean(true, false, true),
643
+ property: "bool",
644
+ expectedIds: []string{id1, id2, id3},
645
+ },
646
+ {
647
+ name: "contains any uuid with uuid",
648
+ where: filters.Where().
649
+ WithPath([]string{"uuid"}).
650
+ WithOperator(filters.ContainsAny).
651
+ WithValueText(id1, id2, id3),
652
+ property: "uuid",
653
+ expectedIds: []string{id1, id2, id3},
654
+ },
655
+ {
656
+ name: "contains any uuid with id",
657
+ where: filters.Where().
658
+ WithPath([]string{"id"}).
659
+ WithOperator(filters.ContainsAny).
660
+ WithValueText(id1, id2, id3),
661
+ property: "uuid",
662
+ expectedIds: []string{id1, id2, id3},
663
+ },
664
+ {
665
+ name: "contains any date with date",
666
+ where: filters.Where().
667
+ WithPath([]string{"date"}).
668
+ WithOperator(filters.ContainsAny).
669
+ WithValueDate(
670
+ mustGetTime("2009-11-01T23:00:00Z"), mustGetTime("2009-11-02T23:00:00Z"), mustGetTime("2009-11-03T23:00:00Z"),
671
+ ),
672
+ property: "date",
673
+ expectedIds: []string{id1, id2, id3},
674
+ },
675
+
676
+ {
677
+ name: "contains all author with string",
678
+ where: filters.Where().
679
+ WithPath([]string{"author"}).
680
+ WithOperator(filters.ContainsAll).
681
+ WithValueString("Jenny"),
682
+ property: "author",
683
+ expectedIds: []string{id2},
684
+ },
685
+ {
686
+ name: "contains all color with text",
687
+ where: filters.Where().
688
+ WithPath([]string{"color"}).
689
+ WithOperator(filters.ContainsAll).
690
+ WithValueText("blue"),
691
+ property: "color",
692
+ expectedIds: []string{id2},
693
+ },
694
+ {
695
+ name: "contains all number with number",
696
+ where: filters.Where().
697
+ WithPath([]string{"number"}).
698
+ WithOperator(filters.ContainsAll).
699
+ WithValueNumber(2.2),
700
+ property: "number",
701
+ expectedIds: []string{id2},
702
+ },
703
+ {
704
+ name: "contains all int with int",
705
+ where: filters.Where().
706
+ WithPath([]string{"int"}).
707
+ WithOperator(filters.ContainsAll).
708
+ WithValueInt(2),
709
+ property: "int",
710
+ expectedIds: []string{id2},
711
+ },
712
+ {
713
+ name: "contains all bool with bool",
714
+ where: filters.Where().
715
+ WithPath([]string{"bool"}).
716
+ WithOperator(filters.ContainsAll).
717
+ WithValueBoolean(false),
718
+ property: "bool",
719
+ expectedIds: []string{id2},
720
+ },
721
+ {
722
+ name: "contains all uuid with uuid",
723
+ where: filters.Where().
724
+ WithPath([]string{"uuid"}).
725
+ WithOperator(filters.ContainsAll).
726
+ WithValueText(id2),
727
+ property: "uuid",
728
+ expectedIds: []string{id2},
729
+ },
730
+ {
731
+ name: "contains all date with date",
732
+ where: filters.Where().
733
+ WithPath([]string{"date"}).
734
+ WithOperator(filters.ContainsAll).
735
+ WithValueDate(mustGetTime("2009-11-02T23:00:00Z")),
736
+ property: "date",
737
+ expectedIds: []string{id2},
738
+ },
739
+
740
+ {
741
+ name: "contains none author with string",
742
+ where: filters.Where().
743
+ WithPath([]string{"author"}).
744
+ WithOperator(filters.ContainsNone).
745
+ WithValueString("Jenny", "Joseph"),
746
+ property: "author",
747
+ expectedIds: []string{id1},
748
+ },
749
+ {
750
+ name: "contains none color with text",
751
+ where: filters.Where().
752
+ WithPath([]string{"color"}).
753
+ WithOperator(filters.ContainsNone).
754
+ WithValueText("blue", "green"),
755
+ property: "color",
756
+ expectedIds: []string{id1},
757
+ },
758
+ {
759
+ name: "contains none number with number",
760
+ where: filters.Where().
761
+ WithPath([]string{"number"}).
762
+ WithOperator(filters.ContainsNone).
763
+ WithValueNumber(2.2, 3.3),
764
+ property: "number",
765
+ expectedIds: []string{id1},
766
+ },
767
+ {
768
+ name: "contains none int with int",
769
+ where: filters.Where().
770
+ WithPath([]string{"int"}).
771
+ WithOperator(filters.ContainsNone).
772
+ WithValueInt(2, 3),
773
+ property: "int",
774
+ expectedIds: []string{id1},
775
+ },
776
+ {
777
+ name: "contains none bool with bool",
778
+ where: filters.Where().
779
+ WithPath([]string{"bool"}).
780
+ WithOperator(filters.ContainsNone).
781
+ WithValueBoolean(false),
782
+ property: "bool",
783
+ expectedIds: []string{id1, id3},
784
+ },
785
+ {
786
+ name: "contains none uuid with uuid",
787
+ where: filters.Where().
788
+ WithPath([]string{"uuid"}).
789
+ WithOperator(filters.ContainsNone).
790
+ WithValueText(id2, id3),
791
+ property: "uuid",
792
+ expectedIds: []string{id1},
793
+ },
794
+ {
795
+ name: "contains none date with date",
796
+ where: filters.Where().
797
+ WithPath([]string{"date"}).
798
+ WithOperator(filters.ContainsNone).
799
+ WithValueDate(
800
+ mustGetTime("2009-11-02T23:00:00Z"),
801
+ mustGetTime("2009-11-03T23:00:00Z"),
802
+ ),
803
+ property: "date",
804
+ expectedIds: []string{id1},
805
+ },
806
+
807
+ {
808
+ name: "contains all authors with string array and nearText",
809
+ where: filters.Where().
810
+ WithPath([]string{"authors"}).
811
+ WithOperator(filters.ContainsAll).
812
+ WithValueString("John", "Jenny", "Joseph"),
813
+ property: "authors",
814
+ nearText: client.GraphQL().NearTextArgBuilder().
815
+ WithConcepts([]string{"John"}),
816
+ expectedIds: []string{id1},
817
+ },
818
+ }
819
+ for _, tt := range tests {
820
+ t.Run(tt.name, func(t *testing.T) {
821
+ fields := []graphql.Field{
822
+ {Name: tt.property},
823
+ {Name: "_additional", Fields: []graphql.Field{{Name: "id"}}},
824
+ }
825
+ resp, err := client.GraphQL().Get().
826
+ WithClassName(className).
827
+ WithWhere(tt.where).
828
+ WithFields(fields...).
829
+ WithNearText(tt.nearText).
830
+ Do(context.TODO())
831
+ require.Nil(t, err)
832
+ resultIds := acceptance_with_go_client.GetIds(t, resp, className)
833
+ assert.Len(t, resultIds, len(tt.expectedIds))
834
+ assert.ElementsMatch(t, resultIds, tt.expectedIds)
835
+ })
836
+ }
837
+ })
838
+ })
839
+ }
840
+ }
841
+
842
+ func testContainsMovies(host string) func(t *testing.T) {
843
+ return func(t *testing.T) {
844
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: host})
845
+ require.NoError(t, err)
846
+
847
+ collectionName := "Movies"
848
+ movies := []struct {
849
+ id string
850
+ title string
851
+ director string
852
+ languages []string
853
+ }{
854
+ {
855
+ id: "00000000-0000-0000-0000-000000000000",
856
+ title: "Braveheart",
857
+ director: "Mel Gibson",
858
+ languages: []string{"English", "French", "Latin", "Scottish Gaelic"},
859
+ },
860
+ {
861
+ id: "00000000-0000-0000-0000-000000000001",
862
+ title: "A Prophet",
863
+ director: "Mel Gibson",
864
+ languages: []string{"French", "Arabic", "Corsican"},
865
+ },
866
+ {
867
+ id: "00000000-0000-0000-0000-000000000002",
868
+ title: "Avatar",
869
+ director: "James Cameron",
870
+ languages: []string{"Portugese", "Czech", "Romanian", "German"},
871
+ },
872
+ {
873
+ id: "00000000-0000-0000-0000-000000000003",
874
+ title: "Spectre",
875
+ director: "Sam Mendes",
876
+ languages: []string{"Spanish", "Finnish", "Polish"},
877
+ },
878
+ {
879
+ id: "00000000-0000-0000-0000-000000000004",
880
+ title: "The Dark Knight Rises",
881
+ director: "Christopher Nolan",
882
+ languages: []string{"English", "German", "Dutch", "Swedish"},
883
+ },
884
+ {
885
+ id: "00000000-0000-0000-0000-000000000005",
886
+ title: "Incendies",
887
+ director: "Denis Villeneuve",
888
+ languages: []string{"English", "French", "Polish", "Arabic"},
889
+ },
890
+ }
891
+
892
+ cleanup := func() {
893
+ err := client.Schema().AllDeleter().Do(context.Background())
894
+ require.Nil(t, err)
895
+ }
896
+ defer cleanup()
897
+
898
+ t.Run("create and populate collection", func(t *testing.T) {
899
+ cleanup()
900
+ class := &models.Class{
901
+ Class: collectionName,
902
+ Properties: []*models.Property{
903
+ {
904
+ Name: "title",
905
+ DataType: schema.DataTypeText.PropString(),
906
+ Tokenization: models.PropertyTokenizationField,
907
+ },
908
+ {
909
+ Name: "director",
910
+ DataType: schema.DataTypeText.PropString(),
911
+ Tokenization: models.PropertyTokenizationField,
912
+ },
913
+ {
914
+ Name: "languages",
915
+ DataType: schema.DataTypeTextArray.PropString(),
916
+ Tokenization: models.PropertyTokenizationField,
917
+ },
918
+ },
919
+ }
920
+ err := client.Schema().ClassCreator().WithClass(class).Do(context.Background())
921
+ require.NoError(t, err)
922
+ // Give time for the schema to replicate and graphql to rebuild it for it's queries
923
+ time.Sleep(3 * time.Second)
924
+
925
+ for i := range movies {
926
+ _, err := client.Data().Creator().
927
+ WithClassName(collectionName).
928
+ WithID(movies[i].id).
929
+ WithProperties(map[string]interface{}{
930
+ "title": movies[i].title,
931
+ "director": movies[i].director,
932
+ "languages": movies[i].languages,
933
+ }).
934
+ Do(context.Background())
935
+ require.NoError(t, err)
936
+ }
937
+ })
938
+
939
+ t.Run("contains", func(t *testing.T) {
940
+ tests := []struct {
941
+ name string
942
+ where *filters.WhereBuilder
943
+ property string
944
+ expectedIds []string
945
+ }{
946
+ {
947
+ name: "contains any languages (1)",
948
+ where: filters.Where().
949
+ WithPath([]string{"languages"}).
950
+ WithOperator(filters.ContainsAny).
951
+ WithValueString("English", "German"),
952
+ property: "languages",
953
+ expectedIds: []string{movies[0].id, movies[2].id, movies[4].id, movies[5].id},
954
+ },
955
+ {
956
+ name: "contains all languages (1)",
957
+ where: filters.Where().
958
+ WithPath([]string{"languages"}).
959
+ WithOperator(filters.ContainsAll).
960
+ WithValueString("English", "German"),
961
+ property: "languages",
962
+ expectedIds: []string{movies[4].id},
963
+ },
964
+ {
965
+ name: "contains none languages (1)",
966
+ where: filters.Where().
967
+ WithPath([]string{"languages"}).
968
+ WithOperator(filters.ContainsNone).
969
+ WithValueString("English", "German"),
970
+ property: "languages",
971
+ expectedIds: []string{movies[1].id, movies[3].id},
972
+ },
973
+
974
+ {
975
+ name: "contains any languages (2)",
976
+ where: filters.Where().
977
+ WithPath([]string{"languages"}).
978
+ WithOperator(filters.ContainsAny).
979
+ WithValueString("French", "Polish"),
980
+ property: "languages",
981
+ expectedIds: []string{movies[0].id, movies[1].id, movies[3].id, movies[5].id},
982
+ },
983
+ {
984
+ name: "contains all languages (2)",
985
+ where: filters.Where().
986
+ WithPath([]string{"languages"}).
987
+ WithOperator(filters.ContainsAll).
988
+ WithValueString("French", "Polish"),
989
+ property: "languages",
990
+ expectedIds: []string{movies[5].id},
991
+ },
992
+ {
993
+ name: "contains none languages (2)",
994
+ where: filters.Where().
995
+ WithPath([]string{"languages"}).
996
+ WithOperator(filters.ContainsNone).
997
+ WithValueString("French", "Polish"),
998
+ property: "languages",
999
+ expectedIds: []string{movies[2].id, movies[4].id},
1000
+ },
1001
+
1002
+ {
1003
+ name: "contains any languages (3)",
1004
+ where: filters.Where().
1005
+ WithPath([]string{"languages"}).
1006
+ WithOperator(filters.ContainsAny).
1007
+ WithValueString("Portugese", "Czech", "Romanian", "German"),
1008
+ property: "languages",
1009
+ expectedIds: []string{movies[2].id, movies[4].id},
1010
+ },
1011
+ {
1012
+ name: "contains all languages (3)",
1013
+ where: filters.Where().
1014
+ WithPath([]string{"languages"}).
1015
+ WithOperator(filters.ContainsAll).
1016
+ WithValueString("Portugese", "Czech", "Romanian", "German"),
1017
+ property: "languages",
1018
+ expectedIds: []string{movies[2].id},
1019
+ },
1020
+ {
1021
+ name: "contains none languages (3)",
1022
+ where: filters.Where().
1023
+ WithPath([]string{"languages"}).
1024
+ WithOperator(filters.ContainsNone).
1025
+ WithValueString("Portugese", "Czech", "Romanian", "German"),
1026
+ property: "languages",
1027
+ expectedIds: []string{movies[0].id, movies[1].id, movies[3].id, movies[5].id},
1028
+ },
1029
+ }
1030
+ for _, tt := range tests {
1031
+ t.Run(tt.name, func(t *testing.T) {
1032
+ fields := []graphql.Field{
1033
+ {Name: tt.property},
1034
+ {Name: "_additional", Fields: []graphql.Field{{Name: "id"}}},
1035
+ }
1036
+ resp, err := client.GraphQL().Get().
1037
+ WithClassName(collectionName).
1038
+ WithWhere(tt.where).
1039
+ WithFields(fields...).
1040
+ Do(context.Background())
1041
+ require.NoError(t, err)
1042
+ resultIds := acceptance_with_go_client.GetIds(t, resp, collectionName)
1043
+ assert.ElementsMatch(t, resultIds, tt.expectedIds)
1044
+ })
1045
+ }
1046
+ })
1047
+
1048
+ }
1049
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/filters_tests/contains_text_test.go ADDED
@@ -0,0 +1,472 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package filters_tests
13
+
14
+ import (
15
+ "context"
16
+ "fmt"
17
+ "testing"
18
+ "time"
19
+
20
+ acceptance_with_go_client "acceptance_tests_with_client"
21
+
22
+ "github.com/go-openapi/strfmt"
23
+ "github.com/stretchr/testify/require"
24
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
25
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/filters"
26
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/graphql"
27
+ "github.com/weaviate/weaviate/entities/models"
28
+ "github.com/weaviate/weaviate/entities/schema"
29
+ )
30
+
31
+ func testContainsText(host string) func(t *testing.T) {
32
+ return func(t *testing.T) {
33
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: host})
34
+ require.NoError(t, err)
35
+
36
+ defer func() {
37
+ err := client.Schema().AllDeleter().Do(context.Background())
38
+ require.NoError(t, err)
39
+ }()
40
+
41
+ ctx := context.Background()
42
+ className := "ContainsText"
43
+ id := "be6452f4-5db6-4a41-bfef-ff5dffd4ab16"
44
+ texts := []string{
45
+ " Hello You*-beautiful_world?!",
46
+ "HoW yOU_DOin? ",
47
+ }
48
+
49
+ t.Run("init data", func(t *testing.T) {
50
+ class := &models.Class{
51
+ Class: className,
52
+ Properties: []*models.Property{
53
+ {
54
+ Name: "textField",
55
+ DataType: schema.DataTypeText.PropString(),
56
+ Tokenization: models.PropertyTokenizationField,
57
+ },
58
+ {
59
+ Name: "textWhitespace",
60
+ DataType: schema.DataTypeText.PropString(),
61
+ Tokenization: models.PropertyTokenizationWhitespace,
62
+ },
63
+ {
64
+ Name: "textLowercase",
65
+ DataType: schema.DataTypeText.PropString(),
66
+ Tokenization: models.PropertyTokenizationLowercase,
67
+ },
68
+ {
69
+ Name: "textWord",
70
+ DataType: schema.DataTypeText.PropString(),
71
+ Tokenization: models.PropertyTokenizationWord,
72
+ },
73
+
74
+ {
75
+ Name: "textsField",
76
+ DataType: schema.DataTypeTextArray.PropString(),
77
+ Tokenization: models.PropertyTokenizationField,
78
+ },
79
+ {
80
+ Name: "textsWhitespace",
81
+ DataType: schema.DataTypeTextArray.PropString(),
82
+ Tokenization: models.PropertyTokenizationWhitespace,
83
+ },
84
+ {
85
+ Name: "textsLowercase",
86
+ DataType: schema.DataTypeTextArray.PropString(),
87
+ Tokenization: models.PropertyTokenizationLowercase,
88
+ },
89
+ {
90
+ Name: "textsWord",
91
+ DataType: schema.DataTypeTextArray.PropString(),
92
+ Tokenization: models.PropertyTokenizationWord,
93
+ },
94
+ },
95
+ }
96
+
97
+ err := client.Schema().ClassCreator().
98
+ WithClass(class).
99
+ Do(ctx)
100
+ require.NoError(t, err)
101
+
102
+ wrap, err := client.Data().Creator().
103
+ WithClassName(className).
104
+ WithID(id).
105
+ WithProperties(map[string]interface{}{
106
+ "textField": texts[0],
107
+ "textWhitespace": texts[0],
108
+ "textLowercase": texts[0],
109
+ "textWord": texts[0],
110
+ "textsField": texts,
111
+ "textsWhitespace": texts,
112
+ "textsLowercase": texts,
113
+ "textsWord": texts,
114
+ }).
115
+ Do(ctx)
116
+ require.NoError(t, err)
117
+ require.NotNil(t, wrap)
118
+ require.NotNil(t, wrap.Object)
119
+ require.Equal(t, strfmt.UUID(id), wrap.Object.ID)
120
+
121
+ // Give time for graphql to receive and rebuild the schema internally
122
+ time.Sleep(3 * time.Second)
123
+ })
124
+
125
+ t.Run("search using contains", func(t *testing.T) {
126
+ type testCase struct {
127
+ propName string
128
+ operator filters.WhereOperator
129
+ values []string
130
+ expectedFound bool
131
+ }
132
+
133
+ testCases := []testCase{}
134
+ testCases = append(testCases,
135
+ testCase{
136
+ propName: "textField",
137
+ operator: filters.ContainsAny,
138
+ values: []string{"Hello You*-beautiful_world?!", "HoW yOU_DOin?"},
139
+ expectedFound: true,
140
+ },
141
+ testCase{
142
+ propName: "textField",
143
+ operator: filters.ContainsAll,
144
+ values: []string{"Hello You*-beautiful_world?!", "HoW yOU_DOin?"},
145
+ expectedFound: false,
146
+ },
147
+ testCase{
148
+ propName: "textField",
149
+ operator: filters.ContainsNone,
150
+ values: []string{"Hello You*-beautiful_world?!", "HoW yOU_DOin?"},
151
+ expectedFound: false,
152
+ },
153
+ testCase{
154
+ propName: "textsField",
155
+ operator: filters.ContainsAny,
156
+ values: []string{"Hello You*-beautiful_world?!", "HoW yOU_DOin?"},
157
+ expectedFound: true,
158
+ },
159
+ testCase{
160
+ propName: "textsField",
161
+ operator: filters.ContainsAll,
162
+ values: []string{"Hello You*-beautiful_world?!", "HoW yOU_DOin?"},
163
+ expectedFound: true,
164
+ },
165
+ testCase{
166
+ propName: "textsField",
167
+ operator: filters.ContainsNone,
168
+ values: []string{"Hello You*-beautiful_world?!", "HoW yOU_DOin?"},
169
+ expectedFound: false,
170
+ },
171
+
172
+ testCase{
173
+ propName: "textWord",
174
+ operator: filters.ContainsAny,
175
+ values: []string{"HELLO", "doin"},
176
+ expectedFound: true,
177
+ },
178
+ testCase{
179
+ propName: "textWord",
180
+ operator: filters.ContainsAll,
181
+ values: []string{"HELLO", "doin"},
182
+ expectedFound: false,
183
+ },
184
+ testCase{
185
+ propName: "textWord",
186
+ operator: filters.ContainsNone,
187
+ values: []string{"HELLO", "doin"},
188
+ expectedFound: false,
189
+ },
190
+ testCase{
191
+ propName: "textsWord",
192
+ operator: filters.ContainsAny,
193
+ values: []string{"HELLO", "doin"},
194
+ expectedFound: true,
195
+ },
196
+ testCase{
197
+ propName: "textsWord",
198
+ operator: filters.ContainsAll,
199
+ values: []string{"HELLO", "doin"},
200
+ expectedFound: true,
201
+ },
202
+ testCase{
203
+ propName: "textsWord",
204
+ operator: filters.ContainsNone,
205
+ values: []string{"HELLO", "doin"},
206
+ expectedFound: false,
207
+ },
208
+
209
+ testCase{
210
+ propName: "textField",
211
+ operator: filters.ContainsAny,
212
+ values: []string{"Hello", "HoW"},
213
+ expectedFound: false,
214
+ },
215
+ testCase{
216
+ propName: "textField",
217
+ operator: filters.ContainsAll,
218
+ values: []string{"Hello", "HoW"},
219
+ expectedFound: false,
220
+ },
221
+ testCase{
222
+ propName: "textField",
223
+ operator: filters.ContainsNone,
224
+ values: []string{"Hello", "HoW"},
225
+ expectedFound: true,
226
+ },
227
+ testCase{
228
+ propName: "textsField",
229
+ operator: filters.ContainsAny,
230
+ values: []string{"Hello", "HoW"},
231
+ expectedFound: false,
232
+ },
233
+ testCase{
234
+ propName: "textsField",
235
+ operator: filters.ContainsAll,
236
+ values: []string{"Hello", "HoW"},
237
+ expectedFound: false,
238
+ },
239
+ testCase{
240
+ propName: "textsField",
241
+ operator: filters.ContainsNone,
242
+ values: []string{"Hello", "HoW"},
243
+ expectedFound: true,
244
+ },
245
+ testCase{
246
+ propName: "textWhitespace",
247
+ operator: filters.ContainsAny,
248
+ values: []string{"Hello", "HoW"},
249
+ expectedFound: true,
250
+ },
251
+ testCase{
252
+ propName: "textWhitespace",
253
+ operator: filters.ContainsAll,
254
+ values: []string{"Hello", "HoW"},
255
+ expectedFound: false,
256
+ },
257
+ testCase{
258
+ propName: "textWhitespace",
259
+ operator: filters.ContainsNone,
260
+ values: []string{"Hello", "HoW"},
261
+ expectedFound: false,
262
+ },
263
+ testCase{
264
+ propName: "textsWhitespace",
265
+ operator: filters.ContainsAny,
266
+ values: []string{"Hello", "HoW"},
267
+ expectedFound: true,
268
+ },
269
+ testCase{
270
+ propName: "textsWhitespace",
271
+ operator: filters.ContainsAll,
272
+ values: []string{"Hello", "HoW"},
273
+ expectedFound: true,
274
+ },
275
+ testCase{
276
+ propName: "textsWhitespace",
277
+ operator: filters.ContainsNone,
278
+ values: []string{"Hello", "HoW"},
279
+ expectedFound: false,
280
+ },
281
+ testCase{
282
+ propName: "textLowercase",
283
+ operator: filters.ContainsAny,
284
+ values: []string{"Hello", "HoW"},
285
+ expectedFound: true,
286
+ },
287
+ testCase{
288
+ propName: "textLowercase",
289
+ operator: filters.ContainsAll,
290
+ values: []string{"Hello", "HoW"},
291
+ expectedFound: false,
292
+ },
293
+ testCase{
294
+ propName: "textLowercase",
295
+ operator: filters.ContainsNone,
296
+ values: []string{"Hello", "HoW"},
297
+ expectedFound: false,
298
+ },
299
+ testCase{
300
+ propName: "textsLowercase",
301
+ operator: filters.ContainsAny,
302
+ values: []string{"Hello", "HoW"},
303
+ expectedFound: true,
304
+ },
305
+ testCase{
306
+ propName: "textsLowercase",
307
+ operator: filters.ContainsAll,
308
+ values: []string{"Hello", "HoW"},
309
+ expectedFound: true,
310
+ },
311
+ testCase{
312
+ propName: "textsLowercase",
313
+ operator: filters.ContainsNone,
314
+ values: []string{"Hello", "HoW"},
315
+ expectedFound: false,
316
+ },
317
+ testCase{
318
+ propName: "textWord",
319
+ operator: filters.ContainsAny,
320
+ values: []string{"Hello", "HoW"},
321
+ expectedFound: true,
322
+ },
323
+ testCase{
324
+ propName: "textWord",
325
+ operator: filters.ContainsAll,
326
+ values: []string{"Hello", "HoW"},
327
+ expectedFound: false,
328
+ },
329
+ testCase{
330
+ propName: "textWord",
331
+ operator: filters.ContainsNone,
332
+ values: []string{"Hello", "HoW"},
333
+ expectedFound: false,
334
+ },
335
+ testCase{
336
+ propName: "textsWord",
337
+ operator: filters.ContainsAny,
338
+ values: []string{"Hello", "HoW"},
339
+ expectedFound: true,
340
+ },
341
+ testCase{
342
+ propName: "textsWord",
343
+ operator: filters.ContainsAll,
344
+ values: []string{"Hello", "HoW"},
345
+ expectedFound: true,
346
+ },
347
+ testCase{
348
+ propName: "textsWord",
349
+ operator: filters.ContainsNone,
350
+ values: []string{"Hello", "HoW"},
351
+ expectedFound: false,
352
+ },
353
+ )
354
+
355
+ for _, propName := range []string{"textField", "textsField"} {
356
+ testCases = append(testCases,
357
+ testCase{
358
+ propName: propName,
359
+ operator: filters.ContainsAny,
360
+ values: []string{"hello", "world"},
361
+ expectedFound: false,
362
+ },
363
+ testCase{
364
+ propName: propName,
365
+ operator: filters.ContainsAll,
366
+ values: []string{"hello", "world"},
367
+ expectedFound: false,
368
+ },
369
+ testCase{
370
+ propName: propName,
371
+ operator: filters.ContainsNone,
372
+ values: []string{"hello", "world"},
373
+ expectedFound: true,
374
+ },
375
+ )
376
+ }
377
+ for _, propName := range []string{"textWhitespace", "textsWhitespace"} {
378
+ testCases = append(testCases,
379
+ testCase{
380
+ propName: propName,
381
+ operator: filters.ContainsAny,
382
+ values: []string{"hello", "world"},
383
+ expectedFound: false,
384
+ },
385
+ testCase{
386
+ propName: propName,
387
+ operator: filters.ContainsAll,
388
+ values: []string{"hello", "world"},
389
+ expectedFound: false,
390
+ },
391
+ testCase{
392
+ propName: propName,
393
+ operator: filters.ContainsNone,
394
+ values: []string{"hello", "world"},
395
+ expectedFound: true,
396
+ },
397
+ )
398
+ }
399
+ for _, propName := range []string{"textLowercase", "textsLowercase"} {
400
+ testCases = append(testCases,
401
+ testCase{
402
+ propName: propName,
403
+ operator: filters.ContainsAny,
404
+ values: []string{"hello", "world"},
405
+ expectedFound: true,
406
+ },
407
+ testCase{
408
+ propName: propName,
409
+ operator: filters.ContainsAll,
410
+ values: []string{"hello", "world"},
411
+ expectedFound: false,
412
+ },
413
+ testCase{
414
+ propName: propName,
415
+ operator: filters.ContainsNone,
416
+ values: []string{"hello", "world"},
417
+ expectedFound: false,
418
+ },
419
+ )
420
+ }
421
+ for _, propName := range []string{"textWord", "textsWord"} {
422
+ testCases = append(testCases,
423
+ testCase{
424
+ propName: propName,
425
+ operator: filters.ContainsAny,
426
+ values: []string{"hello", "world"},
427
+ expectedFound: true,
428
+ },
429
+ testCase{
430
+ propName: propName,
431
+ operator: filters.ContainsAll,
432
+ values: []string{"hello", "world"},
433
+ expectedFound: true,
434
+ },
435
+ testCase{
436
+ propName: propName,
437
+ operator: filters.ContainsNone,
438
+ values: []string{"hello", "world"},
439
+ expectedFound: false,
440
+ },
441
+ )
442
+ }
443
+
444
+ for _, tc := range testCases {
445
+ t.Run(fmt.Sprintf("%+v", tc), func(t *testing.T) {
446
+ where := filters.Where().
447
+ WithPath([]string{tc.propName}).
448
+ WithOperator(tc.operator).
449
+ WithValueText(tc.values...)
450
+ field := graphql.Field{
451
+ Name: "_additional",
452
+ Fields: []graphql.Field{{Name: "id"}},
453
+ }
454
+
455
+ resp, err := client.GraphQL().Get().
456
+ WithClassName(className).
457
+ WithWhere(where).
458
+ WithFields(field).
459
+ Do(ctx)
460
+ require.NoError(t, err)
461
+
462
+ ids := acceptance_with_go_client.GetIds(t, resp, className)
463
+ if tc.expectedFound {
464
+ require.ElementsMatch(t, ids, []string{id})
465
+ } else {
466
+ require.Empty(t, ids)
467
+ }
468
+ })
469
+ }
470
+ })
471
+ }
472
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/filters_tests/numerical_filters_test.go ADDED
@@ -0,0 +1,442 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package filters_tests
13
+
14
+ import (
15
+ "context"
16
+ "math/rand"
17
+ "testing"
18
+ "time"
19
+
20
+ "github.com/go-openapi/strfmt"
21
+ "github.com/google/uuid"
22
+ "github.com/stretchr/testify/assert"
23
+ "github.com/stretchr/testify/require"
24
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
25
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/filters"
26
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/graphql"
27
+ "github.com/weaviate/weaviate/entities/models"
28
+ "github.com/weaviate/weaviate/entities/schema"
29
+ )
30
+
31
+ func testNumericalFilters(host string) func(t *testing.T) {
32
+ return func(t *testing.T) {
33
+ className := "NumericalClass"
34
+
35
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: host})
36
+ require.NoError(t, err)
37
+
38
+ cleanup := func() {
39
+ err := client.Schema().AllDeleter().Do(context.Background())
40
+ require.Nil(t, err)
41
+ }
42
+ cleanup()
43
+ defer cleanup()
44
+
45
+ randPool := 100
46
+ randInts := make([]int64, randPool)
47
+ randNumbers := make([]float64, randPool)
48
+ randDates := make([]time.Time, randPool)
49
+ selectedRandIds := make([]int, 0, 6)
50
+ r := rand.New(rand.NewSource(time.Now().UnixNano()))
51
+
52
+ batches := 50
53
+ perBatch := 200
54
+
55
+ t.Run("create schema", func(t *testing.T) {
56
+ vTrue := true
57
+ vFalse := false
58
+
59
+ class := &models.Class{
60
+ Class: className,
61
+ Vectorizer: "none",
62
+ Properties: []*models.Property{
63
+ {
64
+ Name: "int_filterable",
65
+ DataType: schema.DataTypeInt.PropString(),
66
+ IndexFilterable: &vTrue,
67
+ IndexRangeFilters: &vFalse,
68
+ },
69
+ {
70
+ Name: "int_rangeable",
71
+ DataType: schema.DataTypeInt.PropString(),
72
+ IndexFilterable: &vFalse,
73
+ IndexRangeFilters: &vTrue,
74
+ },
75
+ {
76
+ Name: "number_filterable",
77
+ DataType: schema.DataTypeNumber.PropString(),
78
+ IndexFilterable: &vTrue,
79
+ IndexRangeFilters: &vFalse,
80
+ },
81
+ {
82
+ Name: "number_rangeable",
83
+ DataType: schema.DataTypeNumber.PropString(),
84
+ IndexFilterable: &vFalse,
85
+ IndexRangeFilters: &vTrue,
86
+ },
87
+ {
88
+ Name: "date_filterable",
89
+ DataType: schema.DataTypeDate.PropString(),
90
+ IndexFilterable: &vTrue,
91
+ IndexRangeFilters: &vFalse,
92
+ },
93
+ {
94
+ Name: "date_rangeable",
95
+ DataType: schema.DataTypeDate.PropString(),
96
+ IndexFilterable: &vFalse,
97
+ IndexRangeFilters: &vTrue,
98
+ },
99
+ {
100
+ Name: "delete",
101
+ DataType: schema.DataTypeBoolean.PropString(),
102
+ },
103
+ },
104
+ }
105
+
106
+ err = client.Schema().ClassCreator().
107
+ WithClass(class).
108
+ Do(context.Background())
109
+ require.NoError(t, err)
110
+ })
111
+
112
+ t.Run("generate random data", func(t *testing.T) {
113
+ for i := 0; i < randPool; i++ {
114
+ randInts[i] = int64(r.Uint32())
115
+ randNumbers[i] = r.Float64()
116
+ randDates[i] = time.Unix(0, 0).Add(time.Hour * time.Duration(r.Int63n(1_000_000)))
117
+ }
118
+
119
+ uniqueSelectedRandIds := map[int]struct{}{}
120
+ objects := make([]*models.Object, 0, perBatch)
121
+ for batch := 0; batch < batches; batch++ {
122
+ objects = objects[:0]
123
+
124
+ for i := 0; i < perBatch; i++ {
125
+ randId := r.Intn(randPool)
126
+ toDelete := i%2 == 0
127
+ // collect only the ones not to be deleted later on
128
+ if !toDelete {
129
+ uniqueSelectedRandIds[randId] = struct{}{}
130
+ }
131
+ uuid_, err := uuid.NewRandom()
132
+ require.NoError(t, err)
133
+
134
+ objects = append(objects, &models.Object{
135
+ Class: className,
136
+ ID: strfmt.UUID(uuid_.String()),
137
+ Properties: map[string]interface{}{
138
+ "int_filterable": randInts[randId],
139
+ "int_rangeable": randInts[randId],
140
+ "number_filterable": randNumbers[randId],
141
+ "number_rangeable": randNumbers[randId],
142
+ "date_filterable": randDates[randId],
143
+ "date_rangeable": randDates[randId],
144
+ "delete": toDelete,
145
+ },
146
+ })
147
+ }
148
+
149
+ responses, err := client.Batch().ObjectsBatcher().
150
+ WithObjects(objects...).
151
+ Do(context.Background())
152
+ require.NoError(t, err)
153
+ require.Len(t, responses, perBatch)
154
+
155
+ for _, response := range responses {
156
+ s := response.Result.Status
157
+ require.Equal(t, "SUCCESS", *s)
158
+ }
159
+ }
160
+
161
+ i, c := 0, cap(selectedRandIds)
162
+ for id := range uniqueSelectedRandIds {
163
+ if i == c {
164
+ break
165
+ }
166
+ selectedRandIds = append(selectedRandIds, id)
167
+ i++
168
+ }
169
+ for j := i; j < c; j++ {
170
+ selectedRandIds = append(selectedRandIds, selectedRandIds[j-i])
171
+ }
172
+ })
173
+
174
+ gqlGet := func(where *filters.WhereBuilder) []string {
175
+ resp, err := client.GraphQL().Get().
176
+ WithClassName(className).
177
+ WithLimit(batches * perBatch).
178
+ WithWhere(where).
179
+ WithFields(graphql.Field{
180
+ Name: "_additional", Fields: []graphql.Field{{Name: "id"}},
181
+ }).
182
+ Do(context.Background())
183
+ require.NoError(t, err)
184
+ require.Empty(t, resp.Errors)
185
+
186
+ results := resp.Data["Get"].(map[string]interface{})[className].([]interface{})
187
+ ids := make([]string, len(results))
188
+ for i := range ids {
189
+ ids[i] = results[i].(map[string]interface{})["_additional"].(map[string]interface{})["id"].(string)
190
+ }
191
+ return ids
192
+ }
193
+ equalInt := func(propName string, val int64) []string {
194
+ return gqlGet(filters.Where().
195
+ WithPath([]string{propName}).
196
+ WithOperator(filters.Equal).
197
+ WithValueInt(val))
198
+ }
199
+ equalNumber := func(propName string, val float64) []string {
200
+ return gqlGet(filters.Where().
201
+ WithPath([]string{propName}).
202
+ WithOperator(filters.Equal).
203
+ WithValueNumber(val))
204
+ }
205
+ equalDate := func(propName string, val time.Time) []string {
206
+ return gqlGet(filters.Where().
207
+ WithPath([]string{propName}).
208
+ WithOperator(filters.Equal).
209
+ WithValueDate(val))
210
+ }
211
+ unionInt := func(propName string, val1, val2 int64) []string {
212
+ return gqlGet(filters.Where().
213
+ WithOperator(filters.Or).
214
+ WithOperands(
215
+ []*filters.WhereBuilder{
216
+ filters.Where().
217
+ WithPath([]string{propName}).
218
+ WithOperator(filters.LessThan).
219
+ WithValueInt(val1),
220
+ filters.Where().
221
+ WithPath([]string{propName}).
222
+ WithOperator(filters.GreaterThanEqual).
223
+ WithValueInt(val2),
224
+ }))
225
+ }
226
+ unionNumber := func(propName string, val1, val2 float64) []string {
227
+ return gqlGet(filters.Where().
228
+ WithOperator(filters.Or).
229
+ WithOperands(
230
+ []*filters.WhereBuilder{
231
+ filters.Where().
232
+ WithPath([]string{propName}).
233
+ WithOperator(filters.LessThan).
234
+ WithValueNumber(val1),
235
+ filters.Where().
236
+ WithPath([]string{propName}).
237
+ WithOperator(filters.GreaterThanEqual).
238
+ WithValueNumber(val2),
239
+ }))
240
+ }
241
+ unionDate := func(propName string, val1, val2 time.Time) []string {
242
+ return gqlGet(filters.Where().
243
+ WithOperator(filters.Or).
244
+ WithOperands(
245
+ []*filters.WhereBuilder{
246
+ filters.Where().
247
+ WithPath([]string{propName}).
248
+ WithOperator(filters.LessThan).
249
+ WithValueDate(val1),
250
+ filters.Where().
251
+ WithPath([]string{propName}).
252
+ WithOperator(filters.GreaterThanEqual).
253
+ WithValueDate(val2),
254
+ }))
255
+ }
256
+ intersectionInt := func(propName string, val1, val2 int64) []string {
257
+ return gqlGet(filters.Where().
258
+ WithOperator(filters.And).
259
+ WithOperands(
260
+ []*filters.WhereBuilder{
261
+ filters.Where().
262
+ WithPath([]string{propName}).
263
+ WithOperator(filters.GreaterThanEqual).
264
+ WithValueInt(val1),
265
+ filters.Where().
266
+ WithPath([]string{propName}).
267
+ WithOperator(filters.LessThanEqual).
268
+ WithValueInt(val2),
269
+ }))
270
+ }
271
+ intersectionNumber := func(propName string, val1, val2 float64) []string {
272
+ return gqlGet(filters.Where().
273
+ WithOperator(filters.And).
274
+ WithOperands(
275
+ []*filters.WhereBuilder{
276
+ filters.Where().
277
+ WithPath([]string{propName}).
278
+ WithOperator(filters.GreaterThanEqual).
279
+ WithValueNumber(val1),
280
+ filters.Where().
281
+ WithPath([]string{propName}).
282
+ WithOperator(filters.LessThanEqual).
283
+ WithValueNumber(val2),
284
+ }))
285
+ }
286
+ intersectionDate := func(propName string, val1, val2 time.Time) []string {
287
+ return gqlGet(filters.Where().
288
+ WithOperator(filters.And).
289
+ WithOperands(
290
+ []*filters.WhereBuilder{
291
+ filters.Where().
292
+ WithPath([]string{propName}).
293
+ WithOperator(filters.GreaterThanEqual).
294
+ WithValueDate(val1),
295
+ filters.Where().
296
+ WithPath([]string{propName}).
297
+ WithOperator(filters.LessThanEqual).
298
+ WithValueDate(val2),
299
+ }))
300
+ }
301
+
302
+ randId1 := selectedRandIds[0]
303
+ randId2 := selectedRandIds[1]
304
+ randId3 := selectedRandIds[2]
305
+ randId4 := selectedRandIds[3]
306
+ randId5 := selectedRandIds[4]
307
+ randId6 := selectedRandIds[5]
308
+
309
+ runQueries := func(t *testing.T) {
310
+ t.Run("equal int", func(t *testing.T) {
311
+ int1, int2 := randInts[randId1], randInts[randId2]
312
+
313
+ filterableUuids1 := equalInt("int_filterable", int1)
314
+ rangeableUuids1 := equalInt("int_rangeable", int1)
315
+ assert.GreaterOrEqual(t, len(filterableUuids1), 1)
316
+ assert.ElementsMatch(t, filterableUuids1, rangeableUuids1)
317
+
318
+ filterableUuids2 := equalInt("int_filterable", int2)
319
+ rangeableUuids2 := equalInt("int_rangeable", int2)
320
+ assert.GreaterOrEqual(t, len(filterableUuids2), 1)
321
+ assert.ElementsMatch(t, filterableUuids2, rangeableUuids2)
322
+ })
323
+
324
+ t.Run("equal number", func(t *testing.T) {
325
+ number1, number2 := randNumbers[randId1], randNumbers[randId2]
326
+
327
+ filterableUuids1 := equalNumber("number_filterable", number1)
328
+ rangeableUuids1 := equalNumber("number_rangeable", number1)
329
+ assert.GreaterOrEqual(t, len(filterableUuids1), 1)
330
+ assert.ElementsMatch(t, filterableUuids1, rangeableUuids1)
331
+
332
+ filterableUuids2 := equalNumber("number_filterable", number2)
333
+ rangeableUuids2 := equalNumber("number_rangeable", number2)
334
+ assert.GreaterOrEqual(t, len(filterableUuids2), 1)
335
+ assert.ElementsMatch(t, filterableUuids2, rangeableUuids2)
336
+ })
337
+
338
+ t.Run("equal date", func(t *testing.T) {
339
+ date1, date2 := randDates[randId1], randDates[randId2]
340
+
341
+ filterableUuids1 := equalDate("date_filterable", date1)
342
+ rangeableUuids1 := equalDate("date_rangeable", date1)
343
+ assert.GreaterOrEqual(t, len(filterableUuids1), 1)
344
+ assert.ElementsMatch(t, filterableUuids1, rangeableUuids1)
345
+
346
+ filterableUuids2 := equalDate("date_filterable", date2)
347
+ rangeableUuids2 := equalDate("date_rangeable", date2)
348
+ assert.GreaterOrEqual(t, len(filterableUuids2), 1)
349
+ assert.ElementsMatch(t, filterableUuids2, rangeableUuids2)
350
+ })
351
+
352
+ t.Run("union int", func(t *testing.T) {
353
+ int1, int2 := randInts[randId3], randInts[randId4]
354
+ if int1 > int2 {
355
+ int1, int2 = int2, int1
356
+ }
357
+
358
+ filterableUuids := unionInt("int_filterable", int1, int2)
359
+ rangeableUuids := unionInt("int_rangeable", int1, int2)
360
+ assert.GreaterOrEqual(t, len(filterableUuids), 1)
361
+ assert.ElementsMatch(t, filterableUuids, rangeableUuids)
362
+ })
363
+
364
+ t.Run("union number", func(t *testing.T) {
365
+ number1, number2 := randNumbers[randId3], randNumbers[randId4]
366
+ if number1 > number2 {
367
+ number1, number2 = number2, number1
368
+ }
369
+
370
+ filterableUuids := unionNumber("number_filterable", number1, number2)
371
+ rangeableUuids := unionNumber("number_rangeable", number1, number2)
372
+ assert.GreaterOrEqual(t, len(filterableUuids), 1)
373
+ assert.ElementsMatch(t, filterableUuids, rangeableUuids)
374
+ })
375
+
376
+ t.Run("union date", func(t *testing.T) {
377
+ date1, date2 := randDates[randId3], randDates[randId4]
378
+ if date1.After(date2) {
379
+ date1, date2 = date2, date1
380
+ }
381
+
382
+ filterableUuids := unionDate("date_filterable", date1, date2)
383
+ rangeableUuids := unionDate("date_rangeable", date1, date2)
384
+ assert.GreaterOrEqual(t, len(filterableUuids), 1)
385
+ assert.ElementsMatch(t, filterableUuids, rangeableUuids)
386
+ })
387
+
388
+ t.Run("intersection int", func(t *testing.T) {
389
+ int1, int2 := randInts[randId5], randInts[randId6]
390
+ if int1 > int2 {
391
+ int1, int2 = int2, int1
392
+ }
393
+
394
+ filterableUuids := intersectionInt("int_filterable", int1, int2)
395
+ rangeableUuids := intersectionInt("int_rangeable", int1, int2)
396
+ assert.GreaterOrEqual(t, len(filterableUuids), 1)
397
+ assert.ElementsMatch(t, filterableUuids, rangeableUuids)
398
+ })
399
+
400
+ t.Run("intersection number", func(t *testing.T) {
401
+ number1, number2 := randNumbers[randId5], randNumbers[randId6]
402
+ if number1 > number2 {
403
+ number1, number2 = number2, number1
404
+ }
405
+
406
+ filterableUuids := intersectionNumber("number_filterable", number1, number2)
407
+ rangeableUuids := intersectionNumber("number_rangeable", number1, number2)
408
+ assert.GreaterOrEqual(t, len(filterableUuids), 1)
409
+ assert.ElementsMatch(t, filterableUuids, rangeableUuids)
410
+ })
411
+
412
+ t.Run("intersection date", func(t *testing.T) {
413
+ date1, date2 := randDates[randId5], randDates[randId6]
414
+ if date1.After(date2) {
415
+ date1, date2 = date2, date1
416
+ }
417
+
418
+ filterableUuids := intersectionDate("date_filterable", date1, date2)
419
+ rangeableUuids := intersectionDate("date_rangeable", date1, date2)
420
+ assert.GreaterOrEqual(t, len(filterableUuids), 1)
421
+ assert.ElementsMatch(t, filterableUuids, rangeableUuids)
422
+ })
423
+ }
424
+
425
+ t.Run("queries before delete", runQueries)
426
+
427
+ t.Run("delete some data", func(t *testing.T) {
428
+ resp, err := client.Batch().ObjectsBatchDeleter().
429
+ WithClassName(className).
430
+ WithWhere(filters.Where().
431
+ WithOperator(filters.Equal).
432
+ WithPath([]string{"delete"}).
433
+ WithValueBoolean(true)).
434
+ Do(context.Background())
435
+ require.NoError(t, err)
436
+ require.Equal(t, int64(0), resp.Results.Failed)
437
+ require.Equal(t, int64(batches*perBatch/2), resp.Results.Successful)
438
+ })
439
+
440
+ t.Run("queries after delete", runQueries)
441
+ }
442
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/filters_tests/regex_test.go ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package filters_tests
13
+
14
+ import (
15
+ "context"
16
+ "testing"
17
+
18
+ acceptance_with_go_client "acceptance_tests_with_client"
19
+
20
+ "github.com/stretchr/testify/require"
21
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
22
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/filters"
23
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/graphql"
24
+ "github.com/weaviate/weaviate/entities/models"
25
+ "github.com/weaviate/weaviate/entities/schema"
26
+ )
27
+
28
+ func TestWhereFilter_Regex(t *testing.T) {
29
+ ctx := context.Background()
30
+ config := wvt.Config{Scheme: "http", Host: "localhost:8080"}
31
+ client, err := wvt.NewClient(config)
32
+ require.NoError(t, err)
33
+ require.NotNil(t, client)
34
+ // clean DB
35
+ err = client.Schema().AllDeleter().Do(ctx)
36
+ require.NoError(t, err)
37
+
38
+ t.Run("special characters in where filter value", func(t *testing.T) {
39
+ vectorizer := "text2vec-contextionary"
40
+ id1 := "00000000-0000-0000-0000-000000000001"
41
+ className := "Regex"
42
+
43
+ class := &models.Class{
44
+ Class: className,
45
+ Properties: []*models.Property{
46
+ {
47
+ Name: "summary",
48
+ DataType: []string{schema.DataTypeText.String()},
49
+ Tokenization: "field",
50
+ ModuleConfig: map[string]interface{}{
51
+ vectorizer: map[string]interface{}{
52
+ "skip": true,
53
+ "vectorizePropertyName": "false",
54
+ },
55
+ },
56
+ },
57
+ {
58
+ Name: "summaries",
59
+ DataType: []string{schema.DataTypeTextArray.String()},
60
+ Tokenization: "field",
61
+ ModuleConfig: map[string]interface{}{
62
+ vectorizer: map[string]interface{}{
63
+ "skip": false,
64
+ "vectorizePropertyName": "false",
65
+ },
66
+ },
67
+ },
68
+ },
69
+ }
70
+ err = client.Schema().ClassCreator().WithClass(class).Do(ctx)
71
+ require.NoError(t, err)
72
+ text := `The Hitchhiker's Guide to the Galaxy by Douglas Adams is a comedic science) fiction masterpiece that follows the bewildering adventures of Arthur Dent, an unwitting Earthling, after the destruction of his planet to make way for an interstellar highway. Joined by Ford Prefect, a researcher for the titular guidebook, Zaphod Beeblebrox, a two-headed ex-president, Trillian, the sole human survivor, and Marvin, a depressed robot, Arthur navigates the cosmos while encountering absurdity and philosophical musings. Adams' satirical wit and irreverent humor make this quintessential work a hilarious exploration of the absurdities of life, space, and everything in between.`
73
+ _, err = client.Data().Creator().
74
+ WithClassName(className).
75
+ WithID(id1).
76
+ WithProperties(map[string]interface{}{
77
+ "summary": text,
78
+ "summaries": []string{text},
79
+ }).
80
+ Do(ctx)
81
+ require.NoError(t, err)
82
+ exists, err := client.Data().Checker().WithClassName(className).WithID(id1).Do(ctx)
83
+ require.NoError(t, err)
84
+ require.True(t, exists)
85
+ tests := []struct {
86
+ name string
87
+ where *filters.WhereBuilder
88
+ }{
89
+ {
90
+ name: "special character in text array property",
91
+ where: filters.Where().
92
+ WithPath([]string{"summaries"}).
93
+ WithOperator(filters.Like).
94
+ WithValueString("*science)*"),
95
+ },
96
+ {
97
+ name: "special character in text property",
98
+ where: filters.Where().
99
+ WithPath([]string{"summary"}).
100
+ WithOperator(filters.Like).
101
+ WithValueString("*science)*"),
102
+ },
103
+ {
104
+ name: "without special character in text array property",
105
+ where: filters.Where().
106
+ WithPath([]string{"summaries"}).
107
+ WithOperator(filters.Like).
108
+ WithValueString("*science*"),
109
+ },
110
+ {
111
+ name: "without special character in text property",
112
+ where: filters.Where().
113
+ WithPath([]string{"summary"}).
114
+ WithOperator(filters.Like).
115
+ WithValueString("*science*"),
116
+ },
117
+ }
118
+ for _, tt := range tests {
119
+ t.Run(tt.name, func(t *testing.T) {
120
+ fields := []graphql.Field{
121
+ {Name: "_additional", Fields: []graphql.Field{{Name: "id"}}},
122
+ }
123
+ resp, err := client.GraphQL().Get().
124
+ WithClassName(className).
125
+ WithWhere(tt.where).
126
+ WithFields(fields...).
127
+ Do(ctx)
128
+ require.Nil(t, err)
129
+ require.Empty(t, resp.Errors)
130
+ ids := acceptance_with_go_client.GetIds(t, resp, className)
131
+ require.NotEmpty(t, ids)
132
+ require.ElementsMatch(t, ids, []string{id1})
133
+ })
134
+ }
135
+ })
136
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/filters_tests/where_test.go ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package filters_tests
13
+
14
+ import (
15
+ "context"
16
+ "testing"
17
+
18
+ "github.com/stretchr/testify/require"
19
+ "github.com/weaviate/weaviate/test/docker"
20
+ )
21
+
22
+ func TestWhereFilter_SingleNode_Contains(t *testing.T) {
23
+ t.Run("Contains", testContains("localhost:8080"))
24
+ t.Run("Contains text", testContainsText("localhost:8080"))
25
+ t.Run("Contains movies", testContainsMovies("localhost:8080"))
26
+ }
27
+
28
+ func TestWhereFilter_SingleNode_Numerical(t *testing.T) {
29
+ ctx := context.Background()
30
+
31
+ t.Run("with rangeable on disk", func(t *testing.T) {
32
+ compose, err := docker.New().
33
+ WithWeaviate().
34
+ Start(ctx)
35
+ require.NoError(t, err)
36
+ defer func() {
37
+ require.NoError(t, compose.Terminate(ctx))
38
+ }()
39
+
40
+ endpoint := compose.GetWeaviate().URI()
41
+
42
+ t.Run("numerical filters", testNumericalFilters(endpoint))
43
+ })
44
+
45
+ t.Run("with rangeable in memory", func(t *testing.T) {
46
+ compose, err := docker.New().
47
+ WithWeaviate().
48
+ WithWeaviateEnv("INDEX_RANGEABLE_IN_MEMORY", "true").
49
+ Start(ctx)
50
+ require.NoError(t, err)
51
+ defer func() {
52
+ require.NoError(t, compose.Terminate(ctx))
53
+ }()
54
+
55
+ endpoint := compose.GetWeaviate().URI()
56
+
57
+ t.Run("numerical filters", testNumericalFilters(endpoint))
58
+ })
59
+ }
60
+
61
+ func TestWhereFilter_Cluster(t *testing.T) {
62
+ ctx := context.Background()
63
+ compose, err := docker.New().
64
+ WithWeaviateCluster(3).
65
+ WithText2VecContextionary().
66
+ Start(ctx)
67
+ require.NoError(t, err)
68
+ defer func() {
69
+ require.NoError(t, compose.Terminate(ctx))
70
+ }()
71
+
72
+ endpoint := compose.GetWeaviate().URI()
73
+
74
+ t.Run("Contains", testContains(endpoint))
75
+ t.Run("Contains text", testContainsText(endpoint))
76
+ t.Run("Contains movies", testContainsMovies(endpoint))
77
+ t.Run("Numerical filters", testNumericalFilters(endpoint))
78
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/fixtures/allproperties.go ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package fixtures
13
+
14
+ import (
15
+ "github.com/weaviate/weaviate/entities/models"
16
+ "github.com/weaviate/weaviate/entities/schema"
17
+ )
18
+
19
+ var (
20
+ AllPropertiesClassName = "AllProperties"
21
+ AllPropertiesID1 = "00000000-0000-0000-0000-000000000001"
22
+ vTrue = true
23
+ vFalse = false
24
+ )
25
+
26
+ var AllPropertiesClass = &models.Class{
27
+ Class: AllPropertiesClassName,
28
+ Properties: []*models.Property{
29
+ {
30
+ Name: "objectProperty",
31
+ DataType: schema.DataTypeObject.PropString(),
32
+ IndexFilterable: &vTrue,
33
+ IndexSearchable: &vFalse,
34
+ Tokenization: "",
35
+ NestedProperties: []*models.NestedProperty{
36
+ {
37
+ Name: "text",
38
+ DataType: schema.DataTypeText.PropString(),
39
+ },
40
+ {
41
+ Name: "texts",
42
+ DataType: schema.DataTypeTextArray.PropString(),
43
+ },
44
+ {
45
+ Name: "number",
46
+ DataType: schema.DataTypeNumber.PropString(),
47
+ },
48
+ {
49
+ Name: "numbers",
50
+ DataType: schema.DataTypeNumberArray.PropString(),
51
+ },
52
+ {
53
+ Name: "int",
54
+ DataType: schema.DataTypeInt.PropString(),
55
+ },
56
+ {
57
+ Name: "ints",
58
+ DataType: schema.DataTypeIntArray.PropString(),
59
+ },
60
+ {
61
+ Name: "date",
62
+ DataType: schema.DataTypeDate.PropString(),
63
+ },
64
+ {
65
+ Name: "dates",
66
+ DataType: schema.DataTypeDateArray.PropString(),
67
+ },
68
+ {
69
+ Name: "bool",
70
+ DataType: schema.DataTypeBoolean.PropString(),
71
+ },
72
+ {
73
+ Name: "bools",
74
+ DataType: schema.DataTypeBooleanArray.PropString(),
75
+ },
76
+ {
77
+ Name: "uuid",
78
+ DataType: schema.DataTypeUUID.PropString(),
79
+ },
80
+ {
81
+ Name: "uuids",
82
+ DataType: schema.DataTypeUUIDArray.PropString(),
83
+ },
84
+ {
85
+ Name: "nested_int",
86
+ DataType: schema.DataTypeInt.PropString(),
87
+ IndexFilterable: &vTrue,
88
+ IndexSearchable: &vFalse,
89
+ Tokenization: "",
90
+ },
91
+ {
92
+ Name: "nested_number",
93
+ DataType: schema.DataTypeNumber.PropString(),
94
+ IndexFilterable: &vTrue,
95
+ IndexSearchable: &vFalse,
96
+ Tokenization: "",
97
+ },
98
+ {
99
+ Name: "nested_text",
100
+ DataType: schema.DataTypeText.PropString(),
101
+ IndexFilterable: &vTrue,
102
+ IndexSearchable: &vTrue,
103
+ Tokenization: models.PropertyTokenizationWord,
104
+ },
105
+ {
106
+ Name: "nested_objects",
107
+ DataType: schema.DataTypeObject.PropString(),
108
+ IndexFilterable: &vTrue,
109
+ IndexSearchable: &vFalse,
110
+ Tokenization: "",
111
+ NestedProperties: []*models.NestedProperty{
112
+ {
113
+ Name: "nested_bool_lvl2",
114
+ DataType: schema.DataTypeBoolean.PropString(),
115
+ IndexFilterable: &vTrue,
116
+ IndexSearchable: &vFalse,
117
+ Tokenization: "",
118
+ },
119
+ {
120
+ Name: "nested_numbers_lvl2",
121
+ DataType: schema.DataTypeNumberArray.PropString(),
122
+ IndexFilterable: &vTrue,
123
+ IndexSearchable: &vFalse,
124
+ Tokenization: "",
125
+ },
126
+ },
127
+ },
128
+ {
129
+ Name: "nested_array_objects",
130
+ DataType: schema.DataTypeObjectArray.PropString(),
131
+ IndexFilterable: &vTrue,
132
+ IndexSearchable: &vFalse,
133
+ Tokenization: "",
134
+ NestedProperties: []*models.NestedProperty{
135
+ {
136
+ Name: "nested_bool_lvl2",
137
+ DataType: schema.DataTypeBoolean.PropString(),
138
+ IndexFilterable: &vTrue,
139
+ IndexSearchable: &vFalse,
140
+ Tokenization: "",
141
+ },
142
+ {
143
+ Name: "nested_numbers_lvl2",
144
+ DataType: schema.DataTypeNumberArray.PropString(),
145
+ IndexFilterable: &vTrue,
146
+ IndexSearchable: &vFalse,
147
+ Tokenization: "",
148
+ },
149
+ },
150
+ },
151
+ },
152
+ },
153
+ },
154
+ }
155
+
156
+ var AllPropertiesProperties = map[string]interface{}{
157
+ "text": "red",
158
+ "texts": []string{"red", "blue"},
159
+ "number": float64(1.1),
160
+ "numbers": []float64{1.1, 2.2},
161
+ "int": int64(1),
162
+ "ints": []int64{1, 2},
163
+ "uuid": AllPropertiesID1,
164
+ "uuids": []string{AllPropertiesID1},
165
+ "date": "2009-11-01T23:00:00Z",
166
+ "dates": []string{"2009-11-01T23:00:00Z"},
167
+ "bool": true,
168
+ "bools": []bool{true, false},
169
+ "nested_int": int64(11),
170
+ "nested_number": float64(11.11),
171
+ "nested_text": "nested text",
172
+ "nested_objects": map[string]interface{}{
173
+ "nested_bool_lvl2": true,
174
+ "nested_numbers_lvl2": []float64{11.1, 22.1},
175
+ },
176
+ "nested_array_objects": []interface{}{
177
+ map[string]interface{}{
178
+ "nested_bool_lvl2": true,
179
+ "nested_numbers_lvl2": []float64{111.1, 222.1},
180
+ },
181
+ map[string]interface{}{
182
+ "nested_bool_lvl2": false,
183
+ "nested_numbers_lvl2": []float64{112.1, 222.1},
184
+ },
185
+ },
186
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/fixtures/books.go ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package fixtures
13
+
14
+ type Book struct {
15
+ Author, Title, Description, Genre string
16
+ }
17
+
18
+ func Books() map[string]Book {
19
+ books := map[string]Book{
20
+ "00000000-0000-0000-0000-000000000001": {
21
+ Author: "J.R.R. Tolkien",
22
+ Title: "The Lord of the rings",
23
+ Description: `"The Lord of the Rings" is a timeless epic fantasy tale penned by J.R.R. Tolkien. Set in the fictional world of Middle-earth, the story follows the quest of Frodo Baggins, a humble hobbit, who is tasked with destroying a powerful and corrupting artifact, the One Ring. Accompanied by a diverse fellowship of companions, including humans, elves, dwarves, and other hobbits, Frodo embarks on a perilous journey across Middle-earth to Mount Doom, the only place where the Ring can be unmade. Along the way, they encounter ancient evils, forge unbreakable bonds of friendship, and face monumental challenges that will test their courage and resolve. As the fate of Middle-earth hangs in the balance, Frodo and his companions must confront the forces of darkness in an epic struggle for the survival of their world. Rich with themes of friendship, sacrifice, and the eternal battle between good and evil, "The Lord of the Rings" remains one of the most beloved and influential works of fantasy literature ever written.`,
24
+ Genre: "fantasy",
25
+ },
26
+ "00000000-0000-0000-0000-000000000002": {
27
+ Author: "Douglas Adams",
28
+ Title: "The Hitchhiker's Guide to the Galaxy",
29
+ Description: `"The Hitchhiker's Guide to the Galaxy" is a comedic science fiction novel written by Douglas Adams. It follows the misadventures of Arthur Dent, an ordinary human who is unexpectedly whisked away from Earth just before its demolition to make way for a hyperspace bypass. Arthur's friend, Ford Prefect, turns out to be an alien researcher for the titular guidebook, a humorous compendium of knowledge for intergalactic travelers. Together, they embark on a journey through space, encountering a quirky cast of characters including the two-headed, three-armed ex-President of the Galaxy, Zaphod Beeblebrox, and the depressed robot Marvin. Filled with absurdity, wit, and biting satire, "The Hitchhiker's Guide to the Galaxy" is a delightful romp through the cosmos that pokes fun at the human condition and the universe at large.`,
30
+ Genre: "science-fiction",
31
+ },
32
+ "00000000-0000-0000-0000-000000000003": {
33
+ Author: "Frank Herbert",
34
+ Title: "Dune",
35
+ Description: `"Dune" is a science fiction masterpiece written by Frank Herbert. Set in a distant future where noble houses vie for control of the desert planet Arrakis, known for its valuable spice melange, the story follows young Paul Atreides as his family assumes stewardship of Arrakis. Paul's journey intertwines with political intrigue, betrayal, and a prophesied destiny that could change the fate of the universe. As Paul navigates the harsh desert landscape and confronts the enigmatic Fremen people, he undergoes a transformation that will shape the course of history. "Dune" is a sweeping epic filled with intricate world-building, complex characters, and philosophical themes that have captivated readers for generations.`,
36
+ Genre: "science-fiction",
37
+ },
38
+ "00000000-0000-0000-0000-000000000004": {
39
+ Author: "Isaac Asimov",
40
+ Title: "Foundation",
41
+ Description: `"Foundation" by Isaac Asimov is a groundbreaking science fiction novel that explores the concept of psychohistory—a mathematical science capable of predicting the future of large populations. Set in a distant future where the Galactic Empire is in decline, the story follows mathematician Hari Seldon, who predicts the imminent fall of civilization. To preserve knowledge and shorten the dark ages that will follow, Seldon establishes the Foundation—a secretive organization tasked with guiding humanity's destiny. Spanning centuries, "Foundation" chronicles the Foundation's efforts to navigate political intrigue, technological advancement, and the rise and fall of empires. Asimov's masterful storytelling and thought-provoking exploration of sociopolitical themes make "Foundation" a timeless classic of science fiction literature.`,
42
+ Genre: "science-fiction",
43
+ },
44
+ "00000000-0000-0000-0000-000000000005": {
45
+ Author: "Liu Cixin",
46
+ Title: "The Three-Body Problem",
47
+ Description: `"The Three-Body Problem" by Liu Cixin is a groundbreaking science fiction novel that melds complex scientific concepts with compelling storytelling. Set against the backdrop of China's Cultural Revolution and its aftermath, the story follows physicist Ye Wenjie as she becomes embroiled in a secretive government project to make contact with extraterrestrial life. Meanwhile, present-day scientist Wang Miao finds himself drawn into a mysterious online game that holds the key to understanding an impending alien invasion. As humanity grapples with the implications of contact with an advanced alien civilization and the existential threats it poses, "The Three-Body Problem" explores themes of scientific discovery, cultural revolution, and the nature of humanity itself. Liu Cixin's visionary narrative and intricate exploration of physics and philosophy make "The Three-Body Problem" a thought-provoking and immersive journey into the unknown.`,
48
+ Genre: "science-fiction",
49
+ },
50
+ "00000000-0000-0000-0000-000000000006": {
51
+ Author: "Richard K. Morgan",
52
+ Title: "Altered Carbon",
53
+ Description: `"Altered Carbon" by Richard K. Morgan is a gripping science fiction novel set in a future where consciousness can be transferred between bodies, known as "sleeves," and death has become nearly obsolete for the wealthy. The story follows Takeshi Kovacs, a former soldier turned private investigator, who is hired to solve the murder of a wealthy aristocrat, Laurens Bancroft. As Kovacs delves deeper into the seedy underbelly of a society where the rich live for centuries and the poor struggle to survive, he uncovers a conspiracy that threatens to unravel the fabric of society itself. Blending hard-boiled detective noir with cyberpunk elements and thought-provoking explorations of identity, morality, and the commodification of life, "Altered Carbon" is a thrilling and immersive exploration of a dystopian future where the line between humanity and technology has blurred beyond recognition.`,
54
+ Genre: "science-fiction",
55
+ },
56
+ "00000000-0000-0000-0000-000000000007": {
57
+ Author: "Jeff VanderMeer",
58
+ Title: "Borne",
59
+ Description: `"Borne" by Jeff VanderMeer is a captivating and surreal science fiction novel set in a post-apocalyptic world devastated by biotech experiments gone awry. The story unfolds in a city overrun by strange and dangerous creatures, where scavenger Rachel discovers a mysterious organism she names Borne. As Rachel nurtures Borne, he rapidly grows and evolves, exhibiting intelligence and abilities beyond comprehension. However, their bond is tested when Borne's origins and true nature are revealed, sparking a journey of discovery and survival in a world where nothing is as it seems. VanderMeer's vivid imagination, lyrical prose, and thought-provoking exploration of humanity, nature, and the ethics of scientific experimentation make "Borne" a mesmerizing and unforgettable reading experience.`,
60
+ Genre: "science-fiction",
61
+ },
62
+ "00000000-0000-0000-0000-000000000008": {
63
+ Author: "Greg Egan",
64
+ Title: "Diaspora",
65
+ Description: `"Diaspora" by Greg Egan is a mind-bending science fiction novel that explores themes of identity, consciousness, and the nature of existence in a universe where humanity has transcended physical limitations. Set in the distant future, the story follows a group of post-human beings known as "polises" who exist as digital entities in vast virtual environments. When a catastrophic event threatens their existence, a diverse cast of characters embarks on a journey of exploration and discovery across the cosmos, encountering enigmatic aliens and grappling with existential questions about the nature of reality. Egan's meticulous attention to scientific detail and thought-provoking speculation on the future evolution of humanity make "Diaspora" a challenging yet rewarding exploration of the boundaries of human potential in an infinitely expanding universe.`,
66
+ Genre: "science-fiction",
67
+ },
68
+ "00000000-0000-0000-0000-000000000009": {
69
+ Author: "Janusz A. Zajdel",
70
+ Title: "Limes inferior",
71
+ Description: `"Limes Inferior" is a renowned novel written by Janusz A. Zajdel, a prominent Polish science fiction writer. Set in a dystopian future, the story takes place in a post-apocalyptic world where humanity's survival is threatened by ecological devastation and totalitarian regimes. The narrative follows the protagonist, Peter Cogito, as he navigates the oppressive society ruled by a powerful government and struggles to find his place in a world filled with corruption, surveillance, and social unrest. As Peter delves deeper into the secrets of his society, he uncovers dark truths about the nature of power and the consequences of unchecked authority. "Limes Inferior" is celebrated for its thought-provoking exploration of political themes, moral dilemmas, and the resilience of the human spirit in the face of adversity.`,
72
+ Genre: "science-fiction",
73
+ },
74
+ "00000000-0000-0000-0000-000000000010": {
75
+ Author: "Walter Tevis",
76
+ Title: "The Man Who Fell to Earth",
77
+ Description: `"The Man Who Fell to Earth" is a thought-provoking science fiction novel written by Walter Tevis. The story revolves around Thomas Jerome Newton, an extraterrestrial being from a drought-stricken planet called Anthea. Disguised as a human, Newton arrives on Earth with advanced technology to save his dying world. He becomes a wealthy industrialist, using his knowledge to revolutionize various industries. However, as he becomes increasingly entangled in Earth's society, Newton grapples with the complexities of human emotions, desires, and vices. The novel explores themes of alienation, loneliness, and the struggle to maintain one's identity in a world vastly different from one's own. "The Man Who Fell to Earth" is a poignant and introspective tale that delves into the human condition and the universal quest for connection and belonging.`,
78
+ Genre: "science-fiction",
79
+ },
80
+ "00000000-0000-0000-0000-000000000011": {
81
+ Author: "Neal Stephenson",
82
+ Title: "Seveneves",
83
+ Description: `"Seveneves" by Neal Stephenson is an epic science fiction novel that begins with the sudden destruction of the Moon, setting off a chain reaction of events that threatens all life on Earth. Facing imminent extinction, humanity races against time to ensure its survival by sending a select group of individuals into space to live aboard hastily constructed space habitats known as the "Cloud Ark." As the survivors grapple with the challenges of adaptation and coexistence in their new environment, tensions rise and alliances shift in the struggle to preserve humanity's future. Spanning thousands of years, "Seveneves" explores themes of resilience, ingenuity, and the endurance of the human spirit in the face of catastrophic adversity. With meticulous attention to scientific detail and grand scope, Neal Stephenson delivers a riveting tale of survival and evolution that transcends the bounds of time and space.`,
84
+ Genre: "science-fiction",
85
+ },
86
+ "00000000-0000-0000-0000-000000000012": {
87
+ Author: "Andy Weir",
88
+ Title: "Project Hail Mary",
89
+ Description: `"Project Hail Mary" is a thrilling science fiction novel by Andy Weir, acclaimed author of "The Martian." The story follows Ryland Grace, a brilliant but solitary scientist who wakes up aboard a spacecraft with no memory of who he is or how he got there. As he pieces together his identity and the purpose of his mission, Ryland discovers that he is humanity's last hope to save Earth from an impending catastrophe. With the help of an unlikely ally, an extraterrestrial organism named Rocky, Ryland embarks on a perilous journey across the cosmos to uncover the truth behind the disaster and find a solution to save mankind. Filled with suspense, humor, and ingenious problem-solving, "Project Hail Mary" is a gripping tale of survival, discovery, and the indomitable human spirit in the face of unimaginable challenges.`,
90
+ Genre: "science-fiction",
91
+ },
92
+ "00000000-0000-0000-0000-000000000013": {
93
+ Author: "Dan Simmons",
94
+ Title: "Hyperion",
95
+ Description: `"Hyperion" by Dan Simmons is a gripping science fiction novel that unfolds as a series of interconnected stories, each told by one of seven pilgrims on a journey to the distant world of Hyperion. Set in a future where humanity has spread across the galaxy, the pilgrims share their tales as they seek answers to the enigmatic Shrike, a legendary creature that resides on Hyperion. As each pilgrim reveals their past, fears, and desires, a larger narrative emerges—one of political intrigue, religious conflict, and existential dread. With rich world-building, complex characters, and a narrative structure reminiscent of Chaucer's "The Canterbury Tales," "Hyperion" is a compelling exploration of humanity's place in the universe, the nature of consciousness, and the search for meaning in an ever-expanding cosmos.`,
96
+ Genre: "science-fiction",
97
+ },
98
+ "00000000-0000-0000-0000-000000000014": {
99
+ Author: "Jacek Dukaj",
100
+ Title: "Black Oceans",
101
+ Description: `"Black Oceans" is a science fiction novel by Polish writer Jacek Dukaj, published in Poland by Supernowa in 2001. The novel fits in the hard science fiction genre, describing the late-21st century Earth facing technological singularity. The novel received the prime Polish award for sci-fi literature, Janusz A. Zajdel Award, for 2001.`,
102
+ Genre: "science-fiction",
103
+ },
104
+ }
105
+ return books
106
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/fixtures/colbert.go ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package fixtures
13
+
14
+ import (
15
+ "github.com/weaviate/weaviate/entities/models"
16
+ "github.com/weaviate/weaviate/entities/schema"
17
+ )
18
+
19
+ var (
20
+ BringYourOwnColBERTClassName = "BringYourOwnColBERT"
21
+ BringYourOwnColBERTPropertyName = "name"
22
+ BringYourOwnColBERTNamedVectorName = "byoc"
23
+ NormalVector2dName = "normal_2d"
24
+ MultiVector1dName = "multi_1d"
25
+ MultiVector2dName = "multi_2d"
26
+ MultiVector3dName = "multi_3d"
27
+ )
28
+
29
+ var BringYourOwnColBERTClass = func(className string) *models.Class {
30
+ return &models.Class{
31
+ Class: BringYourOwnColBERTClassName,
32
+ Properties: []*models.Property{
33
+ {
34
+ Name: BringYourOwnColBERTPropertyName, DataType: []string{schema.DataTypeText.String()},
35
+ },
36
+ },
37
+ VectorConfig: map[string]models.VectorConfig{
38
+ BringYourOwnColBERTNamedVectorName: {
39
+ Vectorizer: map[string]interface{}{
40
+ "none": map[string]interface{}{},
41
+ },
42
+ VectorIndexConfig: map[string]interface{}{
43
+ "multivector": map[string]interface{}{
44
+ "enabled": true,
45
+ },
46
+ },
47
+ VectorIndexType: "hnsw",
48
+ },
49
+ NormalVector2dName: {
50
+ Vectorizer: map[string]interface{}{
51
+ "none": map[string]interface{}{},
52
+ },
53
+ VectorIndexType: "hnsw",
54
+ },
55
+ MultiVector1dName: {
56
+ Vectorizer: map[string]interface{}{
57
+ "none": map[string]interface{}{},
58
+ },
59
+ VectorIndexConfig: map[string]interface{}{
60
+ "multivector": map[string]interface{}{
61
+ "enabled": true,
62
+ },
63
+ },
64
+ VectorIndexType: "hnsw",
65
+ },
66
+ MultiVector2dName: {
67
+ Vectorizer: map[string]interface{}{
68
+ "none": map[string]interface{}{},
69
+ },
70
+ VectorIndexConfig: map[string]interface{}{
71
+ "multivector": map[string]interface{}{
72
+ "enabled": true,
73
+ },
74
+ },
75
+ VectorIndexType: "hnsw",
76
+ },
77
+ MultiVector3dName: {
78
+ Vectorizer: map[string]interface{}{
79
+ "none": map[string]interface{}{},
80
+ },
81
+ VectorIndexConfig: map[string]interface{}{
82
+ "multivector": map[string]interface{}{
83
+ "enabled": true,
84
+ },
85
+ },
86
+ VectorIndexType: "hnsw",
87
+ },
88
+ },
89
+ }
90
+ }
91
+
92
+ var BringYourOwnColBERTObjects = []struct {
93
+ ID string
94
+ Name string
95
+ Vector [][]float32
96
+ }{
97
+ {
98
+ ID: "00000000-0000-0000-0000-000000000001", Name: "a", Vector: [][]float32{{0.11, 0.12}, {0.13, 0.14}, {0.15, 0.16}},
99
+ },
100
+ {
101
+ ID: "00000000-0000-0000-0000-000000000002", Name: "b", Vector: [][]float32{{0.21, 0.22}, {0.23, 0.24}, {0.25, 0.26}},
102
+ },
103
+ {
104
+ ID: "00000000-0000-0000-0000-000000000003", Name: "c", Vector: [][]float32{{0.31, 0.32}, {0.33, 0.34}, {0.35, 0.36}},
105
+ },
106
+ {
107
+ ID: "00000000-0000-0000-0000-000000000004", Name: "d", Vector: [][]float32{{0.41, 0.42}, {0.43, 0.44}, {0.45, 0.46}},
108
+ },
109
+ {
110
+ ID: "00000000-0000-0000-0000-000000000005", Name: "e", Vector: [][]float32{{0.51, 0.52}, {0.53, 0.54}, {0.55, 0.56}},
111
+ },
112
+ {
113
+ ID: "00000000-0000-0000-0000-000000000006", Name: "f", Vector: [][]float32{{0.61, 0.62}, {0.63, 0.64}, {0.65, 0.66}},
114
+ },
115
+ {
116
+ ID: "00000000-0000-0000-0000-000000000007", Name: "g", Vector: [][]float32{{0.71, 0.72}, {0.73, 0.74}, {0.75, 0.76}},
117
+ },
118
+ {
119
+ ID: "00000000-0000-0000-0000-000000000008", Name: "h", Vector: [][]float32{{0.81, 0.82}, {0.83, 0.84}, {0.85, 0.86}},
120
+ },
121
+ {
122
+ ID: "00000000-0000-0000-0000-000000000009", Name: "h", Vector: [][]float32{{0.91, 0.92}, {0.93, 0.94}, {0.95, 0.96}},
123
+ },
124
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/fixtures/food.go ADDED
@@ -0,0 +1,545 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package fixtures
13
+
14
+ import (
15
+ "context"
16
+ "fmt"
17
+ "testing"
18
+
19
+ "github.com/stretchr/testify/require"
20
+ "github.com/weaviate/weaviate-go-client/v5/weaviate"
21
+ "github.com/weaviate/weaviate/entities/models"
22
+ "github.com/weaviate/weaviate/entities/schema"
23
+ "github.com/weaviate/weaviate/usecases/config"
24
+ )
25
+
26
+ const (
27
+ PIZZA_QUATTRO_FORMAGGI_ID = "10523cdd-15a2-42f4-81fa-267fe92f7cd6"
28
+ PIZZA_FRUTTI_DI_MARE_ID = "927dd3ac-e012-4093-8007-7799cc7e81e4"
29
+ PIZZA_HAWAII_ID = "00000000-0000-0000-0000-000000000000"
30
+ PIZZA_DOENER_ID = "5b6a08ba-1d46-43aa-89cc-8b070790c6f2"
31
+ SOUP_CHICKENSOUP_ID = "8c156d37-81aa-4ce9-a811-621e2702b825"
32
+ SOUP_BEAUTIFUL_ID = "27351361-2898-4d1a-aad7-1ca48253eb0b"
33
+ SOUP_TRIPE_ID = "a0b0c0d0-2898-4d1a-aad7-1ca48253eb0b"
34
+ RISOTTO_RISI_E_BISI_ID = "da751a25-f573-4715-a893-e607b2de0ba4"
35
+ RISOTTO_ALLA_PILOTA_ID = "10c2ee44-7d58-42be-9d64-5766883ca8cb"
36
+ RISOTTO_AL_NERO_DI_SEPPIA = "696bf381-7f98-40a4-bcad-841780e00e0e"
37
+ )
38
+
39
+ var IdsByClass = map[string][]string{
40
+ "Pizza": {
41
+ PIZZA_QUATTRO_FORMAGGI_ID,
42
+ PIZZA_FRUTTI_DI_MARE_ID,
43
+ PIZZA_HAWAII_ID,
44
+ PIZZA_DOENER_ID,
45
+ },
46
+ "Soup": {
47
+ SOUP_CHICKENSOUP_ID,
48
+ SOUP_BEAUTIFUL_ID,
49
+ },
50
+ "Risotto": {
51
+ RISOTTO_RISI_E_BISI_ID,
52
+ RISOTTO_ALLA_PILOTA_ID,
53
+ RISOTTO_AL_NERO_DI_SEPPIA,
54
+ },
55
+ }
56
+
57
+ var BeaconsByClass = map[string][]map[string]string{
58
+ "Pizza": {
59
+ {"beacon": makeBeacon("Pizza", PIZZA_QUATTRO_FORMAGGI_ID)},
60
+ {"beacon": makeBeacon("Pizza", PIZZA_FRUTTI_DI_MARE_ID)},
61
+ {"beacon": makeBeacon("Pizza", PIZZA_HAWAII_ID)},
62
+ {"beacon": makeBeacon("Pizza", PIZZA_DOENER_ID)},
63
+ },
64
+ "Soup": {
65
+ {"beacon": makeBeacon("Soup", SOUP_CHICKENSOUP_ID)},
66
+ {"beacon": makeBeacon("Soup", SOUP_BEAUTIFUL_ID)},
67
+ },
68
+ "Risotto": {
69
+ {"beacon": makeBeacon("Risotto", RISOTTO_RISI_E_BISI_ID)},
70
+ {"beacon": makeBeacon("Risotto", RISOTTO_ALLA_PILOTA_ID)},
71
+ {"beacon": makeBeacon("Risotto", RISOTTO_AL_NERO_DI_SEPPIA)},
72
+ },
73
+ }
74
+
75
+ var AllIds = []string{
76
+ PIZZA_QUATTRO_FORMAGGI_ID,
77
+ PIZZA_FRUTTI_DI_MARE_ID,
78
+ PIZZA_HAWAII_ID,
79
+ PIZZA_DOENER_ID,
80
+
81
+ SOUP_CHICKENSOUP_ID,
82
+ SOUP_BEAUTIFUL_ID,
83
+
84
+ RISOTTO_RISI_E_BISI_ID,
85
+ RISOTTO_ALLA_PILOTA_ID,
86
+ RISOTTO_AL_NERO_DI_SEPPIA,
87
+ }
88
+
89
+ func makeBeacon(class, id string) string {
90
+ return fmt.Sprintf("weaviate://localhost/%s/%s", class, id)
91
+ }
92
+
93
+ // ##### SCHEMA #####
94
+
95
+ func CreateSchemaPizza(t *testing.T, client *weaviate.Client) {
96
+ createSchema(t, client, classPizza())
97
+ }
98
+
99
+ func CreateSchemaSoup(t *testing.T, client *weaviate.Client) {
100
+ createSchema(t, client, classSoup())
101
+ }
102
+
103
+ func CreateSchemaRisotto(t *testing.T, client *weaviate.Client) {
104
+ createSchema(t, client, classRisotto())
105
+ }
106
+
107
+ func CreateSchemaFood(t *testing.T, client *weaviate.Client) {
108
+ CreateSchemaPizza(t, client)
109
+ CreateSchemaSoup(t, client)
110
+ CreateSchemaRisotto(t, client)
111
+ }
112
+
113
+ func CreateSchemaPizzaForTenants(t *testing.T, client *weaviate.Client) {
114
+ createSchema(t, client, classForTenants(classPizza()))
115
+ }
116
+
117
+ func CreateSchemaPizzaForTenantsWithReplication(t *testing.T, client *weaviate.Client, replicationFactor int64) {
118
+ createSchema(t, client, classWithReplication(classForTenants(classPizza()), replicationFactor))
119
+ }
120
+
121
+ func CreateSchemaSoupForTenants(t *testing.T, client *weaviate.Client) {
122
+ createSchema(t, client, classForTenants(classSoup()))
123
+ }
124
+
125
+ func CreateSchemaRisottoForTenants(t *testing.T, client *weaviate.Client) {
126
+ createSchema(t, client, classForTenants(classRisotto()))
127
+ }
128
+
129
+ func CreateSchemaFoodForTenants(t *testing.T, client *weaviate.Client) {
130
+ CreateSchemaPizzaForTenants(t, client)
131
+ CreateSchemaSoupForTenants(t, client)
132
+ CreateSchemaRisottoForTenants(t, client)
133
+ }
134
+
135
+ func createSchema(t *testing.T, client *weaviate.Client, class *models.Class) {
136
+ err := client.Schema().ClassCreator().
137
+ WithClass(class).
138
+ Do(context.Background())
139
+ if err != nil {
140
+ return
141
+ }
142
+
143
+ require.Nil(t, err)
144
+ }
145
+
146
+ // ##### CLASSES #####
147
+
148
+ func classPizza() *models.Class {
149
+ return &models.Class{
150
+ Class: "Pizza",
151
+ Description: "A delicious religion like food and arguably the best export of Italy.",
152
+ InvertedIndexConfig: &models.InvertedIndexConfig{IndexTimestamps: true, UsingBlockMaxWAND: config.DefaultUsingBlockMaxWAND},
153
+ Properties: classPropertiesFood(),
154
+ }
155
+ }
156
+
157
+ func classSoup() *models.Class {
158
+ return &models.Class{
159
+ Class: "Soup",
160
+ Description: "Mostly water based brew of sustenance for humans.",
161
+ Properties: classPropertiesFood(),
162
+ }
163
+ }
164
+
165
+ func classRisotto() *models.Class {
166
+ return &models.Class{
167
+ Class: "Risotto",
168
+ Description: "Risotto is a northern Italian rice dish cooked with broth.",
169
+ InvertedIndexConfig: &models.InvertedIndexConfig{IndexTimestamps: true, UsingBlockMaxWAND: config.DefaultUsingBlockMaxWAND},
170
+ Properties: classPropertiesFood(),
171
+ }
172
+ }
173
+
174
+ func classForTenants(class *models.Class) *models.Class {
175
+ class.MultiTenancyConfig = &models.MultiTenancyConfig{
176
+ Enabled: true,
177
+ }
178
+ return class
179
+ }
180
+
181
+ func classWithReplication(class *models.Class, replicationFactor int64) *models.Class {
182
+ class.ReplicationConfig = &models.ReplicationConfig{
183
+ Factor: replicationFactor,
184
+ }
185
+ return class
186
+ }
187
+
188
+ func classPropertiesFood() []*models.Property {
189
+ nameProperty := &models.Property{
190
+ Name: "name",
191
+ Description: "name",
192
+ DataType: schema.DataTypeText.PropString(),
193
+ Tokenization: models.PropertyTokenizationField,
194
+ }
195
+ descriptionProperty := &models.Property{
196
+ Name: "description",
197
+ Description: "description",
198
+ DataType: schema.DataTypeText.PropString(),
199
+ }
200
+ bestBeforeProperty := &models.Property{
201
+ Name: "best_before",
202
+ Description: "You better eat this food before it expires",
203
+ DataType: schema.DataTypeDate.PropString(),
204
+ }
205
+ priceProperty := &models.Property{
206
+ Name: "price",
207
+ Description: "price",
208
+ DataType: schema.DataTypeNumber.PropString(),
209
+ ModuleConfig: map[string]interface{}{
210
+ "text2vec-contextionary": map[string]interface{}{
211
+ "skip": true,
212
+ },
213
+ },
214
+ }
215
+
216
+ return []*models.Property{
217
+ nameProperty, descriptionProperty, bestBeforeProperty, priceProperty,
218
+ }
219
+ }
220
+
221
+ // ##### DATA #####
222
+
223
+ func CreateDataPizza(t *testing.T, client *weaviate.Client) {
224
+ createData(t, client, []*models.Object{
225
+ objectPizzaQuattroFormaggi(),
226
+ objectPizzaFruttiDiMare(),
227
+ objectPizzaHawaii(),
228
+ objectPizzaDoener(),
229
+ })
230
+ }
231
+
232
+ func CreateDataSoup(t *testing.T, client *weaviate.Client) {
233
+ createData(t, client, []*models.Object{
234
+ objectSoupChicken(),
235
+ objectSoupBeautiful(),
236
+ })
237
+ }
238
+
239
+ func CreateDataRisotto(t *testing.T, client *weaviate.Client) {
240
+ createData(t, client, []*models.Object{
241
+ objectRisottoRisiEBisi(),
242
+ objectRisottoAllaPilota(),
243
+ objectRisottoAlNeroDiSeppia(),
244
+ })
245
+ }
246
+
247
+ func CreateDataFood(t *testing.T, client *weaviate.Client) {
248
+ createData(t, client, []*models.Object{
249
+ objectPizzaQuattroFormaggi(),
250
+ objectPizzaFruttiDiMare(),
251
+ objectPizzaHawaii(),
252
+ objectPizzaDoener(),
253
+
254
+ objectSoupChicken(),
255
+ objectSoupBeautiful(),
256
+
257
+ objectRisottoRisiEBisi(),
258
+ objectRisottoAllaPilota(),
259
+ objectRisottoAlNeroDiSeppia(),
260
+ })
261
+ }
262
+
263
+ func createData(t *testing.T, client *weaviate.Client, objects []*models.Object) {
264
+ resp, err := client.Batch().ObjectsBatcher().
265
+ WithObjects(objects...).
266
+ Do(context.Background())
267
+
268
+ require.Nil(t, err)
269
+ require.NotNil(t, resp)
270
+ require.Len(t, resp, len(objects))
271
+ }
272
+
273
+ func CreateDataPizzaQuattroFormaggiForTenants(t *testing.T, client *weaviate.Client, tenantNames ...string) {
274
+ createDataForTenants(t, client, tenantNames, func() []*models.Object {
275
+ return []*models.Object{
276
+ objectPizzaQuattroFormaggi(),
277
+ }
278
+ })
279
+ }
280
+
281
+ func CreateDataPizzaFruttiDiMareForTenants(t *testing.T, client *weaviate.Client, tenantNames ...string) {
282
+ createDataForTenants(t, client, tenantNames, func() []*models.Object {
283
+ return []*models.Object{
284
+ objectPizzaFruttiDiMare(),
285
+ }
286
+ })
287
+ }
288
+
289
+ func CreateDataPizzaHawaiiForTenants(t *testing.T, client *weaviate.Client, tenantNames ...string) {
290
+ createDataForTenants(t, client, tenantNames, func() []*models.Object {
291
+ return []*models.Object{
292
+ objectPizzaHawaii(),
293
+ }
294
+ })
295
+ }
296
+
297
+ func CreateDataPizzaDoenerForTenants(t *testing.T, client *weaviate.Client, tenantNames ...string) {
298
+ createDataForTenants(t, client, tenantNames, func() []*models.Object {
299
+ return []*models.Object{
300
+ objectPizzaDoener(),
301
+ }
302
+ })
303
+ }
304
+
305
+ func CreateDataPizzaForTenants(t *testing.T, client *weaviate.Client, tenantNames ...string) {
306
+ createDataForTenants(t, client, tenantNames, func() []*models.Object {
307
+ return []*models.Object{
308
+ objectPizzaQuattroFormaggi(),
309
+ objectPizzaFruttiDiMare(),
310
+ objectPizzaHawaii(),
311
+ objectPizzaDoener(),
312
+ }
313
+ })
314
+ }
315
+
316
+ func CreateDataSoupChickenForTenants(t *testing.T, client *weaviate.Client, tenantNames ...string) {
317
+ createDataForTenants(t, client, tenantNames, func() []*models.Object {
318
+ return []*models.Object{
319
+ objectSoupChicken(),
320
+ }
321
+ })
322
+ }
323
+
324
+ func CreateDataSoupBeautifulForTenants(t *testing.T, client *weaviate.Client, tenantNames ...string) {
325
+ createDataForTenants(t, client, tenantNames, func() []*models.Object {
326
+ return []*models.Object{
327
+ objectSoupBeautiful(),
328
+ }
329
+ })
330
+ }
331
+
332
+ func CreateDataSoupForTenants(t *testing.T, client *weaviate.Client, tenantNames ...string) {
333
+ createDataForTenants(t, client, tenantNames, func() []*models.Object {
334
+ return []*models.Object{
335
+ objectSoupChicken(),
336
+ objectSoupBeautiful(),
337
+ }
338
+ })
339
+ }
340
+
341
+ func CreateDataRisottoForTenants(t *testing.T, client *weaviate.Client, tenantNames ...string) {
342
+ createDataForTenants(t, client, tenantNames, func() []*models.Object {
343
+ return []*models.Object{
344
+ objectRisottoRisiEBisi(),
345
+ objectRisottoAllaPilota(),
346
+ objectRisottoAlNeroDiSeppia(),
347
+ }
348
+ })
349
+ }
350
+
351
+ func CreateDataFoodForTenants(t *testing.T, client *weaviate.Client, tenantNames ...string) {
352
+ createDataForTenants(t, client, tenantNames, func() []*models.Object {
353
+ return []*models.Object{
354
+ objectPizzaQuattroFormaggi(),
355
+ objectPizzaFruttiDiMare(),
356
+ objectPizzaHawaii(),
357
+ objectPizzaDoener(),
358
+
359
+ objectSoupChicken(),
360
+ objectSoupBeautiful(),
361
+
362
+ objectRisottoRisiEBisi(),
363
+ objectRisottoAllaPilota(),
364
+ objectRisottoAlNeroDiSeppia(),
365
+ }
366
+ })
367
+ }
368
+
369
+ func createDataForTenants(t *testing.T, client *weaviate.Client,
370
+ tenantNames []string, objectsSupplier func() []*models.Object,
371
+ ) {
372
+ objects := []*models.Object{}
373
+ for _, name := range tenantNames {
374
+ for _, object := range objectsSupplier() {
375
+ object.Tenant = name
376
+ objects = append(objects, object)
377
+ }
378
+ }
379
+ createData(t, client, objects)
380
+ }
381
+
382
+ // ##### OBJECTS #####
383
+
384
+ func objectPizzaQuattroFormaggi() *models.Object {
385
+ return &models.Object{
386
+ Class: "Pizza",
387
+ ID: PIZZA_QUATTRO_FORMAGGI_ID,
388
+ Properties: map[string]interface{}{
389
+ "name": "Quattro Formaggi",
390
+ "description": "Pizza quattro formaggi Italian: [ˈkwattro forˈmaddʒi] (four cheese pizza) is a variety of pizza in Italian cuisine that is topped with a combination of four kinds of cheese, usually melted together, with (rossa, red) or without (bianca, white) tomato sauce. It is popular worldwide, including in Italy,[1] and is one of the iconic items from pizzerias's menus.",
391
+ "price": float32(1.1),
392
+ "best_before": "2022-05-03T12:04:40+02:00",
393
+ },
394
+ }
395
+ }
396
+
397
+ func objectPizzaFruttiDiMare() *models.Object {
398
+ return &models.Object{
399
+ Class: "Pizza",
400
+ ID: PIZZA_FRUTTI_DI_MARE_ID,
401
+ Properties: map[string]interface{}{
402
+ "name": "Frutti di Mare",
403
+ "description": "Frutti di Mare is an Italian type of pizza that may be served with scampi, mussels or squid. It typically lacks cheese, with the seafood being served atop a tomato sauce.",
404
+ "price": float32(1.2),
405
+ "best_before": "2022-05-05T07:16:30+02:00",
406
+ },
407
+ }
408
+ }
409
+
410
+ func objectPizzaHawaii() *models.Object {
411
+ return &models.Object{
412
+ Class: "Pizza",
413
+ // this uuid guarantees that it's the first for cursor tests (otherwise
414
+ // they might be flaky if the randomly generated ids are sometimes higher
415
+ // and sometimes lower
416
+ ID: PIZZA_HAWAII_ID,
417
+ Properties: map[string]interface{}{
418
+ "name": "Hawaii",
419
+ "description": "Universally accepted to be the best pizza ever created.",
420
+ "price": float32(1.3),
421
+ },
422
+ }
423
+ }
424
+
425
+ func objectPizzaDoener() *models.Object {
426
+ return &models.Object{
427
+ Class: "Pizza",
428
+ ID: PIZZA_DOENER_ID,
429
+ Properties: map[string]interface{}{
430
+ "name": "Doener",
431
+ "description": "A innovation, some say revolution, in the pizza industry.",
432
+ "price": float32(1.4),
433
+ },
434
+ }
435
+ }
436
+
437
+ func objectSoupChicken() *models.Object {
438
+ return &models.Object{
439
+ Class: "Soup",
440
+ ID: SOUP_CHICKENSOUP_ID,
441
+ Properties: map[string]interface{}{
442
+ "name": "ChickenSoup",
443
+ "description": "Used by humans when their inferior genetics are attacked by microscopic organisms.",
444
+ "price": float32(2.1),
445
+ },
446
+ }
447
+ }
448
+
449
+ func objectSoupBeautiful() *models.Object {
450
+ return &models.Object{
451
+ Class: "Soup",
452
+ ID: SOUP_BEAUTIFUL_ID,
453
+ Properties: map[string]interface{}{
454
+ "name": "Beautiful",
455
+ "description": "Putting the game of letter soups to a whole new level.",
456
+ "price": float32(2.2),
457
+ },
458
+ }
459
+ }
460
+
461
+ func objectRisottoRisiEBisi() *models.Object {
462
+ return &models.Object{
463
+ Class: "Risotto",
464
+ ID: RISOTTO_RISI_E_BISI_ID,
465
+ Properties: map[string]interface{}{
466
+ "name": "Risi e bisi",
467
+ "description": "A Veneto spring dish.",
468
+ "price": float32(3.1),
469
+ "best_before": "2022-05-03T12:04:40+02:00",
470
+ },
471
+ }
472
+ }
473
+
474
+ func objectRisottoAllaPilota() *models.Object {
475
+ return &models.Object{
476
+ Class: "Risotto",
477
+ ID: RISOTTO_ALLA_PILOTA_ID,
478
+ Properties: map[string]interface{}{
479
+ "name": "Risotto alla pilota",
480
+ "description": "A specialty of Mantua, made with sausage, pork, and Parmesan cheese.",
481
+ "price": float32(3.2),
482
+ "best_before": "2022-05-03T12:04:40+02:00",
483
+ },
484
+ }
485
+ }
486
+
487
+ func objectRisottoAlNeroDiSeppia() *models.Object {
488
+ return &models.Object{
489
+ Class: "Risotto",
490
+ ID: RISOTTO_AL_NERO_DI_SEPPIA,
491
+ Properties: map[string]interface{}{
492
+ "name": "Risotto al nero di seppia",
493
+ "description": "A specialty of the Veneto region, made with cuttlefish cooked with their ink-sacs intact, leaving the risotto black .",
494
+ "price": float32(3.3),
495
+ },
496
+ }
497
+ }
498
+
499
+ // ##### TENANTS #####
500
+
501
+ func CreateTenantsPizza(t *testing.T, client *weaviate.Client, tenants ...models.Tenant) {
502
+ createTenants(t, client, "Pizza", tenants)
503
+ }
504
+
505
+ func CreateTenantsSoup(t *testing.T, client *weaviate.Client, tenants ...models.Tenant) {
506
+ createTenants(t, client, "Soup", tenants)
507
+ }
508
+
509
+ func CreateTenantsRisotto(t *testing.T, client *weaviate.Client, tenants ...models.Tenant) {
510
+ createTenants(t, client, "Risotto", tenants)
511
+ }
512
+
513
+ func CreateTenantsFood(t *testing.T, client *weaviate.Client, tenants ...models.Tenant) {
514
+ CreateTenantsPizza(t, client, tenants...)
515
+ CreateTenantsSoup(t, client, tenants...)
516
+ CreateTenantsRisotto(t, client, tenants...)
517
+ }
518
+
519
+ func createTenants(t *testing.T, client *weaviate.Client, className string, tenants []models.Tenant) {
520
+ err := client.Schema().TenantsCreator().
521
+ WithClassName(className).
522
+ WithTenants(tenants...).
523
+ Do(context.Background())
524
+
525
+ require.Nil(t, err)
526
+ }
527
+
528
+ type Tenants []models.Tenant
529
+
530
+ func (t Tenants) Names() []string {
531
+ names := make([]string, len(t))
532
+ for i, tenant := range t {
533
+ names[i] = tenant.Name
534
+ }
535
+ return names
536
+ }
537
+
538
+ func (t Tenants) ByName(name string) *models.Tenant {
539
+ for _, tenant := range t {
540
+ if tenant.Name == name {
541
+ return &tenant
542
+ }
543
+ }
544
+ return nil
545
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/fixtures/vector_index_configs.go ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package fixtures
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/grpc_tests/batch_grpc_test.go ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package grpc_tests
13
+
14
+ import (
15
+ "context"
16
+ "testing"
17
+ "time"
18
+
19
+ "acceptance_tests_with_client/fixtures"
20
+
21
+ "github.com/go-openapi/strfmt"
22
+ "github.com/stretchr/testify/assert"
23
+ "github.com/stretchr/testify/require"
24
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
25
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/grpc"
26
+ "github.com/weaviate/weaviate/entities/models"
27
+ "github.com/weaviate/weaviate/test/docker"
28
+ )
29
+
30
+ func TestGRPC_Batch(t *testing.T) {
31
+ ctx := context.Background()
32
+ config := wvt.Config{Scheme: "http", Host: "localhost:8080", GrpcConfig: &grpc.Config{Host: "localhost:50051"}}
33
+ client, err := wvt.NewClient(config)
34
+ require.NoError(t, err)
35
+ require.NotNil(t, client)
36
+ // clean DB
37
+ err = client.Schema().AllDeleter().Do(ctx)
38
+ require.NoError(t, err)
39
+ t.Run("all properties", testGRPCBatchAPI(ctx, client))
40
+ }
41
+
42
+ func TestGRPC_Batch_Cluster(t *testing.T) {
43
+ ctx := context.Background()
44
+ compose, err := docker.New().
45
+ WithWeaviateClusterWithGRPC().
46
+ WithText2VecContextionary().
47
+ Start(ctx)
48
+ require.NoError(t, err)
49
+ defer func() {
50
+ require.NoError(t, compose.Terminate(ctx))
51
+ }()
52
+
53
+ httpUri := compose.GetWeaviateNode(2).GetEndpoint(docker.HTTP)
54
+ grpcUri := compose.GetWeaviateNode(2).GetEndpoint(docker.GRPC)
55
+
56
+ config := wvt.Config{
57
+ Scheme: "http", Host: httpUri,
58
+ GrpcConfig: &grpc.Config{Host: grpcUri},
59
+ StartupTimeout: 30 * time.Second,
60
+ }
61
+ client, err := wvt.NewClient(config)
62
+ require.NoError(t, err)
63
+ require.NotNil(t, client)
64
+
65
+ // clean DB
66
+ err = client.Schema().AllDeleter().Do(ctx)
67
+ require.NoError(t, err)
68
+
69
+ t.Run("all properties", testGRPCBatchAPI(ctx, client))
70
+ t.Run("multi vectors", testGRPCBatchImportColBERT(ctx, client))
71
+ }
72
+
73
+ func testGRPCBatchAPI(ctx context.Context, client *wvt.Client) func(t *testing.T) {
74
+ return func(t *testing.T) {
75
+ class := fixtures.AllPropertiesClass
76
+ className := fixtures.AllPropertiesClassName
77
+ id1 := fixtures.AllPropertiesID1
78
+ properties := fixtures.AllPropertiesProperties
79
+ t.Run("create schema", func(t *testing.T) {
80
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
81
+ require.NoError(t, err)
82
+ })
83
+ t.Run("grpc batch import", func(t *testing.T) {
84
+ objects := []*models.Object{
85
+ {
86
+ Class: className,
87
+ ID: strfmt.UUID(id1),
88
+ // These properties slightly differ from the one defined in the class. We are laying them all out as
89
+ // "base" properties and not as nested properties.
90
+ // This will cause auto schema to kick in and will make the follower have eventual consistency on the
91
+ // schema changes. With proper internal retry mechanism this will be transparent to the client.
92
+ Properties: properties,
93
+ },
94
+ }
95
+ resp, err := client.Batch().ObjectsBatcher().WithObjects(objects...).Do(ctx)
96
+ require.NoError(t, err)
97
+ require.NotNil(t, resp)
98
+ require.Len(t, resp, 1)
99
+ require.NotNil(t, resp[0].Result)
100
+ assert.Nil(t, resp[0].Result.Errors)
101
+ })
102
+ t.Run("check", func(t *testing.T) {
103
+ objs, err := client.Data().ObjectsGetter().WithClassName(className).WithID(id1).Do(ctx)
104
+ require.NoError(t, err)
105
+ require.NotNil(t, objs)
106
+ require.Len(t, objs, 1)
107
+ assert.Equal(t, className, objs[0].Class)
108
+ // We check that the properties are layed out and not nested. This indicates auto schema did it's job.
109
+ objectProperties, ok := objs[0].Properties.(map[string]interface{})
110
+ require.True(t, ok)
111
+ require.Equal(t, len(properties), len(objectProperties))
112
+ })
113
+ }
114
+ }
115
+
116
+ func testGRPCBatchImportColBERT(ctx context.Context, client *wvt.Client) func(t *testing.T) {
117
+ return func(t *testing.T) {
118
+ className := fixtures.BringYourOwnColBERTClassName
119
+ class := fixtures.BringYourOwnColBERTClass(className)
120
+ objects := fixtures.BringYourOwnColBERTObjects
121
+ byoc := fixtures.BringYourOwnColBERTNamedVectorName
122
+ t.Run("create schema", func(t *testing.T) {
123
+ err := client.Schema().ClassCreator().WithClass(class).Do(ctx)
124
+ require.NoError(t, err)
125
+ })
126
+ t.Run("batch import", func(t *testing.T) {
127
+ objs := []*models.Object{}
128
+ for _, o := range objects {
129
+ obj := &models.Object{
130
+ Class: className,
131
+ ID: strfmt.UUID(o.ID),
132
+ Properties: map[string]interface{}{
133
+ "name": o.Name,
134
+ },
135
+ Vectors: models.Vectors{
136
+ byoc: o.Vector,
137
+ },
138
+ }
139
+ objs = append(objs, obj)
140
+ }
141
+ resp, err := client.Batch().ObjectsBatcher().WithObjects(objs...).Do(ctx)
142
+ require.NoError(t, err)
143
+ require.NotNil(t, resp)
144
+ require.Len(t, resp, len(objs))
145
+ for i := range objs {
146
+ require.NotNil(t, resp[i].Result)
147
+ assert.Nil(t, resp[i].Result.Errors)
148
+ }
149
+ })
150
+ t.Run("check", func(t *testing.T) {
151
+ for _, o := range objects {
152
+ objs, err := client.Data().ObjectsGetter().WithClassName(className).WithID(o.ID).WithVector().Do(ctx)
153
+ require.NoError(t, err)
154
+ require.NotNil(t, objs)
155
+ require.Len(t, objs, 1)
156
+ assert.Equal(t, className, objs[0].Class)
157
+ require.Len(t, objs[0].Vectors, 1)
158
+ require.IsType(t, [][]float32{}, objs[0].Vectors[byoc])
159
+ assert.Equal(t, o.Vector, objs[0].Vectors[byoc])
160
+ }
161
+ })
162
+ }
163
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/multi_tenancy_tests/activation_deactivation_test.go ADDED
@@ -0,0 +1,664 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package multi_tenancy_tests
13
+
14
+ import (
15
+ "context"
16
+ "fmt"
17
+ "testing"
18
+ "time"
19
+
20
+ "acceptance_tests_with_client/fixtures"
21
+
22
+ "github.com/stretchr/testify/assert"
23
+ "github.com/stretchr/testify/require"
24
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
25
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/fault"
26
+ "github.com/weaviate/weaviate/entities/models"
27
+ "github.com/weaviate/weaviate/test/docker"
28
+ )
29
+
30
+ func TestActivationDeactivation(t *testing.T) {
31
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: "localhost:8080"})
32
+ require.Nil(t, err)
33
+
34
+ cleanup := func() {
35
+ err := client.Schema().AllDeleter().Do(context.Background())
36
+ require.Nil(t, err)
37
+ }
38
+
39
+ t.Run("deactivate / activate journey", func(t *testing.T) {
40
+ defer cleanup()
41
+
42
+ tenants := fixtures.Tenants{
43
+ {
44
+ Name: "tenantNo1",
45
+ // default status HOT
46
+ },
47
+ {
48
+ Name: "tenantNo2",
49
+ ActivityStatus: models.TenantActivityStatusHOT,
50
+ },
51
+ {
52
+ Name: "tenantNo3",
53
+ ActivityStatus: models.TenantActivityStatusCOLD,
54
+ },
55
+ }
56
+ className := "Pizza"
57
+ ctx := context.Background()
58
+ pizzaIds := fixtures.IdsByClass[className]
59
+
60
+ t.Run("create tenants (1,2,3), populate active tenants (1,2)", func(t *testing.T) {
61
+ fixtures.CreateSchemaPizzaForTenants(t, client)
62
+ fixtures.CreateTenantsPizza(t, client, tenants...)
63
+ fixtures.CreateDataPizzaForTenants(t, client, tenants[:2].Names()...)
64
+
65
+ assertTenantActive(t, client, className, tenants[0].Name)
66
+ assertTenantActive(t, client, className, tenants[1].Name)
67
+ assertTenantInactive(t, client, className, tenants[2].Name)
68
+
69
+ assertActiveTenantObjects(t, client, className, tenants[0].Name, pizzaIds)
70
+ assertActiveTenantObjects(t, client, className, tenants[1].Name, pizzaIds)
71
+ assertInactiveTenantObjects(t, client, className, tenants[2].Name)
72
+ })
73
+
74
+ t.Run("deactivate tenant (1)", func(t *testing.T) {
75
+ err := client.Schema().TenantsUpdater().
76
+ WithClassName(className).
77
+ WithTenants(models.Tenant{
78
+ Name: tenants[0].Name,
79
+ ActivityStatus: models.TenantActivityStatusCOLD,
80
+ }).
81
+ Do(ctx)
82
+ require.Nil(t, err)
83
+
84
+ assertTenantInactive(t, client, className, tenants[0].Name)
85
+ assertTenantActive(t, client, className, tenants[1].Name)
86
+ assertTenantInactive(t, client, className, tenants[2].Name)
87
+
88
+ assertInactiveTenantObjects(t, client, className, tenants[0].Name)
89
+ assertActiveTenantObjects(t, client, className, tenants[1].Name, pizzaIds)
90
+ assertInactiveTenantObjects(t, client, className, tenants[2].Name)
91
+ })
92
+
93
+ t.Run("activate and populate tenant (3)", func(t *testing.T) {
94
+ err := client.Schema().TenantsUpdater().
95
+ WithClassName(className).
96
+ WithTenants(models.Tenant{
97
+ Name: tenants[2].Name,
98
+ ActivityStatus: models.TenantActivityStatusHOT,
99
+ }).
100
+ Do(ctx)
101
+ require.Nil(t, err)
102
+
103
+ fixtures.CreateDataPizzaForTenants(t, client, tenants[2].Name)
104
+
105
+ assertTenantInactive(t, client, className, tenants[0].Name)
106
+ assertTenantActive(t, client, className, tenants[1].Name)
107
+ assertTenantActive(t, client, className, tenants[2].Name)
108
+
109
+ assertInactiveTenantObjects(t, client, className, tenants[0].Name)
110
+ assertActiveTenantObjects(t, client, className, tenants[1].Name, pizzaIds)
111
+ assertActiveTenantObjects(t, client, className, tenants[2].Name, pizzaIds)
112
+ })
113
+
114
+ t.Run("activate tenant (1)", func(t *testing.T) {
115
+ err := client.Schema().TenantsUpdater().
116
+ WithClassName(className).
117
+ WithTenants(models.Tenant{
118
+ Name: tenants[0].Name,
119
+ ActivityStatus: models.TenantActivityStatusHOT,
120
+ }).
121
+ Do(ctx)
122
+ require.Nil(t, err)
123
+
124
+ assertTenantActive(t, client, className, tenants[0].Name)
125
+ assertTenantActive(t, client, className, tenants[1].Name)
126
+ assertTenantActive(t, client, className, tenants[2].Name)
127
+
128
+ assertActiveTenantObjects(t, client, className, tenants[0].Name, pizzaIds)
129
+ assertActiveTenantObjects(t, client, className, tenants[1].Name, pizzaIds)
130
+ assertActiveTenantObjects(t, client, className, tenants[2].Name, pizzaIds)
131
+ })
132
+
133
+ t.Run("deactivate tenant (2)", func(t *testing.T) {
134
+ err := client.Schema().TenantsUpdater().
135
+ WithClassName(className).
136
+ WithTenants(models.Tenant{
137
+ Name: tenants[1].Name,
138
+ ActivityStatus: models.TenantActivityStatusCOLD,
139
+ }).
140
+ Do(ctx)
141
+ require.Nil(t, err)
142
+
143
+ assertTenantActive(t, client, className, tenants[0].Name)
144
+ assertTenantInactive(t, client, className, tenants[1].Name)
145
+ assertTenantActive(t, client, className, tenants[2].Name)
146
+
147
+ assertActiveTenantObjects(t, client, className, tenants[0].Name, pizzaIds)
148
+ assertInactiveTenantObjects(t, client, className, tenants[1].Name)
149
+ assertActiveTenantObjects(t, client, className, tenants[2].Name, pizzaIds)
150
+ })
151
+
152
+ t.Run("delete tenants", func(t *testing.T) {
153
+ err := client.Schema().TenantsDeleter().
154
+ WithClassName(className).
155
+ WithTenants(tenants.Names()...).
156
+ Do(ctx)
157
+
158
+ require.Nil(t, err)
159
+ })
160
+ })
161
+ }
162
+
163
+ type composeFn func(t *testing.T, ctx context.Context) (
164
+ client *wvt.Client,
165
+ cleanupFn func(t *testing.T, ctx context.Context),
166
+ restartFn func(t *testing.T, ctx context.Context) *wvt.Client)
167
+
168
+ func TestActivationDeactivation_Restarts(t *testing.T) {
169
+ t.Run("single node", func(t *testing.T) {
170
+ composeFn := func(t *testing.T, ctx context.Context) (
171
+ client *wvt.Client,
172
+ cleanupFn func(t *testing.T, ctx context.Context),
173
+ restartFn func(t *testing.T, ctx context.Context) *wvt.Client,
174
+ ) {
175
+ compose, err := docker.New().WithWeaviate().Start(ctx)
176
+ require.Nil(t, err)
177
+
178
+ container := compose.GetWeaviate()
179
+ client, err = wvt.NewClient(wvt.Config{Scheme: "http", Host: container.URI()})
180
+ require.Nil(t, err)
181
+
182
+ cleanupFn = func(t *testing.T, ctx context.Context) {
183
+ err := compose.Terminate(ctx)
184
+ require.Nil(t, err)
185
+ }
186
+
187
+ restartFn = func(t *testing.T, ctx context.Context) *wvt.Client {
188
+ require.Nil(t, compose.Stop(ctx, container.Name(), nil))
189
+ require.Nil(t, compose.Start(ctx, container.Name()))
190
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: container.URI()})
191
+ require.Nil(t, err)
192
+
193
+ return client
194
+ }
195
+
196
+ return
197
+ }
198
+
199
+ testActivationDeactivationWithRestarts(t, composeFn)
200
+ })
201
+
202
+ t.Run("multiple nodes", func(t *testing.T) {
203
+ t.Skip("flaky test")
204
+ composeFn := func(t *testing.T, ctx context.Context) (
205
+ client *wvt.Client,
206
+ cleanupFn func(t *testing.T, ctx context.Context),
207
+ restartFn func(t *testing.T, ctx context.Context) *wvt.Client,
208
+ ) {
209
+ compose, err := docker.New().WithWeaviateCluster(3).Start(ctx)
210
+ require.Nil(t, err)
211
+
212
+ client, err = wvt.NewClient(wvt.Config{Scheme: "http", Host: compose.ContainerURI(0)})
213
+ require.Nil(t, err)
214
+
215
+ cleanupFn = func(t *testing.T, ctx context.Context) {
216
+ err := compose.Terminate(ctx)
217
+ require.Nil(t, err)
218
+ }
219
+
220
+ restartFn = func(t *testing.T, ctx context.Context) *wvt.Client {
221
+ require.Nil(t, compose.StopAt(ctx, 1, nil))
222
+ require.Nil(t, compose.StartAt(ctx, 1))
223
+
224
+ require.Nil(t, compose.StopAt(ctx, 2, nil))
225
+ require.Nil(t, compose.StartAt(ctx, 2))
226
+
227
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: compose.ContainerURI(0)})
228
+ require.Nil(t, err)
229
+ return client
230
+ }
231
+
232
+ return
233
+ }
234
+
235
+ testActivationDeactivationWithRestarts(t, composeFn)
236
+ })
237
+ }
238
+
239
+ func testActivationDeactivationWithRestarts(t *testing.T, composeFn composeFn) {
240
+ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
241
+ defer cancel()
242
+
243
+ client, composeCleanup, restart := composeFn(t, ctx)
244
+ defer composeCleanup(t, ctx)
245
+
246
+ cleanup := func() {
247
+ err := client.Schema().AllDeleter().Do(context.Background())
248
+ require.Nil(t, err)
249
+ }
250
+
251
+ classPizza := "Pizza"
252
+ classSoup := "Soup"
253
+
254
+ t.Run("deactivate / activate journey", func(t *testing.T) {
255
+ defer cleanup()
256
+
257
+ createTenants := func(className string, groupId, count int, status string) fixtures.Tenants {
258
+ tenants := make(fixtures.Tenants, count)
259
+ for i := 0; i < count; i++ {
260
+ tenants[i] = models.Tenant{
261
+ Name: fmt.Sprintf("tenant_%s_%d_%d", className, groupId, i),
262
+ ActivityStatus: status,
263
+ }
264
+ }
265
+ return tenants
266
+ }
267
+ assertActiveTenants := func(t *testing.T, tenants fixtures.Tenants, className string, expectedIds []string) {
268
+ for _, tenant := range tenants {
269
+ assertTenantActive(t, client, className, tenant.Name)
270
+ assertActiveTenantObjects(t, client, className, tenant.Name, expectedIds)
271
+ }
272
+ }
273
+ assertInactiveTenants := func(t *testing.T, tenants fixtures.Tenants, className string) {
274
+ for _, tenant := range tenants {
275
+ assertTenantInactive(t, client, className, tenant.Name)
276
+ assertInactiveTenantObjects(t, client, className, tenant.Name)
277
+ }
278
+ }
279
+
280
+ tenants1Pizza := createTenants(classPizza, 1, 5, "") // default status HOT
281
+ tenants2Pizza := createTenants(classPizza, 2, 4, models.TenantActivityStatusHOT)
282
+ tenants3Pizza := createTenants(classPizza, 3, 3, models.TenantActivityStatusCOLD)
283
+ tenants1Soup := createTenants(classSoup, 1, 4, "") // default status HOT
284
+ tenants2Soup := createTenants(classSoup, 2, 3, models.TenantActivityStatusHOT)
285
+ tenants3Soup := createTenants(classSoup, 3, 2, models.TenantActivityStatusCOLD)
286
+ idsPizza := fixtures.IdsByClass[classPizza]
287
+ idsSoup := fixtures.IdsByClass[classSoup]
288
+
289
+ t.Run("create tenants (1,2,3), populate active tenants (1,2)", func(t *testing.T) {
290
+ fixtures.CreateSchemaPizzaForTenants(t, client)
291
+ fixtures.CreateTenantsPizza(t, client, tenants1Pizza...)
292
+ fixtures.CreateTenantsPizza(t, client, tenants2Pizza...)
293
+ fixtures.CreateTenantsPizza(t, client, tenants3Pizza...)
294
+ fixtures.CreateDataPizzaForTenants(t, client, tenants1Pizza.Names()...)
295
+ fixtures.CreateDataPizzaForTenants(t, client, tenants2Pizza.Names()...)
296
+
297
+ assertActiveTenants(t, tenants1Pizza, classPizza, idsPizza)
298
+ assertActiveTenants(t, tenants2Pizza, classPizza, idsPizza)
299
+ assertInactiveTenants(t, tenants3Pizza, classPizza)
300
+
301
+ fixtures.CreateSchemaSoupForTenants(t, client)
302
+ fixtures.CreateTenantsSoup(t, client, tenants1Soup...)
303
+ fixtures.CreateTenantsSoup(t, client, tenants2Soup...)
304
+ fixtures.CreateTenantsSoup(t, client, tenants3Soup...)
305
+ fixtures.CreateDataSoupForTenants(t, client, tenants1Soup.Names()...)
306
+ fixtures.CreateDataSoupForTenants(t, client, tenants2Soup.Names()...)
307
+
308
+ assertActiveTenants(t, tenants1Soup, classSoup, idsSoup)
309
+ assertActiveTenants(t, tenants2Soup, classSoup, idsSoup)
310
+ assertInactiveTenants(t, tenants3Soup, classSoup)
311
+ })
312
+
313
+ t.Run("deactivate tenants (1)", func(t *testing.T) {
314
+ tenants := make(fixtures.Tenants, len(tenants1Pizza))
315
+ for i, tenant := range tenants1Pizza {
316
+ tenants[i] = models.Tenant{
317
+ Name: tenant.Name,
318
+ ActivityStatus: models.TenantActivityStatusCOLD,
319
+ }
320
+ }
321
+
322
+ err := client.Schema().TenantsUpdater().
323
+ WithClassName(classPizza).
324
+ WithTenants(tenants...).
325
+ Do(ctx)
326
+ require.Nil(t, err)
327
+
328
+ assertInactiveTenants(t, tenants1Pizza, classPizza)
329
+ assertActiveTenants(t, tenants2Pizza, classPizza, idsPizza)
330
+ assertInactiveTenants(t, tenants3Pizza, classPizza)
331
+
332
+ tenants = make(fixtures.Tenants, len(tenants1Soup))
333
+ for i, tenant := range tenants1Soup {
334
+ tenants[i] = models.Tenant{
335
+ Name: tenant.Name,
336
+ ActivityStatus: models.TenantActivityStatusCOLD,
337
+ }
338
+ }
339
+
340
+ err = client.Schema().TenantsUpdater().
341
+ WithClassName(classSoup).
342
+ WithTenants(tenants...).
343
+ Do(ctx)
344
+ require.Nil(t, err)
345
+
346
+ assertInactiveTenants(t, tenants1Soup, classSoup)
347
+ assertActiveTenants(t, tenants2Soup, classSoup, idsSoup)
348
+ assertInactiveTenants(t, tenants3Soup, classSoup)
349
+ })
350
+
351
+ t.Run("restart db, nothing changed", func(t *testing.T) {
352
+ client = restart(t, ctx)
353
+
354
+ assertInactiveTenants(t, tenants1Pizza, classPizza)
355
+ assertActiveTenants(t, tenants2Pizza, classPizza, idsPizza)
356
+ assertInactiveTenants(t, tenants3Pizza, classPizza)
357
+
358
+ assertInactiveTenants(t, tenants1Soup, classSoup)
359
+ assertActiveTenants(t, tenants2Soup, classSoup, idsSoup)
360
+ assertInactiveTenants(t, tenants3Soup, classSoup)
361
+ })
362
+
363
+ t.Run("activate and populate tenants (3)", func(t *testing.T) {
364
+ tenants := make(fixtures.Tenants, len(tenants3Pizza))
365
+ for i, tenant := range tenants3Pizza {
366
+ tenants[i] = models.Tenant{
367
+ Name: tenant.Name,
368
+ ActivityStatus: models.TenantActivityStatusHOT,
369
+ }
370
+ }
371
+
372
+ err := client.Schema().TenantsUpdater().
373
+ WithClassName(classPizza).
374
+ WithTenants(tenants...).
375
+ Do(ctx)
376
+ require.Nil(t, err)
377
+
378
+ fixtures.CreateDataPizzaForTenants(t, client, tenants3Pizza.Names()...)
379
+
380
+ tenants = make(fixtures.Tenants, len(tenants3Soup))
381
+ for i, tenant := range tenants3Soup {
382
+ tenants[i] = models.Tenant{
383
+ Name: tenant.Name,
384
+ ActivityStatus: models.TenantActivityStatusHOT,
385
+ }
386
+ }
387
+
388
+ err = client.Schema().TenantsUpdater().
389
+ WithClassName(classSoup).
390
+ WithTenants(tenants...).
391
+ Do(ctx)
392
+ require.Nil(t, err)
393
+
394
+ fixtures.CreateDataSoupForTenants(t, client, tenants3Soup.Names()...)
395
+
396
+ assertInactiveTenants(t, tenants1Pizza, classPizza)
397
+ assertActiveTenants(t, tenants2Pizza, classPizza, idsPizza)
398
+ assertActiveTenants(t, tenants3Pizza, classPizza, idsPizza)
399
+
400
+ assertInactiveTenants(t, tenants1Soup, classSoup)
401
+ assertActiveTenants(t, tenants2Soup, classSoup, idsSoup)
402
+ assertActiveTenants(t, tenants3Soup, classSoup, idsSoup)
403
+ })
404
+
405
+ t.Run("activate tenants (1)", func(t *testing.T) {
406
+ tenants := make(fixtures.Tenants, len(tenants1Pizza))
407
+ for i, tenant := range tenants1Pizza {
408
+ tenants[i] = models.Tenant{
409
+ Name: tenant.Name,
410
+ ActivityStatus: models.TenantActivityStatusHOT,
411
+ }
412
+ }
413
+
414
+ err := client.Schema().TenantsUpdater().
415
+ WithClassName(classPizza).
416
+ WithTenants(tenants...).
417
+ Do(ctx)
418
+ require.Nil(t, err)
419
+
420
+ tenants = make(fixtures.Tenants, len(tenants1Soup))
421
+ for i, tenant := range tenants1Soup {
422
+ tenants[i] = models.Tenant{
423
+ Name: tenant.Name,
424
+ ActivityStatus: models.TenantActivityStatusHOT,
425
+ }
426
+ }
427
+
428
+ err = client.Schema().TenantsUpdater().
429
+ WithClassName(classSoup).
430
+ WithTenants(tenants...).
431
+ Do(ctx)
432
+ require.Nil(t, err)
433
+
434
+ assertActiveTenants(t, tenants1Pizza, classPizza, idsPizza)
435
+ assertActiveTenants(t, tenants2Pizza, classPizza, idsPizza)
436
+ assertActiveTenants(t, tenants3Pizza, classPizza, idsPizza)
437
+
438
+ assertActiveTenants(t, tenants1Soup, classSoup, idsSoup)
439
+ assertActiveTenants(t, tenants2Soup, classSoup, idsSoup)
440
+ assertActiveTenants(t, tenants3Soup, classSoup, idsSoup)
441
+ })
442
+
443
+ t.Run("deactivate tenants (2)", func(t *testing.T) {
444
+ tenants := make(fixtures.Tenants, len(tenants2Pizza))
445
+ for i, tenant := range tenants2Pizza {
446
+ tenants[i] = models.Tenant{
447
+ Name: tenant.Name,
448
+ ActivityStatus: models.TenantActivityStatusCOLD,
449
+ }
450
+ }
451
+
452
+ err := client.Schema().TenantsUpdater().
453
+ WithClassName(classPizza).
454
+ WithTenants(tenants...).
455
+ Do(ctx)
456
+ require.Nil(t, err)
457
+
458
+ tenants = make(fixtures.Tenants, len(tenants2Soup))
459
+ for i, tenant := range tenants2Soup {
460
+ tenants[i] = models.Tenant{
461
+ Name: tenant.Name,
462
+ ActivityStatus: models.TenantActivityStatusCOLD,
463
+ }
464
+ }
465
+
466
+ err = client.Schema().TenantsUpdater().
467
+ WithClassName(classSoup).
468
+ WithTenants(tenants...).
469
+ Do(ctx)
470
+ require.Nil(t, err)
471
+
472
+ assertActiveTenants(t, tenants1Pizza, classPizza, idsPizza)
473
+ assertInactiveTenants(t, tenants2Pizza, classPizza)
474
+ assertActiveTenants(t, tenants3Pizza, classPizza, idsPizza)
475
+
476
+ assertActiveTenants(t, tenants1Soup, classSoup, idsSoup)
477
+ assertInactiveTenants(t, tenants2Soup, classSoup)
478
+ assertActiveTenants(t, tenants3Soup, classSoup, idsSoup)
479
+ })
480
+
481
+ t.Run("restart db, nothing changed", func(t *testing.T) {
482
+ client = restart(t, ctx)
483
+
484
+ assertActiveTenants(t, tenants1Pizza, classPizza, idsPizza)
485
+ assertInactiveTenants(t, tenants2Pizza, classPizza)
486
+ assertActiveTenants(t, tenants3Pizza, classPizza, idsPizza)
487
+
488
+ assertActiveTenants(t, tenants1Soup, classSoup, idsSoup)
489
+ assertInactiveTenants(t, tenants2Soup, classSoup)
490
+ assertActiveTenants(t, tenants3Soup, classSoup, idsSoup)
491
+ })
492
+
493
+ t.Run("activate already active (1,3), deactivate already inactive (2), nothing changed", func(t *testing.T) {
494
+ tenants := make(fixtures.Tenants, 0, len(tenants1Pizza)+len(tenants2Pizza)+len(tenants3Pizza))
495
+ for _, tenant := range tenants1Pizza {
496
+ tenants = append(tenants, models.Tenant{
497
+ Name: tenant.Name,
498
+ ActivityStatus: models.TenantActivityStatusHOT,
499
+ })
500
+ }
501
+ for _, tenant := range tenants2Pizza {
502
+ tenants = append(tenants, models.Tenant{
503
+ Name: tenant.Name,
504
+ ActivityStatus: models.TenantActivityStatusCOLD,
505
+ })
506
+ }
507
+ for _, tenant := range tenants3Pizza {
508
+ tenants = append(tenants, models.Tenant{
509
+ Name: tenant.Name,
510
+ ActivityStatus: models.TenantActivityStatusHOT,
511
+ })
512
+ }
513
+
514
+ err := client.Schema().TenantsUpdater().
515
+ WithClassName(classPizza).
516
+ WithTenants(tenants...).
517
+ Do(ctx)
518
+ require.Nil(t, err)
519
+
520
+ tenants = make(fixtures.Tenants, 0, len(tenants1Soup)+len(tenants2Soup)+len(tenants3Soup))
521
+ for _, tenant := range tenants1Soup {
522
+ tenants = append(tenants, models.Tenant{
523
+ Name: tenant.Name,
524
+ ActivityStatus: models.TenantActivityStatusHOT,
525
+ })
526
+ }
527
+ for _, tenant := range tenants2Soup {
528
+ tenants = append(tenants, models.Tenant{
529
+ Name: tenant.Name,
530
+ ActivityStatus: models.TenantActivityStatusCOLD,
531
+ })
532
+ }
533
+ for _, tenant := range tenants3Soup {
534
+ tenants = append(tenants, models.Tenant{
535
+ Name: tenant.Name,
536
+ ActivityStatus: models.TenantActivityStatusHOT,
537
+ })
538
+ }
539
+
540
+ err = client.Schema().TenantsUpdater().
541
+ WithClassName(classSoup).
542
+ WithTenants(tenants...).
543
+ Do(ctx)
544
+ require.Nil(t, err)
545
+
546
+ assertActiveTenants(t, tenants1Pizza, classPizza, idsPizza)
547
+ assertInactiveTenants(t, tenants2Pizza, classPizza)
548
+ assertActiveTenants(t, tenants3Pizza, classPizza, idsPizza)
549
+
550
+ assertActiveTenants(t, tenants1Soup, classSoup, idsSoup)
551
+ assertInactiveTenants(t, tenants2Soup, classSoup)
552
+ assertActiveTenants(t, tenants3Soup, classSoup, idsSoup)
553
+ })
554
+
555
+ t.Run("activate tenants (2)", func(t *testing.T) {
556
+ tenants := make(fixtures.Tenants, len(tenants2Pizza))
557
+ for i, tenant := range tenants2Pizza {
558
+ tenants[i] = models.Tenant{
559
+ Name: tenant.Name,
560
+ ActivityStatus: models.TenantActivityStatusHOT,
561
+ }
562
+ }
563
+
564
+ err := client.Schema().TenantsUpdater().
565
+ WithClassName(classPizza).
566
+ WithTenants(tenants...).
567
+ Do(ctx)
568
+ require.Nil(t, err)
569
+
570
+ tenants = make(fixtures.Tenants, len(tenants2Soup))
571
+ for i, tenant := range tenants2Soup {
572
+ tenants[i] = models.Tenant{
573
+ Name: tenant.Name,
574
+ ActivityStatus: models.TenantActivityStatusHOT,
575
+ }
576
+ }
577
+
578
+ err = client.Schema().TenantsUpdater().
579
+ WithClassName(classSoup).
580
+ WithTenants(tenants...).
581
+ Do(ctx)
582
+ require.Nil(t, err)
583
+
584
+ assertActiveTenants(t, tenants1Pizza, classPizza, idsPizza)
585
+ assertActiveTenants(t, tenants2Pizza, classPizza, idsPizza)
586
+ assertActiveTenants(t, tenants3Pizza, classPizza, idsPizza)
587
+
588
+ assertActiveTenants(t, tenants1Soup, classSoup, idsSoup)
589
+ assertActiveTenants(t, tenants2Soup, classSoup, idsSoup)
590
+ assertActiveTenants(t, tenants3Soup, classSoup, idsSoup)
591
+ })
592
+
593
+ t.Run("restart db, nothing changed", func(t *testing.T) {
594
+ client = restart(t, ctx)
595
+
596
+ assertActiveTenants(t, tenants1Pizza, classPizza, idsPizza)
597
+ assertActiveTenants(t, tenants2Pizza, classPizza, idsPizza)
598
+ assertActiveTenants(t, tenants3Pizza, classPizza, idsPizza)
599
+
600
+ assertActiveTenants(t, tenants1Soup, classSoup, idsSoup)
601
+ assertActiveTenants(t, tenants2Soup, classSoup, idsSoup)
602
+ assertActiveTenants(t, tenants3Soup, classSoup, idsSoup)
603
+ })
604
+ })
605
+ }
606
+
607
+ func assertTenantActive(t *testing.T, client *wvt.Client, className, tenantName string) {
608
+ gotTenants, err := client.Schema().TenantsGetter().
609
+ WithClassName(className).
610
+ Do(context.Background())
611
+ require.Nil(t, err)
612
+ require.NotEmpty(t, gotTenants)
613
+
614
+ byName := fixtures.Tenants(gotTenants).ByName(tenantName)
615
+ require.NotNil(t, byName)
616
+ require.Equal(t, models.TenantActivityStatusHOT, byName.ActivityStatus)
617
+ }
618
+
619
+ func assertTenantInactive(t *testing.T, client *wvt.Client, className, tenantName string) {
620
+ gotTenants, err := client.Schema().TenantsGetter().
621
+ WithClassName(className).
622
+ Do(context.Background())
623
+ require.Nil(t, err)
624
+ require.NotEmpty(t, gotTenants)
625
+
626
+ byName := fixtures.Tenants(gotTenants).ByName(tenantName)
627
+ require.NotNil(t, byName)
628
+ require.Equal(t, models.TenantActivityStatusCOLD, byName.ActivityStatus)
629
+ }
630
+
631
+ func assertActiveTenantObjects(t *testing.T, client *wvt.Client, className, tenantName string, expectedIds []string) {
632
+ objects, err := client.Data().ObjectsGetter().
633
+ WithClassName(className).
634
+ WithTenant(tenantName).
635
+ Do(context.Background())
636
+
637
+ require.Nil(t, err)
638
+ require.NotNil(t, objects)
639
+ require.Len(t, objects, len(expectedIds))
640
+
641
+ ids := make([]string, len(objects))
642
+ for i, object := range objects {
643
+ ids[i] = string(object.ID)
644
+ }
645
+ assert.ElementsMatch(t, expectedIds, ids)
646
+ }
647
+
648
+ func assertInactiveTenantObjects(t *testing.T, client *wvt.Client, className, tenantName string) {
649
+ // Data objects in Weaviate are eventually consistent, therefore we have to add some sleep time
650
+ // to make sure that the tenant was deactivate in all nodes
651
+ // see docs: https://github.com/weaviate/weaviate-io/blob/main/developers/weaviate/concepts/replication-architecture/consistency.md#data-objects
652
+ assert.EventuallyWithT(t, func(collect *assert.CollectT) {
653
+ objects, err := client.Data().ObjectsGetter().
654
+ WithClassName(className).
655
+ WithTenant(tenantName).
656
+ Do(context.Background())
657
+
658
+ assert.NotNil(t, err)
659
+ clientErr := err.(*fault.WeaviateClientError)
660
+ assert.Equal(t, 422, clientErr.StatusCode)
661
+ assert.Contains(t, clientErr.Msg, "tenant not active")
662
+ assert.Nil(t, objects)
663
+ }, 5*time.Second, 1*time.Second, "tenant was active, expected to be inactive")
664
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/multi_tenancy_tests/batch_reference_test.go ADDED
@@ -0,0 +1,1589 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package multi_tenancy_tests
13
+
14
+ import (
15
+ "context"
16
+ "testing"
17
+
18
+ "acceptance_tests_with_client/fixtures"
19
+
20
+ "github.com/stretchr/testify/assert"
21
+ "github.com/stretchr/testify/require"
22
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
23
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/filters"
24
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/graphql"
25
+ "github.com/weaviate/weaviate/entities/models"
26
+ )
27
+
28
+ func TestBatchReferenceCreate_MultiTenancy(t *testing.T) {
29
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: "localhost:8080"})
30
+ require.Nil(t, err)
31
+
32
+ cleanup := func() {
33
+ err := client.Schema().AllDeleter().Do(context.Background())
34
+ require.Nil(t, err)
35
+ }
36
+
37
+ testCases := []struct {
38
+ name string
39
+ explicitTargetClass bool
40
+ }{
41
+ {
42
+ name: "explicit target class",
43
+ explicitTargetClass: true,
44
+ },
45
+ {
46
+ name: "auto detected target class",
47
+ explicitTargetClass: false,
48
+ },
49
+ }
50
+
51
+ for _, tc := range testCases {
52
+ t.Run(tc.name, func(t *testing.T) {
53
+ t.Run("creates references between MT classes", func(t *testing.T) {
54
+ defer cleanup()
55
+
56
+ tenants := fixtures.Tenants{
57
+ {Name: "tenantNo1"},
58
+ {Name: "tenantNo2"},
59
+ }
60
+ soupIds := fixtures.IdsByClass["Soup"]
61
+ pizzaIds := fixtures.IdsByClass["Pizza"]
62
+
63
+ fixtures.CreateSchemaSoupForTenants(t, client)
64
+ fixtures.CreateTenantsSoup(t, client, tenants...)
65
+ fixtures.CreateDataSoupForTenants(t, client, tenants.Names()...)
66
+
67
+ fixtures.CreateSchemaPizzaForTenants(t, client)
68
+ fixtures.CreateTenantsPizza(t, client, tenants...)
69
+ fixtures.CreateDataPizzaForTenants(t, client, tenants.Names()...)
70
+
71
+ t.Run("create ref property", func(t *testing.T) {
72
+ err := client.Schema().PropertyCreator().
73
+ WithClassName("Soup").
74
+ WithProperty(&models.Property{
75
+ Name: "relatedToPizza",
76
+ DataType: []string{"Pizza"},
77
+ }).
78
+ Do(context.Background())
79
+
80
+ require.Nil(t, err)
81
+ })
82
+
83
+ references := []*models.BatchReference{}
84
+ for _, tenant := range tenants {
85
+ for _, soupId := range soupIds {
86
+ for _, pizzaId := range pizzaIds {
87
+ rpb := client.Batch().ReferencePayloadBuilder().
88
+ WithFromClassName("Soup").
89
+ WithFromRefProp("relatedToPizza").
90
+ WithFromID(soupId).
91
+ WithToID(pizzaId).
92
+ WithTenant(tenant.Name)
93
+
94
+ if tc.explicitTargetClass {
95
+ rpb.WithToClassName("Pizza")
96
+ }
97
+
98
+ references = append(references, rpb.Payload())
99
+ }
100
+ }
101
+ }
102
+
103
+ resp, err := client.Batch().ReferencesBatcher().
104
+ WithReferences(references...).
105
+ Do(context.Background())
106
+
107
+ require.Nil(t, err)
108
+ require.NotNil(t, resp)
109
+ assert.Len(t, resp, len(references))
110
+ for i := range resp {
111
+ require.NotNil(t, resp[i].Result)
112
+ require.NotNil(t, resp[i].Result.Status)
113
+ assert.Equal(t, "SUCCESS", *resp[i].Result.Status)
114
+ assert.Nil(t, resp[i].Result.Errors)
115
+ }
116
+
117
+ t.Run("verify created", func(t *testing.T) {
118
+ for _, tenant := range tenants {
119
+ for _, soupId := range soupIds {
120
+ objects, err := client.Data().ObjectsGetter().
121
+ WithClassName("Soup").
122
+ WithID(soupId).
123
+ WithTenant(tenant.Name).
124
+ Do(context.Background())
125
+
126
+ require.Nil(t, err)
127
+ require.NotNil(t, objects)
128
+ require.Len(t, objects, 1)
129
+ assert.Len(t, objects[0].Properties.(map[string]interface{})["relatedToPizza"].([]interface{}),
130
+ len(pizzaIds))
131
+ }
132
+ }
133
+ })
134
+
135
+ t.Run("verify graphql search", func(t *testing.T) {
136
+ for _, tenant := range tenants {
137
+ resp, err := client.GraphQL().Get().
138
+ WithClassName("Soup").
139
+ WithTenant(tenant.Name).
140
+ WithFields(graphql.Field{
141
+ Name: "_additional", Fields: []graphql.Field{{Name: "id"}},
142
+ }).
143
+ WithWhere(filters.Where().
144
+ WithPath([]string{"relatedToPizza", "Pizza", "name"}).
145
+ WithOperator(filters.Equal).
146
+ WithValueString("Quattro Formaggi")).
147
+ Do(context.Background())
148
+
149
+ require.NoError(t, err)
150
+ assertGraphqlGetIds(t, resp, "Soup", soupIds)
151
+ }
152
+ })
153
+ })
154
+
155
+ t.Run("fails creating references between MT classes without tenant", func(t *testing.T) {
156
+ defer cleanup()
157
+
158
+ tenants := fixtures.Tenants{
159
+ {Name: "tenantNo1"},
160
+ {Name: "tenantNo2"},
161
+ }
162
+ soupIds := fixtures.IdsByClass["Soup"]
163
+ pizzaIds := fixtures.IdsByClass["Pizza"]
164
+
165
+ fixtures.CreateSchemaSoupForTenants(t, client)
166
+ fixtures.CreateTenantsSoup(t, client, tenants...)
167
+ fixtures.CreateDataSoupForTenants(t, client, tenants.Names()...)
168
+
169
+ fixtures.CreateSchemaPizzaForTenants(t, client)
170
+ fixtures.CreateTenantsPizza(t, client, tenants...)
171
+ fixtures.CreateDataPizzaForTenants(t, client, tenants.Names()...)
172
+
173
+ t.Run("create ref property", func(t *testing.T) {
174
+ err := client.Schema().PropertyCreator().
175
+ WithClassName("Soup").
176
+ WithProperty(&models.Property{
177
+ Name: "relatedToPizza",
178
+ DataType: []string{"Pizza"},
179
+ }).
180
+ Do(context.Background())
181
+
182
+ require.Nil(t, err)
183
+ })
184
+
185
+ references := []*models.BatchReference{}
186
+ for _, soupId := range soupIds {
187
+ for _, pizzaId := range pizzaIds {
188
+ rpb := client.Batch().ReferencePayloadBuilder().
189
+ WithFromClassName("Soup").
190
+ WithFromRefProp("relatedToPizza").
191
+ WithFromID(soupId).
192
+ WithToID(pizzaId)
193
+
194
+ if tc.explicitTargetClass {
195
+ rpb.WithToClassName("Pizza")
196
+ }
197
+
198
+ references = append(references, rpb.Payload())
199
+ }
200
+ }
201
+
202
+ resp, err := client.Batch().ReferencesBatcher().
203
+ WithReferences(references...).
204
+ Do(context.Background())
205
+
206
+ require.Nil(t, err)
207
+ require.NotNil(t, resp)
208
+ assert.Len(t, resp, len(references))
209
+ for i := range resp {
210
+ require.NotNil(t, resp[i].Result)
211
+ require.NotNil(t, resp[i].Result.Status)
212
+ assert.Equal(t, "FAILED", *resp[i].Result.Status)
213
+ require.NotNil(t, resp[i].Result.Errors)
214
+ require.Len(t, resp[i].Result.Errors.Error, 1)
215
+ assert.Contains(t, resp[i].Result.Errors.Error[0].Message, "has multi-tenancy enabled, but request was without tenant")
216
+ }
217
+
218
+ t.Run("verify not created", func(t *testing.T) {
219
+ for _, tenant := range tenants {
220
+ for _, soupId := range soupIds {
221
+ objects, err := client.Data().ObjectsGetter().
222
+ WithClassName("Soup").
223
+ WithID(soupId).
224
+ WithTenant(tenant.Name).
225
+ Do(context.Background())
226
+
227
+ require.Nil(t, err)
228
+ require.NotNil(t, objects)
229
+ require.Len(t, objects, 1)
230
+ assert.Nil(t, objects[0].Properties.(map[string]interface{})["relatedToPizza"])
231
+ }
232
+ }
233
+ })
234
+ })
235
+
236
+ t.Run("fails creating references between MT classes with non existent tenant", func(t *testing.T) {
237
+ defer cleanup()
238
+
239
+ tenants := fixtures.Tenants{
240
+ {Name: "tenantNo1"},
241
+ {Name: "tenantNo2"},
242
+ }
243
+ soupIds := fixtures.IdsByClass["Soup"]
244
+ pizzaIds := fixtures.IdsByClass["Pizza"]
245
+
246
+ fixtures.CreateSchemaSoupForTenants(t, client)
247
+ fixtures.CreateTenantsSoup(t, client, tenants...)
248
+ fixtures.CreateDataSoupForTenants(t, client, tenants.Names()...)
249
+
250
+ fixtures.CreateSchemaPizzaForTenants(t, client)
251
+ fixtures.CreateTenantsPizza(t, client, tenants...)
252
+ fixtures.CreateDataPizzaForTenants(t, client, tenants.Names()...)
253
+
254
+ t.Run("create ref property", func(t *testing.T) {
255
+ err := client.Schema().PropertyCreator().
256
+ WithClassName("Soup").
257
+ WithProperty(&models.Property{
258
+ Name: "relatedToPizza",
259
+ DataType: []string{"Pizza"},
260
+ }).
261
+ Do(context.Background())
262
+
263
+ require.Nil(t, err)
264
+ })
265
+
266
+ references := []*models.BatchReference{}
267
+ for _, soupId := range soupIds {
268
+ for _, pizzaId := range pizzaIds {
269
+ rpb := client.Batch().ReferencePayloadBuilder().
270
+ WithFromClassName("Soup").
271
+ WithFromRefProp("relatedToPizza").
272
+ WithFromID(soupId).
273
+ WithToID(pizzaId).
274
+ WithTenant("nonExistentTenant")
275
+
276
+ if tc.explicitTargetClass {
277
+ rpb.WithToClassName("Pizza")
278
+ }
279
+
280
+ references = append(references, rpb.Payload())
281
+ }
282
+ }
283
+
284
+ resp, err := client.Batch().ReferencesBatcher().
285
+ WithReferences(references...).
286
+ Do(context.Background())
287
+
288
+ require.Nil(t, err)
289
+ require.NotNil(t, resp)
290
+ assert.Len(t, resp, len(references))
291
+ for i := range resp {
292
+ require.NotNil(t, resp[i].Result)
293
+ require.NotNil(t, resp[i].Result.Status)
294
+ assert.Equal(t, "FAILED", *resp[i].Result.Status)
295
+ require.NotNil(t, resp[i].Result.Errors)
296
+ require.Len(t, resp[i].Result.Errors.Error, 1)
297
+ assert.Contains(t, resp[i].Result.Errors.Error[0].Message, "tenant not found")
298
+ }
299
+
300
+ t.Run("verify not created", func(t *testing.T) {
301
+ for _, tenant := range tenants {
302
+ for _, soupId := range soupIds {
303
+ objects, err := client.Data().ObjectsGetter().
304
+ WithClassName("Soup").
305
+ WithID(soupId).
306
+ WithTenant(tenant.Name).
307
+ Do(context.Background())
308
+
309
+ require.Nil(t, err)
310
+ require.NotNil(t, objects)
311
+ require.Len(t, objects, 1)
312
+ assert.Nil(t, objects[0].Properties.(map[string]interface{})["relatedToPizza"])
313
+ }
314
+ }
315
+ })
316
+ })
317
+
318
+ t.Run("fails creating references between MT classes with different existing tenant", func(t *testing.T) {
319
+ defer cleanup()
320
+
321
+ tenants := fixtures.Tenants{
322
+ {Name: "tenantNo1"},
323
+ {Name: "tenantNo2"},
324
+ }
325
+ soupIds := fixtures.IdsByClass["Soup"]
326
+ pizzaIds := fixtures.IdsByClass["Pizza"]
327
+
328
+ fixtures.CreateSchemaSoupForTenants(t, client)
329
+ fixtures.CreateTenantsSoup(t, client, tenants...)
330
+ fixtures.CreateDataSoupForTenants(t, client, tenants[0].Name)
331
+
332
+ fixtures.CreateSchemaPizzaForTenants(t, client)
333
+ fixtures.CreateTenantsPizza(t, client, tenants...)
334
+ fixtures.CreateDataPizzaForTenants(t, client, tenants[0].Name)
335
+
336
+ t.Run("create ref property", func(t *testing.T) {
337
+ err := client.Schema().PropertyCreator().
338
+ WithClassName("Soup").
339
+ WithProperty(&models.Property{
340
+ Name: "relatedToPizza",
341
+ DataType: []string{"Pizza"},
342
+ }).
343
+ Do(context.Background())
344
+
345
+ require.Nil(t, err)
346
+ })
347
+
348
+ references := []*models.BatchReference{}
349
+ for _, soupId := range soupIds {
350
+ for _, pizzaId := range pizzaIds {
351
+ rpb := client.Batch().ReferencePayloadBuilder().
352
+ WithFromClassName("Soup").
353
+ WithFromRefProp("relatedToPizza").
354
+ WithFromID(soupId).
355
+ WithToID(pizzaId).
356
+ WithTenant(tenants[1].Name)
357
+
358
+ if tc.explicitTargetClass {
359
+ rpb.WithToClassName("Pizza")
360
+ }
361
+
362
+ references = append(references, rpb.Payload())
363
+ }
364
+ }
365
+
366
+ resp, err := client.Batch().ReferencesBatcher().
367
+ WithReferences(references...).
368
+ Do(context.Background())
369
+
370
+ require.Nil(t, err)
371
+ require.NotNil(t, resp)
372
+ assert.Len(t, resp, len(references))
373
+ for i := range resp {
374
+ require.NotNil(t, resp[i].Result)
375
+ require.NotNil(t, resp[i].Result.Status)
376
+ assert.Equal(t, "FAILED", *resp[i].Result.Status)
377
+ require.NotNil(t, resp[i].Result.Errors)
378
+ require.Len(t, resp[i].Result.Errors.Error, 1)
379
+ assert.Contains(t, resp[i].Result.Errors.Error[0].Message, "not found for tenant")
380
+ }
381
+
382
+ t.Run("verify not created", func(t *testing.T) {
383
+ for _, soupId := range soupIds {
384
+ objects, err := client.Data().ObjectsGetter().
385
+ WithClassName("Soup").
386
+ WithID(soupId).
387
+ WithTenant(tenants[0].Name).
388
+ Do(context.Background())
389
+
390
+ require.Nil(t, err)
391
+ require.NotNil(t, objects)
392
+ require.Len(t, objects, 1)
393
+ assert.Nil(t, objects[0].Properties.(map[string]interface{})["relatedToPizza"])
394
+ }
395
+ })
396
+
397
+ t.Run("verify new objects not created", func(t *testing.T) {
398
+ for _, soupId := range soupIds {
399
+ exists, err := client.Data().Checker().
400
+ WithClassName("Soup").
401
+ WithID(soupId).
402
+ WithTenant(tenants[1].Name).
403
+ Do(context.Background())
404
+
405
+ require.Nil(t, err)
406
+ assert.False(t, exists)
407
+ }
408
+
409
+ for _, pizzaId := range pizzaIds {
410
+ exists, err := client.Data().Checker().
411
+ WithClassName("Pizza").
412
+ WithID(pizzaId).
413
+ WithTenant(tenants[1].Name).
414
+ Do(context.Background())
415
+
416
+ require.Nil(t, err)
417
+ assert.False(t, exists)
418
+ }
419
+ })
420
+ })
421
+
422
+ t.Run("fails creating references between MT classes and different tenants", func(t *testing.T) {
423
+ tenantPizza := models.Tenant{Name: "tenantPizza"}
424
+ tenantSoup := models.Tenant{Name: "tenantSoup"}
425
+ soupIds := fixtures.IdsByClass["Soup"]
426
+ pizzaIds := fixtures.IdsByClass["Pizza"]
427
+
428
+ t.Run("with SRC tenant (common tenants)", func(t *testing.T) {
429
+ defer cleanup()
430
+
431
+ fixtures.CreateSchemaSoupForTenants(t, client)
432
+ fixtures.CreateTenantsSoup(t, client, tenantPizza, tenantSoup)
433
+ fixtures.CreateDataSoupForTenants(t, client, tenantSoup.Name)
434
+
435
+ fixtures.CreateSchemaPizzaForTenants(t, client)
436
+ fixtures.CreateTenantsPizza(t, client, tenantPizza, tenantSoup)
437
+ fixtures.CreateDataPizzaForTenants(t, client, tenantPizza.Name)
438
+
439
+ t.Run("create ref property", func(t *testing.T) {
440
+ err := client.Schema().PropertyCreator().
441
+ WithClassName("Soup").
442
+ WithProperty(&models.Property{
443
+ Name: "relatedToPizza",
444
+ DataType: []string{"Pizza"},
445
+ }).
446
+ Do(context.Background())
447
+
448
+ require.Nil(t, err)
449
+ })
450
+
451
+ references := []*models.BatchReference{}
452
+ for _, soupId := range soupIds {
453
+ for _, pizzaId := range pizzaIds {
454
+ rpb := client.Batch().ReferencePayloadBuilder().
455
+ WithFromClassName("Soup").
456
+ WithFromRefProp("relatedToPizza").
457
+ WithFromID(soupId).
458
+ WithToID(pizzaId).
459
+ WithTenant(tenantSoup.Name) // SRC tenant
460
+
461
+ if tc.explicitTargetClass {
462
+ rpb.WithToClassName("Pizza")
463
+ }
464
+
465
+ references = append(references, rpb.Payload())
466
+ }
467
+ }
468
+
469
+ resp, err := client.Batch().ReferencesBatcher().
470
+ WithReferences(references...).
471
+ Do(context.Background())
472
+
473
+ require.Nil(t, err)
474
+ require.NotNil(t, resp)
475
+ assert.Len(t, resp, len(references))
476
+ for i := range resp {
477
+ require.NotNil(t, resp[i].Result)
478
+ require.NotNil(t, resp[i].Result.Status)
479
+ assert.Equal(t, "FAILED", *resp[i].Result.Status)
480
+ require.NotNil(t, resp[i].Result.Errors)
481
+ require.Len(t, resp[i].Result.Errors.Error, 1)
482
+ assert.Contains(t, resp[i].Result.Errors.Error[0].Message, "not found for tenant")
483
+ }
484
+
485
+ t.Run("verify not created", func(t *testing.T) {
486
+ for _, soupId := range soupIds {
487
+ objects, err := client.Data().ObjectsGetter().
488
+ WithClassName("Soup").
489
+ WithID(soupId).
490
+ WithTenant(tenantSoup.Name).
491
+ Do(context.Background())
492
+
493
+ require.Nil(t, err)
494
+ require.NotNil(t, objects)
495
+ require.Len(t, objects, 1)
496
+ assert.Nil(t, objects[0].Properties.(map[string]interface{})["relatedToPizza"])
497
+ }
498
+ })
499
+
500
+ t.Run("verify new objects not created", func(t *testing.T) {
501
+ for _, soupId := range soupIds {
502
+ exists, err := client.Data().Checker().
503
+ WithClassName("Soup").
504
+ WithID(soupId).
505
+ WithTenant(tenantPizza.Name).
506
+ Do(context.Background())
507
+
508
+ require.Nil(t, err)
509
+ assert.False(t, exists)
510
+ }
511
+
512
+ for _, pizzaId := range pizzaIds {
513
+ exists, err := client.Data().Checker().
514
+ WithClassName("Pizza").
515
+ WithID(pizzaId).
516
+ WithTenant(tenantSoup.Name).
517
+ Do(context.Background())
518
+
519
+ require.Nil(t, err)
520
+ assert.False(t, exists)
521
+ }
522
+ })
523
+ })
524
+
525
+ t.Run("with SRC tenant (separate tenants)", func(t *testing.T) {
526
+ defer cleanup()
527
+
528
+ fixtures.CreateSchemaSoupForTenants(t, client)
529
+ fixtures.CreateTenantsSoup(t, client, tenantSoup)
530
+ fixtures.CreateDataSoupForTenants(t, client, tenantSoup.Name)
531
+
532
+ fixtures.CreateSchemaPizzaForTenants(t, client)
533
+ fixtures.CreateTenantsPizza(t, client, tenantPizza)
534
+ fixtures.CreateDataPizzaForTenants(t, client, tenantPizza.Name)
535
+
536
+ t.Run("create ref property", func(t *testing.T) {
537
+ err := client.Schema().PropertyCreator().
538
+ WithClassName("Soup").
539
+ WithProperty(&models.Property{
540
+ Name: "relatedToPizza",
541
+ DataType: []string{"Pizza"},
542
+ }).
543
+ Do(context.Background())
544
+
545
+ require.Nil(t, err)
546
+ })
547
+
548
+ references := []*models.BatchReference{}
549
+ for _, soupId := range soupIds {
550
+ for _, pizzaId := range pizzaIds {
551
+ rpb := client.Batch().ReferencePayloadBuilder().
552
+ WithFromClassName("Soup").
553
+ WithFromRefProp("relatedToPizza").
554
+ WithFromID(soupId).
555
+ WithToID(pizzaId).
556
+ WithTenant(tenantSoup.Name) // SRC tenant
557
+
558
+ if tc.explicitTargetClass {
559
+ rpb.WithToClassName("Pizza")
560
+ }
561
+
562
+ references = append(references, rpb.Payload())
563
+ }
564
+ }
565
+
566
+ resp, err := client.Batch().ReferencesBatcher().
567
+ WithReferences(references...).
568
+ Do(context.Background())
569
+
570
+ require.Nil(t, err)
571
+ require.NotNil(t, resp)
572
+ assert.Len(t, resp, len(references))
573
+ for i := range resp {
574
+ require.NotNil(t, resp[i].Result)
575
+ require.NotNil(t, resp[i].Result.Status)
576
+ assert.Equal(t, "FAILED", *resp[i].Result.Status)
577
+ require.NotNil(t, resp[i].Result.Errors)
578
+ require.Len(t, resp[i].Result.Errors.Error, 1)
579
+ assert.Contains(t, resp[i].Result.Errors.Error[0].Message, "tenant not found")
580
+ }
581
+
582
+ t.Run("verify not created", func(t *testing.T) {
583
+ for _, soupId := range soupIds {
584
+ objects, err := client.Data().ObjectsGetter().
585
+ WithClassName("Soup").
586
+ WithID(soupId).
587
+ WithTenant(tenantSoup.Name).
588
+ Do(context.Background())
589
+
590
+ require.Nil(t, err)
591
+ require.NotNil(t, objects)
592
+ require.Len(t, objects, 1)
593
+ assert.Nil(t, objects[0].Properties.(map[string]interface{})["relatedToPizza"])
594
+ }
595
+ })
596
+
597
+ t.Run("verify new objects not created", func(t *testing.T) {
598
+ for _, soupId := range soupIds {
599
+ exists, err := client.Data().Checker().
600
+ WithClassName("Soup").
601
+ WithID(soupId).
602
+ WithTenant(tenantPizza.Name).
603
+ Do(context.Background())
604
+
605
+ require.NotNil(t, err)
606
+ assert.False(t, exists)
607
+ }
608
+
609
+ for _, pizzaId := range pizzaIds {
610
+ exists, err := client.Data().Checker().
611
+ WithClassName("Pizza").
612
+ WithID(pizzaId).
613
+ WithTenant(tenantSoup.Name).
614
+ Do(context.Background())
615
+
616
+ require.NotNil(t, err)
617
+ assert.False(t, exists)
618
+ }
619
+ })
620
+ })
621
+
622
+ t.Run("with DEST tenant (common tenants)", func(t *testing.T) {
623
+ defer cleanup()
624
+
625
+ fixtures.CreateSchemaSoupForTenants(t, client)
626
+ fixtures.CreateTenantsSoup(t, client, tenantPizza, tenantSoup)
627
+ fixtures.CreateDataSoupForTenants(t, client, tenantSoup.Name)
628
+
629
+ fixtures.CreateSchemaPizzaForTenants(t, client)
630
+ fixtures.CreateTenantsPizza(t, client, tenantPizza, tenantSoup)
631
+ fixtures.CreateDataPizzaForTenants(t, client, tenantPizza.Name)
632
+
633
+ t.Run("create ref property", func(t *testing.T) {
634
+ err := client.Schema().PropertyCreator().
635
+ WithClassName("Soup").
636
+ WithProperty(&models.Property{
637
+ Name: "relatedToPizza",
638
+ DataType: []string{"Pizza"},
639
+ }).
640
+ Do(context.Background())
641
+
642
+ require.Nil(t, err)
643
+ })
644
+
645
+ references := []*models.BatchReference{}
646
+ for _, soupId := range soupIds {
647
+ for _, pizzaId := range pizzaIds {
648
+ rpb := client.Batch().ReferencePayloadBuilder().
649
+ WithFromClassName("Soup").
650
+ WithFromRefProp("relatedToPizza").
651
+ WithFromID(soupId).
652
+ WithToID(pizzaId).
653
+ WithTenant(tenantPizza.Name) // DEST tenant
654
+
655
+ if tc.explicitTargetClass {
656
+ rpb.WithToClassName("Pizza")
657
+ }
658
+
659
+ references = append(references, rpb.Payload())
660
+ }
661
+ }
662
+
663
+ resp, err := client.Batch().ReferencesBatcher().
664
+ WithReferences(references...).
665
+ Do(context.Background())
666
+
667
+ require.Nil(t, err)
668
+ require.NotNil(t, resp)
669
+ assert.Len(t, resp, len(references))
670
+ for i := range resp {
671
+ require.NotNil(t, resp[i].Result)
672
+ require.NotNil(t, resp[i].Result.Status)
673
+ assert.Equal(t, "FAILED", *resp[i].Result.Status)
674
+ require.NotNil(t, resp[i].Result.Errors)
675
+ require.Len(t, resp[i].Result.Errors.Error, 1)
676
+ assert.Contains(t, resp[i].Result.Errors.Error[0].Message, "not found for tenant")
677
+ }
678
+
679
+ t.Run("verify not created", func(t *testing.T) {
680
+ for _, soupId := range soupIds {
681
+ objects, err := client.Data().ObjectsGetter().
682
+ WithClassName("Soup").
683
+ WithID(soupId).
684
+ WithTenant(tenantSoup.Name).
685
+ Do(context.Background())
686
+
687
+ require.Nil(t, err)
688
+ require.NotNil(t, objects)
689
+ require.Len(t, objects, 1)
690
+ assert.Nil(t, objects[0].Properties.(map[string]interface{})["relatedToPizza"])
691
+ }
692
+ })
693
+
694
+ t.Run("verify new objects not created", func(t *testing.T) {
695
+ for _, soupId := range soupIds {
696
+ exists, err := client.Data().Checker().
697
+ WithClassName("Soup").
698
+ WithID(soupId).
699
+ WithTenant(tenantPizza.Name).
700
+ Do(context.Background())
701
+
702
+ require.Nil(t, err)
703
+ assert.False(t, exists)
704
+ }
705
+
706
+ for _, pizzaId := range pizzaIds {
707
+ exists, err := client.Data().Checker().
708
+ WithClassName("Pizza").
709
+ WithID(pizzaId).
710
+ WithTenant(tenantSoup.Name).
711
+ Do(context.Background())
712
+
713
+ require.Nil(t, err)
714
+ assert.False(t, exists)
715
+ }
716
+ })
717
+ })
718
+
719
+ t.Run("with DEST tenant (separate tenants)", func(t *testing.T) {
720
+ defer cleanup()
721
+
722
+ fixtures.CreateSchemaSoupForTenants(t, client)
723
+ fixtures.CreateTenantsSoup(t, client, tenantSoup)
724
+ fixtures.CreateDataSoupForTenants(t, client, tenantSoup.Name)
725
+
726
+ fixtures.CreateSchemaPizzaForTenants(t, client)
727
+ fixtures.CreateTenantsPizza(t, client, tenantPizza)
728
+ fixtures.CreateDataPizzaForTenants(t, client, tenantPizza.Name)
729
+
730
+ t.Run("create ref property", func(t *testing.T) {
731
+ err := client.Schema().PropertyCreator().
732
+ WithClassName("Soup").
733
+ WithProperty(&models.Property{
734
+ Name: "relatedToPizza",
735
+ DataType: []string{"Pizza"},
736
+ }).
737
+ Do(context.Background())
738
+
739
+ require.Nil(t, err)
740
+ })
741
+
742
+ references := []*models.BatchReference{}
743
+ for _, soupId := range soupIds {
744
+ for _, pizzaId := range pizzaIds {
745
+ rpb := client.Batch().ReferencePayloadBuilder().
746
+ WithFromClassName("Soup").
747
+ WithFromRefProp("relatedToPizza").
748
+ WithFromID(soupId).
749
+ WithToID(pizzaId).
750
+ WithTenant(tenantPizza.Name) // DEST tenant
751
+
752
+ if tc.explicitTargetClass {
753
+ rpb.WithToClassName("Pizza")
754
+ }
755
+
756
+ references = append(references, rpb.Payload())
757
+ }
758
+ }
759
+
760
+ resp, err := client.Batch().ReferencesBatcher().
761
+ WithReferences(references...).
762
+ Do(context.Background())
763
+
764
+ require.Nil(t, err)
765
+ require.NotNil(t, resp)
766
+ assert.Len(t, resp, len(references))
767
+ for i := range resp {
768
+ require.NotNil(t, resp[i].Result)
769
+ require.NotNil(t, resp[i].Result.Status)
770
+ assert.Equal(t, "FAILED", *resp[i].Result.Status)
771
+ require.NotNil(t, resp[i].Result.Errors)
772
+ require.Len(t, resp[i].Result.Errors.Error, 1)
773
+ assert.Contains(t, resp[i].Result.Errors.Error[0].Message, "tenant not found")
774
+ }
775
+
776
+ t.Run("verify not created", func(t *testing.T) {
777
+ for _, soupId := range soupIds {
778
+ objects, err := client.Data().ObjectsGetter().
779
+ WithClassName("Soup").
780
+ WithID(soupId).
781
+ WithTenant(tenantSoup.Name).
782
+ Do(context.Background())
783
+
784
+ require.Nil(t, err)
785
+ require.NotNil(t, objects)
786
+ require.Len(t, objects, 1)
787
+ assert.Nil(t, objects[0].Properties.(map[string]interface{})["relatedToPizza"])
788
+ }
789
+ })
790
+
791
+ t.Run("verify new objects not created", func(t *testing.T) {
792
+ for _, soupId := range soupIds {
793
+ exists, err := client.Data().Checker().
794
+ WithClassName("Soup").
795
+ WithID(soupId).
796
+ WithTenant(tenantPizza.Name).
797
+ Do(context.Background())
798
+
799
+ require.NotNil(t, err)
800
+ assert.False(t, exists)
801
+ }
802
+
803
+ for _, pizzaId := range pizzaIds {
804
+ exists, err := client.Data().Checker().
805
+ WithClassName("Pizza").
806
+ WithID(pizzaId).
807
+ WithTenant(tenantSoup.Name).
808
+ Do(context.Background())
809
+
810
+ require.NotNil(t, err)
811
+ assert.False(t, exists)
812
+ }
813
+ })
814
+ })
815
+ })
816
+
817
+ t.Run("creates references between MT and non-MT classes", func(t *testing.T) {
818
+ defer cleanup()
819
+
820
+ tenantSoup := models.Tenant{Name: "tenantSoup"}
821
+ pizzaIds := fixtures.IdsByClass["Pizza"]
822
+ soupIds := fixtures.IdsByClass["Soup"]
823
+
824
+ fixtures.CreateSchemaSoupForTenants(t, client)
825
+ fixtures.CreateTenantsSoup(t, client, tenantSoup)
826
+ fixtures.CreateDataSoupForTenants(t, client, tenantSoup.Name)
827
+
828
+ fixtures.CreateSchemaPizza(t, client)
829
+ fixtures.CreateDataPizza(t, client)
830
+
831
+ t.Run("create ref property", func(t *testing.T) {
832
+ err := client.Schema().PropertyCreator().
833
+ WithClassName("Soup").
834
+ WithProperty(&models.Property{
835
+ Name: "relatedToPizza",
836
+ DataType: []string{"Pizza"},
837
+ }).
838
+ Do(context.Background())
839
+
840
+ require.Nil(t, err)
841
+ })
842
+
843
+ references := []*models.BatchReference{}
844
+ for _, soupId := range soupIds {
845
+ for _, pizzaId := range pizzaIds {
846
+ rpb := client.Batch().ReferencePayloadBuilder().
847
+ WithFromClassName("Soup").
848
+ WithFromRefProp("relatedToPizza").
849
+ WithFromID(soupId).
850
+ WithToID(pizzaId).
851
+ WithTenant(tenantSoup.Name)
852
+
853
+ if tc.explicitTargetClass {
854
+ rpb.WithToClassName("Pizza")
855
+ }
856
+
857
+ references = append(references, rpb.Payload())
858
+ }
859
+ }
860
+
861
+ resp, err := client.Batch().ReferencesBatcher().
862
+ WithReferences(references...).
863
+ Do(context.Background())
864
+
865
+ require.Nil(t, err)
866
+ require.NotNil(t, resp)
867
+ assert.Len(t, resp, len(references))
868
+ for i := range resp {
869
+ require.NotNil(t, resp[i].Result)
870
+ require.NotNil(t, resp[i].Result.Status)
871
+ assert.Equal(t, "SUCCESS", *resp[i].Result.Status)
872
+ assert.Nil(t, resp[i].Result.Errors)
873
+ }
874
+
875
+ t.Run("verify created", func(t *testing.T) {
876
+ for _, soupId := range soupIds {
877
+ objects, err := client.Data().ObjectsGetter().
878
+ WithClassName("Soup").
879
+ WithID(soupId).
880
+ WithTenant(tenantSoup.Name).
881
+ Do(context.Background())
882
+
883
+ require.Nil(t, err)
884
+ require.NotNil(t, objects)
885
+ require.Len(t, objects, 1)
886
+ assert.Len(t, objects[0].Properties.(map[string]interface{})["relatedToPizza"].([]interface{}),
887
+ len(pizzaIds))
888
+ }
889
+ })
890
+
891
+ t.Run("verify graphql search", func(t *testing.T) {
892
+ resp, err := client.GraphQL().Get().
893
+ WithClassName("Soup").
894
+ WithTenant(tenantSoup.Name).
895
+ WithFields(graphql.Field{
896
+ Name: "_additional", Fields: []graphql.Field{{Name: "id"}},
897
+ }).
898
+ WithWhere(filters.Where().
899
+ WithPath([]string{"relatedToPizza", "Pizza", "name"}).
900
+ WithOperator(filters.Equal).
901
+ WithValueString("Quattro Formaggi")).
902
+ Do(context.Background())
903
+
904
+ require.NoError(t, err)
905
+ assertGraphqlGetIds(t, resp, "Soup", soupIds)
906
+ })
907
+ })
908
+
909
+ t.Run("fails creating references between MT and non-MT classes without tenant", func(t *testing.T) {
910
+ defer cleanup()
911
+
912
+ tenantSoup := models.Tenant{Name: "tenantSoup"}
913
+ pizzaIds := fixtures.IdsByClass["Pizza"]
914
+ soupIds := fixtures.IdsByClass["Soup"]
915
+
916
+ fixtures.CreateSchemaSoupForTenants(t, client)
917
+ fixtures.CreateTenantsSoup(t, client, tenantSoup)
918
+ fixtures.CreateDataSoupForTenants(t, client, tenantSoup.Name)
919
+
920
+ fixtures.CreateSchemaPizza(t, client)
921
+ fixtures.CreateDataPizza(t, client)
922
+
923
+ t.Run("create ref property", func(t *testing.T) {
924
+ err := client.Schema().PropertyCreator().
925
+ WithClassName("Soup").
926
+ WithProperty(&models.Property{
927
+ Name: "relatedToPizza",
928
+ DataType: []string{"Pizza"},
929
+ }).
930
+ Do(context.Background())
931
+
932
+ require.Nil(t, err)
933
+ })
934
+
935
+ references := []*models.BatchReference{}
936
+ for _, soupId := range soupIds {
937
+ for _, pizzaId := range pizzaIds {
938
+ rpb := client.Batch().ReferencePayloadBuilder().
939
+ WithFromClassName("Soup").
940
+ WithFromRefProp("relatedToPizza").
941
+ WithFromID(soupId).
942
+ WithToID(pizzaId)
943
+
944
+ if tc.explicitTargetClass {
945
+ rpb.WithToClassName("Pizza")
946
+ }
947
+
948
+ references = append(references, rpb.Payload())
949
+ }
950
+ }
951
+
952
+ resp, err := client.Batch().ReferencesBatcher().
953
+ WithReferences(references...).
954
+ Do(context.Background())
955
+
956
+ require.Nil(t, err)
957
+ require.NotNil(t, resp)
958
+ assert.Len(t, resp, len(references))
959
+ for i := range resp {
960
+ require.NotNil(t, resp[i].Result)
961
+ require.NotNil(t, resp[i].Result.Status)
962
+ assert.Equal(t, "FAILED", *resp[i].Result.Status)
963
+ require.NotNil(t, resp[i].Result.Errors)
964
+ require.Len(t, resp[i].Result.Errors.Error, 1)
965
+ assert.Contains(t, resp[i].Result.Errors.Error[0].Message, "has multi-tenancy enabled, but request was without tenant")
966
+ }
967
+
968
+ t.Run("verify not created", func(t *testing.T) {
969
+ for _, soupId := range soupIds {
970
+ objects, err := client.Data().ObjectsGetter().
971
+ WithClassName("Soup").
972
+ WithID(soupId).
973
+ WithTenant(tenantSoup.Name).
974
+ Do(context.Background())
975
+
976
+ require.Nil(t, err)
977
+ require.NotNil(t, objects)
978
+ require.Len(t, objects, 1)
979
+ assert.Nil(t, objects[0].Properties.(map[string]interface{})["relatedToPizza"])
980
+ }
981
+ })
982
+
983
+ t.Run("verify new objects not created", func(t *testing.T) {
984
+ for _, soupId := range soupIds {
985
+ exists, err := client.Data().Checker().
986
+ WithClassName("Soup").
987
+ WithID(soupId).
988
+ Do(context.Background())
989
+
990
+ require.NotNil(t, err)
991
+ assert.False(t, exists)
992
+ }
993
+
994
+ for _, pizzaId := range pizzaIds {
995
+ exists, err := client.Data().Checker().
996
+ WithClassName("Pizza").
997
+ WithID(pizzaId).
998
+ WithTenant(tenantSoup.Name).
999
+ Do(context.Background())
1000
+
1001
+ require.NotNil(t, err)
1002
+ assert.False(t, exists)
1003
+ }
1004
+ })
1005
+ })
1006
+
1007
+ t.Run("fails creating references between MT and non-MT classes with non existent tenant", func(t *testing.T) {
1008
+ defer cleanup()
1009
+
1010
+ tenantSoup := models.Tenant{Name: "tenantSoup"}
1011
+ pizzaIds := fixtures.IdsByClass["Pizza"]
1012
+ soupIds := fixtures.IdsByClass["Soup"]
1013
+
1014
+ fixtures.CreateSchemaSoupForTenants(t, client)
1015
+ fixtures.CreateTenantsSoup(t, client, tenantSoup)
1016
+ fixtures.CreateDataSoupForTenants(t, client, tenantSoup.Name)
1017
+
1018
+ fixtures.CreateSchemaPizza(t, client)
1019
+ fixtures.CreateDataPizza(t, client)
1020
+
1021
+ t.Run("create ref property", func(t *testing.T) {
1022
+ err := client.Schema().PropertyCreator().
1023
+ WithClassName("Soup").
1024
+ WithProperty(&models.Property{
1025
+ Name: "relatedToPizza",
1026
+ DataType: []string{"Pizza"},
1027
+ }).
1028
+ Do(context.Background())
1029
+
1030
+ require.Nil(t, err)
1031
+ })
1032
+
1033
+ references := []*models.BatchReference{}
1034
+ for _, soupId := range soupIds {
1035
+ for _, pizzaId := range pizzaIds {
1036
+ rpb := client.Batch().ReferencePayloadBuilder().
1037
+ WithFromClassName("Soup").
1038
+ WithFromRefProp("relatedToPizza").
1039
+ WithFromID(soupId).
1040
+ WithToID(pizzaId).
1041
+ WithTenant("nonExistentTenant")
1042
+
1043
+ if tc.explicitTargetClass {
1044
+ rpb.WithToClassName("Pizza")
1045
+ }
1046
+
1047
+ references = append(references, rpb.Payload())
1048
+ }
1049
+ }
1050
+
1051
+ resp, err := client.Batch().ReferencesBatcher().
1052
+ WithReferences(references...).
1053
+ Do(context.Background())
1054
+
1055
+ require.Nil(t, err)
1056
+ require.NotNil(t, resp)
1057
+ assert.Len(t, resp, len(references))
1058
+ for i := range resp {
1059
+ require.NotNil(t, resp[i].Result)
1060
+ require.NotNil(t, resp[i].Result.Status)
1061
+ assert.Equal(t, "FAILED", *resp[i].Result.Status)
1062
+ require.NotNil(t, resp[i].Result.Errors)
1063
+ require.Len(t, resp[i].Result.Errors.Error, 1)
1064
+ assert.Contains(t, resp[i].Result.Errors.Error[0].Message, "tenant not found")
1065
+ }
1066
+
1067
+ t.Run("verify not created", func(t *testing.T) {
1068
+ for _, soupId := range soupIds {
1069
+ objects, err := client.Data().ObjectsGetter().
1070
+ WithClassName("Soup").
1071
+ WithID(soupId).
1072
+ WithTenant(tenantSoup.Name).
1073
+ Do(context.Background())
1074
+
1075
+ require.Nil(t, err)
1076
+ require.NotNil(t, objects)
1077
+ require.Len(t, objects, 1)
1078
+ assert.Nil(t, objects[0].Properties.(map[string]interface{})["relatedToPizza"])
1079
+ }
1080
+ })
1081
+
1082
+ t.Run("verify new objects not created", func(t *testing.T) {
1083
+ for _, soupId := range soupIds {
1084
+ exists, err := client.Data().Checker().
1085
+ WithClassName("Soup").
1086
+ WithID(soupId).
1087
+ Do(context.Background())
1088
+
1089
+ require.NotNil(t, err)
1090
+ assert.False(t, exists)
1091
+ }
1092
+
1093
+ for _, pizzaId := range pizzaIds {
1094
+ exists, err := client.Data().Checker().
1095
+ WithClassName("Pizza").
1096
+ WithID(pizzaId).
1097
+ WithTenant(tenantSoup.Name).
1098
+ Do(context.Background())
1099
+
1100
+ require.NotNil(t, err)
1101
+ assert.False(t, exists)
1102
+ }
1103
+ })
1104
+ })
1105
+
1106
+ t.Run("fails creating references between MT and non-MT classes with different existing tenant", func(t *testing.T) {
1107
+ defer cleanup()
1108
+
1109
+ tenants := fixtures.Tenants{
1110
+ {Name: "tenantNo1"},
1111
+ {Name: "tenantNo2"},
1112
+ }
1113
+ pizzaIds := fixtures.IdsByClass["Pizza"]
1114
+ soupIds := fixtures.IdsByClass["Soup"]
1115
+
1116
+ fixtures.CreateSchemaSoupForTenants(t, client)
1117
+ fixtures.CreateTenantsSoup(t, client, tenants...)
1118
+ fixtures.CreateDataSoupForTenants(t, client, tenants[0].Name)
1119
+
1120
+ fixtures.CreateSchemaPizza(t, client)
1121
+ fixtures.CreateDataPizza(t, client)
1122
+
1123
+ t.Run("create ref property", func(t *testing.T) {
1124
+ err := client.Schema().PropertyCreator().
1125
+ WithClassName("Soup").
1126
+ WithProperty(&models.Property{
1127
+ Name: "relatedToPizza",
1128
+ DataType: []string{"Pizza"},
1129
+ }).
1130
+ Do(context.Background())
1131
+
1132
+ require.Nil(t, err)
1133
+ })
1134
+
1135
+ references := []*models.BatchReference{}
1136
+ for _, soupId := range soupIds {
1137
+ for _, pizzaId := range pizzaIds {
1138
+ rpb := client.Batch().ReferencePayloadBuilder().
1139
+ WithFromClassName("Soup").
1140
+ WithFromRefProp("relatedToPizza").
1141
+ WithFromID(soupId).
1142
+ WithToID(pizzaId).
1143
+ WithTenant(tenants[1].Name)
1144
+
1145
+ if tc.explicitTargetClass {
1146
+ rpb.WithToClassName("Pizza")
1147
+ }
1148
+
1149
+ references = append(references, rpb.Payload())
1150
+ }
1151
+ }
1152
+
1153
+ resp, err := client.Batch().ReferencesBatcher().
1154
+ WithReferences(references...).
1155
+ Do(context.Background())
1156
+
1157
+ require.Nil(t, err)
1158
+ require.NotNil(t, resp)
1159
+ assert.Len(t, resp, len(references))
1160
+ for i := range resp {
1161
+ require.NotNil(t, resp[i].Result)
1162
+ require.NotNil(t, resp[i].Result.Status)
1163
+ assert.Equal(t, "FAILED", *resp[i].Result.Status)
1164
+ require.NotNil(t, resp[i].Result.Errors)
1165
+ require.Len(t, resp[i].Result.Errors.Error, 1)
1166
+ assert.Contains(t, resp[i].Result.Errors.Error[0].Message, "not found for tenant")
1167
+ }
1168
+
1169
+ t.Run("verify not created", func(t *testing.T) {
1170
+ for _, soupId := range soupIds {
1171
+ objects, err := client.Data().ObjectsGetter().
1172
+ WithClassName("Soup").
1173
+ WithID(soupId).
1174
+ WithTenant(tenants[0].Name).
1175
+ Do(context.Background())
1176
+
1177
+ require.Nil(t, err)
1178
+ require.NotNil(t, objects)
1179
+ require.Len(t, objects, 1)
1180
+ assert.Nil(t, objects[0].Properties.(map[string]interface{})["relatedToPizza"])
1181
+ }
1182
+ })
1183
+
1184
+ t.Run("verify new objects not created", func(t *testing.T) {
1185
+ for _, soupId := range soupIds {
1186
+ exists, err := client.Data().Checker().
1187
+ WithClassName("Soup").
1188
+ WithID(soupId).
1189
+ Do(context.Background())
1190
+
1191
+ require.NotNil(t, err)
1192
+ assert.False(t, exists)
1193
+ }
1194
+
1195
+ for _, soupId := range soupIds {
1196
+ exists, err := client.Data().Checker().
1197
+ WithClassName("Soup").
1198
+ WithID(soupId).
1199
+ WithTenant(tenants[1].Name).
1200
+ Do(context.Background())
1201
+
1202
+ require.Nil(t, err)
1203
+ assert.False(t, exists)
1204
+ }
1205
+
1206
+ for _, tenant := range tenants {
1207
+ for _, pizzaId := range pizzaIds {
1208
+ exists, err := client.Data().Checker().
1209
+ WithClassName("Pizza").
1210
+ WithID(pizzaId).
1211
+ WithTenant(tenant.Name).
1212
+ Do(context.Background())
1213
+
1214
+ require.NotNil(t, err)
1215
+ assert.False(t, exists)
1216
+ }
1217
+ }
1218
+ })
1219
+ })
1220
+
1221
+ t.Run("fails creating references between non-MT and MT classes", func(t *testing.T) {
1222
+ defer cleanup()
1223
+
1224
+ tenantPizza := models.Tenant{Name: "tenantPizza"}
1225
+ pizzaIds := fixtures.IdsByClass["Pizza"]
1226
+ soupIds := fixtures.IdsByClass["Soup"]
1227
+
1228
+ fixtures.CreateSchemaSoup(t, client)
1229
+ fixtures.CreateDataSoup(t, client)
1230
+
1231
+ fixtures.CreateSchemaPizzaForTenants(t, client)
1232
+ fixtures.CreateTenantsPizza(t, client, tenantPizza)
1233
+ fixtures.CreateDataPizzaForTenants(t, client, tenantPizza.Name)
1234
+
1235
+ t.Run("create ref property", func(t *testing.T) {
1236
+ err := client.Schema().PropertyCreator().
1237
+ WithClassName("Soup").
1238
+ WithProperty(&models.Property{
1239
+ Name: "relatedToPizza",
1240
+ DataType: []string{"Pizza"},
1241
+ }).
1242
+ Do(context.Background())
1243
+
1244
+ require.Nil(t, err)
1245
+ })
1246
+
1247
+ references := []*models.BatchReference{}
1248
+ for _, soupId := range soupIds {
1249
+ for _, pizzaId := range pizzaIds {
1250
+ rpb := client.Batch().ReferencePayloadBuilder().
1251
+ WithFromClassName("Soup").
1252
+ WithFromRefProp("relatedToPizza").
1253
+ WithFromID(soupId).
1254
+ WithToID(pizzaId).
1255
+ WithTenant(tenantPizza.Name)
1256
+
1257
+ if tc.explicitTargetClass {
1258
+ rpb.WithToClassName("Pizza")
1259
+ }
1260
+
1261
+ references = append(references, rpb.Payload())
1262
+ }
1263
+ }
1264
+
1265
+ resp, err := client.Batch().ReferencesBatcher().
1266
+ WithReferences(references...).
1267
+ Do(context.Background())
1268
+
1269
+ require.Nil(t, err)
1270
+ require.NotNil(t, resp)
1271
+ assert.Len(t, resp, len(references))
1272
+ for i := range resp {
1273
+ require.NotNil(t, resp[i].Result)
1274
+ require.NotNil(t, resp[i].Result.Status)
1275
+ assert.Equal(t, "FAILED", *resp[i].Result.Status)
1276
+ require.NotNil(t, resp[i].Result.Errors)
1277
+ require.Len(t, resp[i].Result.Errors.Error, 1)
1278
+ assert.Contains(t, resp[i].Result.Errors.Error[0].Message, "cannot reference a multi-tenant enabled class from a non multi-tenant enabled class")
1279
+ }
1280
+
1281
+ t.Run("verify not created", func(t *testing.T) {
1282
+ for _, soupId := range soupIds {
1283
+ objects, err := client.Data().ObjectsGetter().
1284
+ WithClassName("Soup").
1285
+ WithID(soupId).
1286
+ Do(context.Background())
1287
+
1288
+ require.Nil(t, err)
1289
+ require.NotNil(t, objects)
1290
+ require.Len(t, objects, 1)
1291
+ assert.Nil(t, objects[0].Properties.(map[string]interface{})["relatedToPizza"])
1292
+ }
1293
+ })
1294
+
1295
+ t.Run("verify new objects not created", func(t *testing.T) {
1296
+ for _, soupId := range soupIds {
1297
+ exists, err := client.Data().Checker().
1298
+ WithClassName("Soup").
1299
+ WithID(soupId).
1300
+ WithTenant(tenantPizza.Name).
1301
+ Do(context.Background())
1302
+
1303
+ require.NotNil(t, err)
1304
+ assert.False(t, exists)
1305
+ }
1306
+ })
1307
+ })
1308
+
1309
+ t.Run("fails creating references between non-MT and MT classes without tenant", func(t *testing.T) {
1310
+ defer cleanup()
1311
+
1312
+ tenantPizza := models.Tenant{Name: "tenantPizza"}
1313
+ pizzaIds := fixtures.IdsByClass["Pizza"]
1314
+ soupIds := fixtures.IdsByClass["Soup"]
1315
+
1316
+ fixtures.CreateSchemaSoup(t, client)
1317
+ fixtures.CreateDataSoup(t, client)
1318
+
1319
+ fixtures.CreateSchemaPizzaForTenants(t, client)
1320
+ fixtures.CreateTenantsPizza(t, client, tenantPizza)
1321
+ fixtures.CreateDataPizzaForTenants(t, client, tenantPizza.Name)
1322
+
1323
+ t.Run("create ref property", func(t *testing.T) {
1324
+ err := client.Schema().PropertyCreator().
1325
+ WithClassName("Soup").
1326
+ WithProperty(&models.Property{
1327
+ Name: "relatedToPizza",
1328
+ DataType: []string{"Pizza"},
1329
+ }).
1330
+ Do(context.Background())
1331
+
1332
+ require.Nil(t, err)
1333
+ })
1334
+
1335
+ references := []*models.BatchReference{}
1336
+ for _, soupId := range soupIds {
1337
+ for _, pizzaId := range pizzaIds {
1338
+ rpb := client.Batch().ReferencePayloadBuilder().
1339
+ WithFromClassName("Soup").
1340
+ WithFromRefProp("relatedToPizza").
1341
+ WithFromID(soupId).
1342
+ WithToID(pizzaId)
1343
+
1344
+ if tc.explicitTargetClass {
1345
+ rpb.WithToClassName("Pizza")
1346
+ }
1347
+
1348
+ references = append(references, rpb.Payload())
1349
+ }
1350
+ }
1351
+
1352
+ resp, err := client.Batch().ReferencesBatcher().
1353
+ WithReferences(references...).
1354
+ Do(context.Background())
1355
+
1356
+ require.Nil(t, err)
1357
+ require.NotNil(t, resp)
1358
+ assert.Len(t, resp, len(references))
1359
+ for i := range resp {
1360
+ require.NotNil(t, resp[i].Result)
1361
+ require.NotNil(t, resp[i].Result.Status)
1362
+ assert.Equal(t, "FAILED", *resp[i].Result.Status)
1363
+ require.NotNil(t, resp[i].Result.Errors)
1364
+ require.Len(t, resp[i].Result.Errors.Error, 1)
1365
+ assert.Contains(t, resp[i].Result.Errors.Error[0].Message, "cannot reference a multi-tenant enabled class from a non multi-tenant enabled class")
1366
+ }
1367
+
1368
+ t.Run("verify not created", func(t *testing.T) {
1369
+ for _, soupId := range soupIds {
1370
+ objects, err := client.Data().ObjectsGetter().
1371
+ WithClassName("Soup").
1372
+ WithID(soupId).
1373
+ Do(context.Background())
1374
+
1375
+ require.Nil(t, err)
1376
+ require.NotNil(t, objects)
1377
+ require.Len(t, objects, 1)
1378
+ assert.Nil(t, objects[0].Properties.(map[string]interface{})["relatedToPizza"])
1379
+ }
1380
+ })
1381
+
1382
+ t.Run("verify new objects not created", func(t *testing.T) {
1383
+ for _, soupId := range soupIds {
1384
+ exists, err := client.Data().Checker().
1385
+ WithClassName("Soup").
1386
+ WithID(soupId).
1387
+ WithTenant(tenantPizza.Name).
1388
+ Do(context.Background())
1389
+
1390
+ require.NotNil(t, err)
1391
+ assert.False(t, exists)
1392
+ }
1393
+ })
1394
+ })
1395
+
1396
+ t.Run("fails creating references between non-MT and MT classes with non existent tenant", func(t *testing.T) {
1397
+ defer cleanup()
1398
+
1399
+ tenantPizza := models.Tenant{Name: "tenantPizza"}
1400
+ pizzaIds := fixtures.IdsByClass["Pizza"]
1401
+ soupIds := fixtures.IdsByClass["Soup"]
1402
+
1403
+ fixtures.CreateSchemaSoup(t, client)
1404
+ fixtures.CreateDataSoup(t, client)
1405
+
1406
+ fixtures.CreateSchemaPizzaForTenants(t, client)
1407
+ fixtures.CreateTenantsPizza(t, client, tenantPizza)
1408
+ fixtures.CreateDataPizzaForTenants(t, client, tenantPizza.Name)
1409
+
1410
+ t.Run("create ref property", func(t *testing.T) {
1411
+ err := client.Schema().PropertyCreator().
1412
+ WithClassName("Soup").
1413
+ WithProperty(&models.Property{
1414
+ Name: "relatedToPizza",
1415
+ DataType: []string{"Pizza"},
1416
+ }).
1417
+ Do(context.Background())
1418
+
1419
+ require.Nil(t, err)
1420
+ })
1421
+
1422
+ references := []*models.BatchReference{}
1423
+ for _, soupId := range soupIds {
1424
+ for _, pizzaId := range pizzaIds {
1425
+ rpb := client.Batch().ReferencePayloadBuilder().
1426
+ WithFromClassName("Soup").
1427
+ WithFromRefProp("relatedToPizza").
1428
+ WithFromID(soupId).
1429
+ WithToID(pizzaId).
1430
+ WithTenant("nonExistentTenant")
1431
+
1432
+ if tc.explicitTargetClass {
1433
+ rpb.WithToClassName("Pizza")
1434
+ }
1435
+
1436
+ references = append(references, rpb.Payload())
1437
+ }
1438
+ }
1439
+
1440
+ resp, err := client.Batch().ReferencesBatcher().
1441
+ WithReferences(references...).
1442
+ Do(context.Background())
1443
+
1444
+ require.Nil(t, err)
1445
+ require.NotNil(t, resp)
1446
+ assert.Len(t, resp, len(references))
1447
+ for i := range resp {
1448
+ require.NotNil(t, resp[i].Result)
1449
+ require.NotNil(t, resp[i].Result.Status)
1450
+ assert.Equal(t, "FAILED", *resp[i].Result.Status)
1451
+ require.NotNil(t, resp[i].Result.Errors)
1452
+ require.Len(t, resp[i].Result.Errors.Error, 1)
1453
+ assert.Contains(t, resp[i].Result.Errors.Error[0].Message, "cannot reference a multi-tenant enabled class from a non multi-tenant enabled class")
1454
+ }
1455
+
1456
+ t.Run("verify not created", func(t *testing.T) {
1457
+ for _, soupId := range soupIds {
1458
+ objects, err := client.Data().ObjectsGetter().
1459
+ WithClassName("Soup").
1460
+ WithID(soupId).
1461
+ Do(context.Background())
1462
+
1463
+ require.Nil(t, err)
1464
+ require.NotNil(t, objects)
1465
+ require.Len(t, objects, 1)
1466
+ assert.Nil(t, objects[0].Properties.(map[string]interface{})["relatedToPizza"])
1467
+ }
1468
+ })
1469
+
1470
+ t.Run("verify new objects not created", func(t *testing.T) {
1471
+ for _, soupId := range soupIds {
1472
+ exists, err := client.Data().Checker().
1473
+ WithClassName("Soup").
1474
+ WithID(soupId).
1475
+ WithTenant(tenantPizza.Name).
1476
+ Do(context.Background())
1477
+
1478
+ require.NotNil(t, err)
1479
+ assert.False(t, exists)
1480
+ }
1481
+ })
1482
+ })
1483
+
1484
+ t.Run("fails creating references between non-MT and MT classes with different existing tenant", func(t *testing.T) {
1485
+ defer cleanup()
1486
+
1487
+ tenants := fixtures.Tenants{
1488
+ {Name: "tenantNo1"},
1489
+ {Name: "tenantNo2"},
1490
+ }
1491
+ pizzaIds := fixtures.IdsByClass["Pizza"]
1492
+ soupIds := fixtures.IdsByClass["Soup"]
1493
+
1494
+ fixtures.CreateSchemaSoup(t, client)
1495
+ fixtures.CreateDataSoup(t, client)
1496
+
1497
+ fixtures.CreateSchemaPizzaForTenants(t, client)
1498
+ fixtures.CreateTenantsPizza(t, client, tenants...)
1499
+ fixtures.CreateDataPizzaForTenants(t, client, tenants[0].Name)
1500
+
1501
+ t.Run("create ref property", func(t *testing.T) {
1502
+ err := client.Schema().PropertyCreator().
1503
+ WithClassName("Soup").
1504
+ WithProperty(&models.Property{
1505
+ Name: "relatedToPizza",
1506
+ DataType: []string{"Pizza"},
1507
+ }).
1508
+ Do(context.Background())
1509
+
1510
+ require.Nil(t, err)
1511
+ })
1512
+
1513
+ references := []*models.BatchReference{}
1514
+ for _, soupId := range soupIds {
1515
+ for _, pizzaId := range pizzaIds {
1516
+ rpb := client.Batch().ReferencePayloadBuilder().
1517
+ WithFromClassName("Soup").
1518
+ WithFromRefProp("relatedToPizza").
1519
+ WithFromID(soupId).
1520
+ WithToID(pizzaId).
1521
+ WithTenant(tenants[1].Name)
1522
+
1523
+ if tc.explicitTargetClass {
1524
+ rpb.WithToClassName("Pizza")
1525
+ }
1526
+
1527
+ references = append(references, rpb.Payload())
1528
+ }
1529
+ }
1530
+
1531
+ resp, err := client.Batch().ReferencesBatcher().
1532
+ WithReferences(references...).
1533
+ Do(context.Background())
1534
+
1535
+ require.Nil(t, err)
1536
+ require.NotNil(t, resp)
1537
+ assert.Len(t, resp, len(references))
1538
+ for i := range resp {
1539
+ require.NotNil(t, resp[i].Result)
1540
+ require.NotNil(t, resp[i].Result.Status)
1541
+ assert.Equal(t, "FAILED", *resp[i].Result.Status)
1542
+ require.NotNil(t, resp[i].Result.Errors)
1543
+ require.Len(t, resp[i].Result.Errors.Error, 1)
1544
+ assert.Contains(t, resp[i].Result.Errors.Error[0].Message, "cannot reference a multi-tenant enabled class from a non multi-tenant enabled class")
1545
+ }
1546
+
1547
+ t.Run("verify not created", func(t *testing.T) {
1548
+ for _, soupId := range soupIds {
1549
+ objects, err := client.Data().ObjectsGetter().
1550
+ WithClassName("Soup").
1551
+ WithID(soupId).
1552
+ Do(context.Background())
1553
+
1554
+ require.Nil(t, err)
1555
+ require.NotNil(t, objects)
1556
+ require.Len(t, objects, 1)
1557
+ assert.Nil(t, objects[0].Properties.(map[string]interface{})["relatedToPizza"])
1558
+ }
1559
+ })
1560
+
1561
+ t.Run("verify new objects not created", func(t *testing.T) {
1562
+ for _, tenant := range tenants {
1563
+ for _, soupId := range soupIds {
1564
+ exists, err := client.Data().Checker().
1565
+ WithClassName("Soup").
1566
+ WithID(soupId).
1567
+ WithTenant(tenant.Name).
1568
+ Do(context.Background())
1569
+
1570
+ require.NotNil(t, err)
1571
+ assert.False(t, exists)
1572
+ }
1573
+ }
1574
+
1575
+ for _, pizzaId := range pizzaIds {
1576
+ exists, err := client.Data().Checker().
1577
+ WithClassName("Soup").
1578
+ WithID(pizzaId).
1579
+ WithTenant(tenants[1].Name).
1580
+ Do(context.Background())
1581
+
1582
+ require.NotNil(t, err)
1583
+ assert.False(t, exists)
1584
+ }
1585
+ })
1586
+ })
1587
+ })
1588
+ }
1589
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/multi_tenancy_tests/batch_test.go ADDED
@@ -0,0 +1,729 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package multi_tenancy_tests
13
+
14
+ import (
15
+ "context"
16
+ "testing"
17
+
18
+ "acceptance_tests_with_client/fixtures"
19
+
20
+ "github.com/stretchr/testify/assert"
21
+ "github.com/stretchr/testify/require"
22
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
23
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/fault"
24
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/filters"
25
+ "github.com/weaviate/weaviate/entities/models"
26
+ )
27
+
28
+ func TestBatchCreate_MultiTenancy(t *testing.T) {
29
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: "localhost:8080"})
30
+ require.Nil(t, err)
31
+
32
+ cleanup := func() {
33
+ err := client.Schema().AllDeleter().Do(context.Background())
34
+ require.Nil(t, err)
35
+ }
36
+
37
+ t.Run("creates objects of MT class", func(t *testing.T) {
38
+ defer cleanup()
39
+
40
+ tenants := fixtures.Tenants{
41
+ {Name: "tenantNo1"},
42
+ {Name: "tenantNo2"},
43
+ }
44
+
45
+ fixtures.CreateSchemaPizzaForTenants(t, client)
46
+ fixtures.CreateSchemaSoupForTenants(t, client)
47
+ fixtures.CreateTenantsPizza(t, client, tenants...)
48
+ fixtures.CreateTenantsSoup(t, client, tenants...)
49
+
50
+ for _, tenant := range tenants {
51
+ resp, err := client.Batch().ObjectsBatcher().
52
+ WithObjects(
53
+ &models.Object{
54
+ Class: "Pizza",
55
+ ID: fixtures.PIZZA_QUATTRO_FORMAGGI_ID,
56
+ Properties: map[string]interface{}{
57
+ "name": "Quattro Formaggi",
58
+ "description": "Pizza quattro formaggi Italian: [ˈkwattro forˈmaddʒi] (four cheese pizza) is a variety of pizza in Italian cuisine that is topped with a combination of four kinds of cheese, usually melted together, with (rossa, red) or without (bianca, white) tomato sauce. It is popular worldwide, including in Italy,[1] and is one of the iconic items from pizzerias's menus.",
59
+ "price": float32(1.1),
60
+ "best_before": "2022-05-03T12:04:40+02:00",
61
+ },
62
+ Tenant: tenant.Name,
63
+ },
64
+ &models.Object{
65
+ Class: "Pizza",
66
+ ID: fixtures.PIZZA_FRUTTI_DI_MARE_ID,
67
+ Properties: map[string]interface{}{
68
+ "name": "Frutti di Mare",
69
+ "description": "Frutti di Mare is an Italian type of pizza that may be served with scampi, mussels or squid. It typically lacks cheese, with the seafood being served atop a tomato sauce.",
70
+ "price": float32(1.2),
71
+ "best_before": "2022-05-05T07:16:30+02:00",
72
+ },
73
+ Tenant: tenant.Name,
74
+ },
75
+ &models.Object{
76
+ Class: "Soup",
77
+ ID: fixtures.SOUP_CHICKENSOUP_ID,
78
+ Properties: map[string]interface{}{
79
+ "name": "ChickenSoup",
80
+ "description": "Used by humans when their inferior genetics are attacked by microscopic organisms.",
81
+ "price": float32(2.1),
82
+ },
83
+ Tenant: tenant.Name,
84
+ },
85
+ &models.Object{
86
+ Class: "Soup",
87
+ ID: fixtures.SOUP_BEAUTIFUL_ID,
88
+ Properties: map[string]interface{}{
89
+ "name": "Beautiful",
90
+ "description": "Putting the game of letter soups to a whole new level.",
91
+ "price": float32(2.2),
92
+ },
93
+ Tenant: tenant.Name,
94
+ }).
95
+ Do(context.Background())
96
+
97
+ require.Nil(t, err)
98
+ require.NotNil(t, resp)
99
+ require.Len(t, resp, 4)
100
+
101
+ ids := make([]string, len(resp))
102
+ for i := range resp {
103
+ require.NotNil(t, resp[i])
104
+ require.NotNil(t, resp[i].Result)
105
+ require.NotNil(t, resp[i].Result.Status)
106
+ assert.Equal(t, "SUCCESS", *resp[i].Result.Status)
107
+ assert.Equal(t, tenant.Name, resp[i].Tenant)
108
+
109
+ ids[i] = resp[i].ID.String()
110
+ }
111
+ assert.ElementsMatch(t, ids, []string{
112
+ fixtures.PIZZA_QUATTRO_FORMAGGI_ID,
113
+ fixtures.PIZZA_FRUTTI_DI_MARE_ID,
114
+ fixtures.SOUP_CHICKENSOUP_ID,
115
+ fixtures.SOUP_BEAUTIFUL_ID,
116
+ })
117
+ }
118
+
119
+ t.Run("verify created", func(t *testing.T) {
120
+ for _, tenant := range tenants {
121
+ for id, className := range map[string]string{
122
+ fixtures.PIZZA_QUATTRO_FORMAGGI_ID: "Pizza",
123
+ fixtures.PIZZA_FRUTTI_DI_MARE_ID: "Pizza",
124
+ fixtures.SOUP_CHICKENSOUP_ID: "Soup",
125
+ fixtures.SOUP_BEAUTIFUL_ID: "Soup",
126
+ } {
127
+ exists, err := client.Data().Checker().
128
+ WithID(id).
129
+ WithClassName(className).
130
+ WithTenant(tenant.Name).
131
+ Do(context.Background())
132
+
133
+ require.Nil(t, err)
134
+ require.True(t, exists)
135
+ }
136
+ }
137
+ })
138
+ })
139
+
140
+ t.Run("fails creating objects of MT class without tenant", func(t *testing.T) {
141
+ defer cleanup()
142
+
143
+ tenants := fixtures.Tenants{
144
+ {Name: "tenantNo1"},
145
+ {Name: "tenantNo2"},
146
+ }
147
+
148
+ fixtures.CreateSchemaPizzaForTenants(t, client)
149
+ fixtures.CreateSchemaSoupForTenants(t, client)
150
+ fixtures.CreateTenantsPizza(t, client, tenants...)
151
+ fixtures.CreateTenantsSoup(t, client, tenants...)
152
+
153
+ resp, err := client.Batch().ObjectsBatcher().
154
+ WithObjects(
155
+ &models.Object{
156
+ Class: "Pizza",
157
+ ID: fixtures.PIZZA_QUATTRO_FORMAGGI_ID,
158
+ Properties: map[string]interface{}{
159
+ "name": "Quattro Formaggi",
160
+ "description": "Pizza quattro formaggi Italian: [ˈkwattro forˈmaddʒi] (four cheese pizza) is a variety of pizza in Italian cuisine that is topped with a combination of four kinds of cheese, usually melted together, with (rossa, red) or without (bianca, white) tomato sauce. It is popular worldwide, including in Italy,[1] and is one of the iconic items from pizzerias's menus.",
161
+ "price": float32(1.1),
162
+ "best_before": "2022-05-03T12:04:40+02:00",
163
+ },
164
+ },
165
+ &models.Object{
166
+ Class: "Pizza",
167
+ ID: fixtures.PIZZA_FRUTTI_DI_MARE_ID,
168
+ Properties: map[string]interface{}{
169
+ "name": "Frutti di Mare",
170
+ "description": "Frutti di Mare is an Italian type of pizza that may be served with scampi, mussels or squid. It typically lacks cheese, with the seafood being served atop a tomato sauce.",
171
+ "price": float32(1.2),
172
+ "best_before": "2022-05-05T07:16:30+02:00",
173
+ },
174
+ },
175
+ &models.Object{
176
+ Class: "Soup",
177
+ ID: fixtures.SOUP_CHICKENSOUP_ID,
178
+ Properties: map[string]interface{}{
179
+ "name": "ChickenSoup",
180
+ "description": "Used by humans when their inferior genetics are attacked by microscopic organisms.",
181
+ "price": float32(2.1),
182
+ },
183
+ },
184
+ &models.Object{
185
+ Class: "Soup",
186
+ ID: fixtures.SOUP_BEAUTIFUL_ID,
187
+ Properties: map[string]interface{}{
188
+ "name": "Beautiful",
189
+ "description": "Putting the game of letter soups to a whole new level.",
190
+ "price": float32(2.2),
191
+ },
192
+ }).
193
+ Do(context.Background())
194
+
195
+ require.Nil(t, err)
196
+ require.NotNil(t, resp)
197
+ require.Len(t, resp, 4)
198
+
199
+ for i := range resp {
200
+ require.NotNil(t, resp[i])
201
+ require.NotNil(t, resp[i].Result)
202
+ require.NotNil(t, resp[i].Result.Status)
203
+ assert.Equal(t, "FAILED", *resp[i].Result.Status)
204
+ require.NotNil(t, resp[i].Result.Errors)
205
+ require.NotNil(t, resp[i].Result.Errors.Error)
206
+ require.Len(t, resp[i].Result.Errors.Error, 1)
207
+ assert.Contains(t, resp[i].Result.Errors.Error[0].Message, "has multi-tenancy enabled, but request was without tenant")
208
+ assert.Empty(t, resp[i].Tenant)
209
+ }
210
+
211
+ t.Run("verify not created", func(t *testing.T) {
212
+ for _, tenant := range tenants {
213
+ for id, className := range map[string]string{
214
+ fixtures.PIZZA_QUATTRO_FORMAGGI_ID: "Pizza",
215
+ fixtures.PIZZA_FRUTTI_DI_MARE_ID: "Pizza",
216
+ fixtures.SOUP_CHICKENSOUP_ID: "Soup",
217
+ fixtures.SOUP_BEAUTIFUL_ID: "Soup",
218
+ } {
219
+ exists, err := client.Data().Checker().
220
+ WithID(id).
221
+ WithClassName(className).
222
+ WithTenant(tenant.Name).
223
+ Do(context.Background())
224
+
225
+ require.Nil(t, err)
226
+ require.False(t, exists)
227
+ }
228
+ }
229
+ })
230
+ })
231
+
232
+ t.Run("fails creating objects of MT class with non existent tenant", func(t *testing.T) {
233
+ defer cleanup()
234
+
235
+ tenants := fixtures.Tenants{
236
+ {Name: "tenantNo1"},
237
+ {Name: "tenantNo2"},
238
+ }
239
+
240
+ fixtures.CreateSchemaPizzaForTenants(t, client)
241
+ fixtures.CreateSchemaSoupForTenants(t, client)
242
+ fixtures.CreateTenantsPizza(t, client, tenants...)
243
+ fixtures.CreateTenantsSoup(t, client, tenants...)
244
+
245
+ resp, err := client.Batch().ObjectsBatcher().
246
+ WithObjects(
247
+ &models.Object{
248
+ Class: "Pizza",
249
+ ID: fixtures.PIZZA_QUATTRO_FORMAGGI_ID,
250
+ Properties: map[string]interface{}{
251
+ "name": "Quattro Formaggi",
252
+ "description": "Pizza quattro formaggi Italian: [ˈkwattro forˈmaddʒi] (four cheese pizza) is a variety of pizza in Italian cuisine that is topped with a combination of four kinds of cheese, usually melted together, with (rossa, red) or without (bianca, white) tomato sauce. It is popular worldwide, including in Italy,[1] and is one of the iconic items from pizzerias's menus.",
253
+ "price": float32(1.1),
254
+ "best_before": "2022-05-03T12:04:40+02:00",
255
+ },
256
+ Tenant: "nonExistentTenant",
257
+ },
258
+ &models.Object{
259
+ Class: "Pizza",
260
+ ID: fixtures.PIZZA_FRUTTI_DI_MARE_ID,
261
+ Properties: map[string]interface{}{
262
+ "name": "Frutti di Mare",
263
+ "description": "Frutti di Mare is an Italian type of pizza that may be served with scampi, mussels or squid. It typically lacks cheese, with the seafood being served atop a tomato sauce.",
264
+ "price": float32(1.2),
265
+ "best_before": "2022-05-05T07:16:30+02:00",
266
+ },
267
+ Tenant: "nonExistentTenant",
268
+ },
269
+ &models.Object{
270
+ Class: "Soup",
271
+ ID: fixtures.SOUP_CHICKENSOUP_ID,
272
+ Properties: map[string]interface{}{
273
+ "name": "ChickenSoup",
274
+ "description": "Used by humans when their inferior genetics are attacked by microscopic organisms.",
275
+ "price": float32(2.1),
276
+ },
277
+ Tenant: "nonExistentTenant",
278
+ },
279
+ &models.Object{
280
+ Class: "Soup",
281
+ ID: fixtures.SOUP_BEAUTIFUL_ID,
282
+ Properties: map[string]interface{}{
283
+ "name": "Beautiful",
284
+ "description": "Putting the game of letter soups to a whole new level.",
285
+ "price": float32(2.2),
286
+ },
287
+ Tenant: "nonExistentTenant",
288
+ }).
289
+ Do(context.Background())
290
+
291
+ require.Nil(t, err)
292
+ require.NotNil(t, resp)
293
+ assert.Len(t, resp, 4)
294
+ for i := range resp {
295
+ require.NotNil(t, resp[i])
296
+ require.NotNil(t, resp[i].Result)
297
+ require.NotNil(t, resp[i].Result.Status)
298
+ assert.Equal(t, "FAILED", *resp[i].Result.Status)
299
+ require.NotNil(t, resp[i].Result.Errors)
300
+ require.NotNil(t, resp[i].Result.Errors.Error)
301
+ require.Len(t, resp[i].Result.Errors.Error, 1)
302
+ assert.Contains(t, resp[i].Result.Errors.Error[0].Message, "tenant not found")
303
+ assert.Equal(t, "nonExistentTenant", resp[i].Tenant)
304
+ }
305
+
306
+ t.Run("verify not created", func(t *testing.T) {
307
+ for _, tenant := range tenants {
308
+ for id, className := range map[string]string{
309
+ fixtures.PIZZA_QUATTRO_FORMAGGI_ID: "Pizza",
310
+ fixtures.PIZZA_FRUTTI_DI_MARE_ID: "Pizza",
311
+ fixtures.SOUP_CHICKENSOUP_ID: "Soup",
312
+ fixtures.SOUP_BEAUTIFUL_ID: "Soup",
313
+ } {
314
+ exists, err := client.Data().Checker().
315
+ WithID(id).
316
+ WithClassName(className).
317
+ WithTenant(tenant.Name).
318
+ Do(context.Background())
319
+
320
+ require.Nil(t, err)
321
+ require.False(t, exists)
322
+ }
323
+ }
324
+ })
325
+ })
326
+
327
+ t.Run("fails creating objects of non-MT class when tenant given", func(t *testing.T) {
328
+ defer cleanup()
329
+
330
+ tenants := fixtures.Tenants{
331
+ {Name: "tenantNo1"},
332
+ {Name: "tenantNo2"},
333
+ }
334
+
335
+ fixtures.CreateSchemaPizza(t, client)
336
+ fixtures.CreateSchemaSoup(t, client)
337
+
338
+ for _, tenant := range tenants {
339
+ resp, err := client.Batch().ObjectsBatcher().
340
+ WithObjects(
341
+ &models.Object{
342
+ Class: "Pizza",
343
+ ID: fixtures.PIZZA_QUATTRO_FORMAGGI_ID,
344
+ Properties: map[string]interface{}{
345
+ "name": "Quattro Formaggi",
346
+ "description": "Pizza quattro formaggi Italian: [ˈkwattro forˈmaddʒi] (four cheese pizza) is a variety of pizza in Italian cuisine that is topped with a combination of four kinds of cheese, usually melted together, with (rossa, red) or without (bianca, white) tomato sauce. It is popular worldwide, including in Italy,[1] and is one of the iconic items from pizzerias's menus.",
347
+ "price": float32(1.1),
348
+ "best_before": "2022-05-03T12:04:40+02:00",
349
+ },
350
+ Tenant: tenant.Name,
351
+ },
352
+ &models.Object{
353
+ Class: "Pizza",
354
+ ID: fixtures.PIZZA_FRUTTI_DI_MARE_ID,
355
+ Properties: map[string]interface{}{
356
+ "name": "Frutti di Mare",
357
+ "description": "Frutti di Mare is an Italian type of pizza that may be served with scampi, mussels or squid. It typically lacks cheese, with the seafood being served atop a tomato sauce.",
358
+ "price": float32(1.2),
359
+ "best_before": "2022-05-05T07:16:30+02:00",
360
+ },
361
+ Tenant: tenant.Name,
362
+ },
363
+ &models.Object{
364
+ Class: "Soup",
365
+ ID: fixtures.SOUP_CHICKENSOUP_ID,
366
+ Properties: map[string]interface{}{
367
+ "name": "ChickenSoup",
368
+ "description": "Used by humans when their inferior genetics are attacked by microscopic organisms.",
369
+ "price": float32(2.1),
370
+ },
371
+ Tenant: tenant.Name,
372
+ },
373
+ &models.Object{
374
+ Class: "Soup",
375
+ ID: fixtures.SOUP_BEAUTIFUL_ID,
376
+ Properties: map[string]interface{}{
377
+ "name": "Beautiful",
378
+ "description": "Putting the game of letter soups to a whole new level.",
379
+ "price": float32(2.2),
380
+ },
381
+ Tenant: tenant.Name,
382
+ }).
383
+ Do(context.Background())
384
+
385
+ require.Nil(t, err)
386
+ require.NotNil(t, resp)
387
+ require.Len(t, resp, 4)
388
+ for i := range resp {
389
+ require.NotNil(t, resp[i])
390
+ require.NotNil(t, resp[i].Result)
391
+ require.NotNil(t, resp[i].Result.Status)
392
+ assert.Equal(t, "FAILED", *resp[i].Result.Status)
393
+ require.NotNil(t, resp[i].Result.Errors)
394
+ require.NotNil(t, resp[i].Result.Errors.Error)
395
+ require.Len(t, resp[i].Result.Errors.Error, 1)
396
+ assert.Contains(t, resp[i].Result.Errors.Error[0].Message, "has multi-tenancy disabled, but request was with tenant")
397
+ assert.Equal(t, tenant.Name, resp[i].Tenant)
398
+ }
399
+ }
400
+
401
+ t.Run("verify not created", func(t *testing.T) {
402
+ for id, className := range map[string]string{
403
+ fixtures.PIZZA_QUATTRO_FORMAGGI_ID: "Pizza",
404
+ fixtures.PIZZA_FRUTTI_DI_MARE_ID: "Pizza",
405
+ fixtures.SOUP_CHICKENSOUP_ID: "Soup",
406
+ fixtures.SOUP_BEAUTIFUL_ID: "Soup",
407
+ } {
408
+ exists, err := client.Data().Checker().
409
+ WithID(id).
410
+ WithClassName(className).
411
+ Do(context.Background())
412
+
413
+ require.Nil(t, err)
414
+ require.False(t, exists)
415
+ }
416
+ })
417
+ })
418
+ }
419
+
420
+ func TestBatchDelete_MultiTenancy(t *testing.T) {
421
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: "localhost:8080"})
422
+ require.Nil(t, err)
423
+
424
+ cleanup := func() {
425
+ err := client.Schema().AllDeleter().Do(context.Background())
426
+ require.Nil(t, err)
427
+ }
428
+
429
+ t.Run("deletes objects from MT class", func(t *testing.T) {
430
+ defer cleanup()
431
+
432
+ tenants := fixtures.Tenants{
433
+ {Name: "tenantNo1"},
434
+ {Name: "tenantNo2"},
435
+ }
436
+
437
+ fixtures.CreateSchemaFoodForTenants(t, client)
438
+ fixtures.CreateTenantsFood(t, client, tenants...)
439
+ fixtures.CreateDataFoodForTenants(t, client, tenants.Names()...)
440
+
441
+ for _, tenant := range tenants {
442
+ for className, ids := range fixtures.IdsByClass {
443
+ resp, err := client.Batch().ObjectsBatchDeleter().
444
+ WithClassName(className).
445
+ WithWhere(filters.Where().
446
+ WithOperator(filters.Like).
447
+ WithPath([]string{"name"}).
448
+ WithValueText("*")).
449
+ WithOutput("minimal").
450
+ WithTenant(tenant.Name).
451
+ Do(context.Background())
452
+
453
+ require.Nil(t, err)
454
+ require.NotNil(t, resp)
455
+ require.NotNil(t, resp.Results)
456
+ assert.Equal(t, int64(len(ids)), resp.Results.Matches)
457
+ assert.Equal(t, int64(len(ids)), resp.Results.Successful)
458
+ }
459
+ }
460
+
461
+ t.Run("verify deleted", func(t *testing.T) {
462
+ for _, tenant := range tenants {
463
+ for className, ids := range fixtures.IdsByClass {
464
+ for _, id := range ids {
465
+ exists, err := client.Data().Checker().
466
+ WithID(id).
467
+ WithClassName(className).
468
+ WithTenant(tenant.Name).
469
+ Do(context.Background())
470
+
471
+ require.Nil(t, err)
472
+ require.False(t, exists)
473
+ }
474
+ }
475
+ }
476
+ })
477
+ })
478
+
479
+ t.Run("fails deleting objects from MT class without tenant", func(t *testing.T) {
480
+ defer cleanup()
481
+
482
+ tenants := fixtures.Tenants{
483
+ {Name: "tenantNo1"},
484
+ {Name: "tenantNo2"},
485
+ }
486
+
487
+ fixtures.CreateSchemaFoodForTenants(t, client)
488
+ fixtures.CreateTenantsFood(t, client, tenants...)
489
+ fixtures.CreateDataFoodForTenants(t, client, tenants.Names()...)
490
+
491
+ for className := range fixtures.IdsByClass {
492
+ resp, err := client.Batch().ObjectsBatchDeleter().
493
+ WithClassName(className).
494
+ WithWhere(filters.Where().
495
+ WithOperator(filters.Like).
496
+ WithPath([]string{"name"}).
497
+ WithValueText("*")).
498
+ WithOutput("minimal").
499
+ Do(context.Background())
500
+
501
+ require.NotNil(t, err)
502
+ clientErr := err.(*fault.WeaviateClientError)
503
+ assert.Equal(t, 422, clientErr.StatusCode)
504
+ assert.Contains(t, clientErr.Msg, "has multi-tenancy enabled, but request was without tenant")
505
+ require.Nil(t, resp)
506
+ }
507
+
508
+ t.Run("verify not deleted", func(t *testing.T) {
509
+ for _, tenant := range tenants {
510
+ for className, ids := range fixtures.IdsByClass {
511
+ for _, id := range ids {
512
+ exists, err := client.Data().Checker().
513
+ WithID(id).
514
+ WithClassName(className).
515
+ WithTenant(tenant.Name).
516
+ Do(context.Background())
517
+
518
+ require.Nil(t, err)
519
+ require.True(t, exists)
520
+ }
521
+ }
522
+ }
523
+ })
524
+ })
525
+
526
+ t.Run("fails deleting objects from MT class with non existent tenant", func(t *testing.T) {
527
+ defer cleanup()
528
+
529
+ tenants := fixtures.Tenants{
530
+ {Name: "tenantNo1"},
531
+ {Name: "tenantNo2"},
532
+ }
533
+
534
+ fixtures.CreateSchemaFoodForTenants(t, client)
535
+ fixtures.CreateTenantsFood(t, client, tenants...)
536
+ fixtures.CreateDataFoodForTenants(t, client, tenants.Names()...)
537
+
538
+ for className := range fixtures.IdsByClass {
539
+ resp, err := client.Batch().ObjectsBatchDeleter().
540
+ WithClassName(className).
541
+ WithWhere(filters.Where().
542
+ WithOperator(filters.Like).
543
+ WithPath([]string{"name"}).
544
+ WithValueText("*")).
545
+ WithOutput("minimal").
546
+ WithTenant("nonExistentTenant").
547
+ Do(context.Background())
548
+
549
+ require.NotNil(t, err)
550
+ clientErr := err.(*fault.WeaviateClientError)
551
+ assert.Equal(t, 422, clientErr.StatusCode)
552
+ assert.Contains(t, clientErr.Msg, "tenant not found")
553
+ require.Nil(t, resp)
554
+ }
555
+
556
+ t.Run("verify not deleted", func(t *testing.T) {
557
+ for _, tenant := range tenants {
558
+ for className, ids := range fixtures.IdsByClass {
559
+ for _, id := range ids {
560
+ exists, err := client.Data().Checker().
561
+ WithID(id).
562
+ WithClassName(className).
563
+ WithTenant(tenant.Name).
564
+ Do(context.Background())
565
+
566
+ require.Nil(t, err)
567
+ require.True(t, exists)
568
+ }
569
+ }
570
+ }
571
+ })
572
+ })
573
+
574
+ t.Run("fails deleting objects from non-MT class when tenant given", func(t *testing.T) {
575
+ defer cleanup()
576
+
577
+ fixtures.CreateSchemaFood(t, client)
578
+ fixtures.CreateDataFood(t, client)
579
+
580
+ for className := range fixtures.IdsByClass {
581
+ resp, err := client.Batch().ObjectsBatchDeleter().
582
+ WithClassName(className).
583
+ WithWhere(filters.Where().
584
+ WithOperator(filters.Like).
585
+ WithPath([]string{"name"}).
586
+ WithValueText("*")).
587
+ WithOutput("minimal").
588
+ WithTenant("nonExistentTenant").
589
+ Do(context.Background())
590
+
591
+ require.NotNil(t, err)
592
+ clientErr := err.(*fault.WeaviateClientError)
593
+ assert.Equal(t, 422, clientErr.StatusCode)
594
+ assert.Contains(t, clientErr.Msg, "has multi-tenancy disabled, but request was with tenant")
595
+ require.Nil(t, resp)
596
+ }
597
+
598
+ t.Run("verify non deleted", func(t *testing.T) {
599
+ for className, ids := range fixtures.IdsByClass {
600
+ for _, id := range ids {
601
+ exists, err := client.Data().Checker().
602
+ WithID(id).
603
+ WithClassName(className).
604
+ Do(context.Background())
605
+
606
+ require.Nil(t, err)
607
+ require.True(t, exists)
608
+ }
609
+ }
610
+ })
611
+ })
612
+
613
+ t.Run("deletes objects from MT class by ref", func(t *testing.T) {
614
+ defer cleanup()
615
+
616
+ tenant1 := models.Tenant{Name: "tenantNo1"}
617
+ tenant2 := models.Tenant{Name: "tenantNo2"}
618
+ soupIdByTenantAndPizza := map[string]map[string]string{
619
+ tenant1.Name: {
620
+ fixtures.PIZZA_QUATTRO_FORMAGGI_ID: fixtures.SOUP_CHICKENSOUP_ID,
621
+ fixtures.PIZZA_FRUTTI_DI_MARE_ID: fixtures.SOUP_CHICKENSOUP_ID,
622
+ },
623
+ tenant2.Name: {
624
+ fixtures.PIZZA_HAWAII_ID: fixtures.SOUP_BEAUTIFUL_ID,
625
+ fixtures.PIZZA_DOENER_ID: fixtures.SOUP_BEAUTIFUL_ID,
626
+ },
627
+ }
628
+
629
+ t.Run("add data", func(t *testing.T) {
630
+ fixtures.CreateSchemaPizzaForTenants(t, client)
631
+ fixtures.CreateTenantsPizza(t, client, tenant1, tenant2)
632
+ fixtures.CreateDataPizzaQuattroFormaggiForTenants(t, client, tenant1.Name)
633
+ fixtures.CreateDataPizzaFruttiDiMareForTenants(t, client, tenant1.Name)
634
+ fixtures.CreateDataPizzaHawaiiForTenants(t, client, tenant2.Name)
635
+ fixtures.CreateDataPizzaDoenerForTenants(t, client, tenant2.Name)
636
+
637
+ fixtures.CreateSchemaSoupForTenants(t, client)
638
+ fixtures.CreateTenantsSoup(t, client, tenant1, tenant2)
639
+ fixtures.CreateDataSoupChickenForTenants(t, client, tenant1.Name)
640
+ fixtures.CreateDataSoupBeautifulForTenants(t, client, tenant2.Name)
641
+ })
642
+
643
+ t.Run("create ref property", func(t *testing.T) {
644
+ err := client.Schema().PropertyCreator().
645
+ WithClassName("Soup").
646
+ WithProperty(&models.Property{
647
+ Name: "relatedToPizza",
648
+ DataType: []string{"Pizza"},
649
+ }).
650
+ Do(context.Background())
651
+
652
+ require.Nil(t, err)
653
+ })
654
+
655
+ t.Run("create refs", func(t *testing.T) {
656
+ references := []*models.BatchReference{}
657
+
658
+ for tenant, pizzaToSoup := range soupIdByTenantAndPizza {
659
+ for pizzaId, soupId := range pizzaToSoup {
660
+ rpb := client.Batch().ReferencePayloadBuilder().
661
+ WithFromClassName("Soup").
662
+ WithFromRefProp("relatedToPizza").
663
+ WithFromID(soupId).
664
+ WithToClassName("Pizza").
665
+ WithToID(pizzaId).
666
+ WithTenant(tenant)
667
+
668
+ references = append(references, rpb.Payload())
669
+ }
670
+ }
671
+
672
+ resp, err := client.Batch().ReferencesBatcher().
673
+ WithReferences(references...).
674
+ Do(context.Background())
675
+
676
+ require.Nil(t, err)
677
+ require.NotNil(t, resp)
678
+ assert.Len(t, resp, len(references))
679
+ for i := range resp {
680
+ require.NotNil(t, resp[i].Result)
681
+ assert.Nil(t, resp[i].Result.Errors)
682
+ }
683
+ })
684
+
685
+ for tenant, pizzaToSoup := range soupIdByTenantAndPizza {
686
+ i := 0
687
+ for pizzaId := range pizzaToSoup {
688
+ resp, err := client.Batch().ObjectsBatchDeleter().
689
+ WithClassName("Soup").
690
+ WithWhere(filters.Where().
691
+ WithOperator(filters.Like).
692
+ WithPath([]string{"relatedToPizza", "Pizza", "_id"}).
693
+ WithValueText(pizzaId)).
694
+ WithOutput("minimal").
695
+ WithTenant(tenant).
696
+ Do(context.Background())
697
+
698
+ require.Nil(t, err)
699
+ require.NotNil(t, resp)
700
+ require.NotNil(t, resp.Results)
701
+
702
+ // single soup references two pizzas, so soup will be deleted only for 1st pizza
703
+ if i == 0 {
704
+ assert.Equal(t, int64(1), resp.Results.Matches)
705
+ assert.Equal(t, int64(1), resp.Results.Successful)
706
+ } else {
707
+ assert.Equal(t, int64(0), resp.Results.Matches)
708
+ assert.Equal(t, int64(0), resp.Results.Successful)
709
+ }
710
+ i++
711
+ }
712
+ }
713
+
714
+ t.Run("verify deleted", func(t *testing.T) {
715
+ for tenant, pizzaToSoup := range soupIdByTenantAndPizza {
716
+ for _, soupId := range pizzaToSoup {
717
+ exists, err := client.Data().Checker().
718
+ WithID(soupId).
719
+ WithClassName("Soup").
720
+ WithTenant(tenant).
721
+ Do(context.Background())
722
+
723
+ require.Nil(t, err)
724
+ require.False(t, exists)
725
+ }
726
+ }
727
+ })
728
+ })
729
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/multi_tenancy_tests/data_test.go ADDED
@@ -0,0 +1,1382 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package multi_tenancy_tests
13
+
14
+ import (
15
+ "context"
16
+ "fmt"
17
+ "testing"
18
+
19
+ "acceptance_tests_with_client/fixtures"
20
+
21
+ "github.com/go-openapi/strfmt"
22
+ "github.com/stretchr/testify/assert"
23
+ "github.com/stretchr/testify/require"
24
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
25
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/fault"
26
+ "github.com/weaviate/weaviate/entities/models"
27
+ )
28
+
29
+ func TestData_MultiTenancy(t *testing.T) {
30
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: "localhost:8080"})
31
+ require.Nil(t, err)
32
+
33
+ cleanup := func() {
34
+ err := client.Schema().AllDeleter().Do(context.Background())
35
+ require.Nil(t, err)
36
+ }
37
+
38
+ t.Run("creates objects of MT class", func(t *testing.T) {
39
+ defer cleanup()
40
+
41
+ className := "Pizza"
42
+ tenants := fixtures.Tenants{
43
+ {Name: "tenantNo1"},
44
+ {Name: "tenantNo2"},
45
+ }
46
+
47
+ fixtures.CreateSchemaPizzaForTenants(t, client)
48
+ fixtures.CreateTenantsPizza(t, client, tenants...)
49
+
50
+ for _, tenant := range tenants {
51
+ wrap, err := client.Data().Creator().
52
+ WithClassName(className).
53
+ WithID(fixtures.PIZZA_QUATTRO_FORMAGGI_ID).
54
+ WithProperties(map[string]interface{}{
55
+ "name": "Quattro Formaggi",
56
+ "description": "Pizza quattro formaggi Italian: [ˈkwattro forˈmaddʒi] (four cheese pizza) is a variety of pizza in Italian cuisine that is topped with a combination of four kinds of cheese, usually melted together, with (rossa, red) or without (bianca, white) tomato sauce. It is popular worldwide, including in Italy,[1] and is one of the iconic items from pizzerias's menus.",
57
+ "price": float32(1.1),
58
+ "best_before": "2022-05-03T12:04:40+02:00",
59
+ }).
60
+ WithTenant(tenant.Name).
61
+ Do(context.Background())
62
+
63
+ require.Nil(t, err)
64
+ require.NotNil(t, wrap)
65
+ require.NotNil(t, wrap.Object)
66
+ assert.Equal(t, strfmt.UUID(fixtures.PIZZA_QUATTRO_FORMAGGI_ID), wrap.Object.ID)
67
+ assert.Equal(t, "Quattro Formaggi", wrap.Object.Properties.(map[string]interface{})["name"])
68
+ assert.Equal(t, tenant.Name, wrap.Object.Tenant)
69
+
70
+ wrap, err = client.Data().Creator().
71
+ WithClassName(className).
72
+ WithID(fixtures.PIZZA_FRUTTI_DI_MARE_ID).
73
+ WithProperties(map[string]interface{}{
74
+ "name": "Frutti di Mare",
75
+ "description": "Frutti di Mare is an Italian type of pizza that may be served with scampi, mussels or squid. It typically lacks cheese, with the seafood being served atop a tomato sauce.",
76
+ "price": float32(1.2),
77
+ "best_before": "2022-05-05T07:16:30+02:00",
78
+ }).
79
+ WithTenant(tenant.Name).
80
+ Do(context.Background())
81
+
82
+ require.Nil(t, err)
83
+ require.NotNil(t, wrap)
84
+ require.NotNil(t, wrap.Object)
85
+ assert.Equal(t, strfmt.UUID(fixtures.PIZZA_FRUTTI_DI_MARE_ID), wrap.Object.ID)
86
+ assert.Equal(t, "Frutti di Mare", wrap.Object.Properties.(map[string]interface{})["name"])
87
+ assert.Equal(t, tenant.Name, wrap.Object.Tenant)
88
+ }
89
+
90
+ t.Run("verify created", func(t *testing.T) {
91
+ for _, tenant := range tenants {
92
+ for _, id := range []string{
93
+ fixtures.PIZZA_QUATTRO_FORMAGGI_ID,
94
+ fixtures.PIZZA_FRUTTI_DI_MARE_ID,
95
+ } {
96
+ exists, err := client.Data().Checker().
97
+ WithID(id).
98
+ WithClassName(className).
99
+ WithTenant(tenant.Name).
100
+ Do(context.Background())
101
+
102
+ require.Nil(t, err)
103
+ require.True(t, exists)
104
+ }
105
+ }
106
+ })
107
+ })
108
+
109
+ t.Run("fails creating objects of MT class without tenant", func(t *testing.T) {
110
+ defer cleanup()
111
+
112
+ className := "Pizza"
113
+ tenants := fixtures.Tenants{
114
+ {Name: "tenantNo1"},
115
+ {Name: "tenantNo2"},
116
+ }
117
+
118
+ fixtures.CreateSchemaPizzaForTenants(t, client)
119
+ fixtures.CreateTenantsPizza(t, client, tenants...)
120
+
121
+ wrap, err := client.Data().Creator().
122
+ WithClassName(className).
123
+ WithID(fixtures.PIZZA_QUATTRO_FORMAGGI_ID).
124
+ WithProperties(map[string]interface{}{
125
+ "name": "Quattro Formaggi",
126
+ "description": "Pizza quattro formaggi Italian: [ˈkwattro forˈmaddʒi] (four cheese pizza) is a variety of pizza in Italian cuisine that is topped with a combination of four kinds of cheese, usually melted together, with (rossa, red) or without (bianca, white) tomato sauce. It is popular worldwide, including in Italy,[1] and is one of the iconic items from pizzerias's menus.",
127
+ "price": float32(1.1),
128
+ "best_before": "2022-05-03T12:04:40+02:00",
129
+ }).
130
+ Do(context.Background())
131
+
132
+ require.NotNil(t, err)
133
+ clientErr := err.(*fault.WeaviateClientError)
134
+ assert.Equal(t, 422, clientErr.StatusCode)
135
+ assert.Contains(t, clientErr.Msg, "has multi-tenancy enabled, but request was without tenant")
136
+ require.Nil(t, wrap)
137
+
138
+ wrap, err = client.Data().Creator().
139
+ WithClassName(className).
140
+ WithID(fixtures.PIZZA_FRUTTI_DI_MARE_ID).
141
+ WithProperties(map[string]interface{}{
142
+ "name": "Frutti di Mare",
143
+ "description": "Frutti di Mare is an Italian type of pizza that may be served with scampi, mussels or squid. It typically lacks cheese, with the seafood being served atop a tomato sauce.",
144
+ "price": float32(1.2),
145
+ "best_before": "2022-05-05T07:16:30+02:00",
146
+ }).
147
+ Do(context.Background())
148
+
149
+ require.NotNil(t, err)
150
+ clientErr = err.(*fault.WeaviateClientError)
151
+ assert.Equal(t, 422, clientErr.StatusCode)
152
+ assert.Contains(t, clientErr.Msg, "has multi-tenancy enabled, but request was without tenant")
153
+ require.Nil(t, wrap)
154
+
155
+ t.Run("verify not created", func(t *testing.T) {
156
+ for _, tenant := range tenants {
157
+ for _, id := range []string{
158
+ fixtures.PIZZA_QUATTRO_FORMAGGI_ID,
159
+ fixtures.PIZZA_FRUTTI_DI_MARE_ID,
160
+ } {
161
+ exists, err := client.Data().Checker().
162
+ WithID(id).
163
+ WithClassName(className).
164
+ WithTenant(tenant.Name).
165
+ Do(context.Background())
166
+
167
+ require.Nil(t, err)
168
+ require.False(t, exists)
169
+ }
170
+ }
171
+ })
172
+ })
173
+
174
+ t.Run("fails creating objects of MT class with non existent tenant", func(t *testing.T) {
175
+ defer cleanup()
176
+
177
+ className := "Pizza"
178
+ tenants := fixtures.Tenants{
179
+ {Name: "tenantNo1"},
180
+ {Name: "tenantNo2"},
181
+ }
182
+
183
+ fixtures.CreateSchemaPizzaForTenants(t, client)
184
+ fixtures.CreateTenantsPizza(t, client, tenants...)
185
+
186
+ wrap, err := client.Data().Creator().
187
+ WithClassName(className).
188
+ WithID(fixtures.PIZZA_QUATTRO_FORMAGGI_ID).
189
+ WithProperties(map[string]interface{}{
190
+ "name": "Quattro Formaggi",
191
+ "description": "Pizza quattro formaggi Italian: [ˈkwattro forˈmaddʒi] (four cheese pizza) is a variety of pizza in Italian cuisine that is topped with a combination of four kinds of cheese, usually melted together, with (rossa, red) or without (bianca, white) tomato sauce. It is popular worldwide, including in Italy,[1] and is one of the iconic items from pizzerias's menus.",
192
+ "price": float32(1.1),
193
+ "best_before": "2022-05-03T12:04:40+02:00",
194
+ }).
195
+ WithTenant("nonExistentTenant").
196
+ Do(context.Background())
197
+
198
+ require.NotNil(t, err)
199
+ clientErr := err.(*fault.WeaviateClientError)
200
+ assert.Equal(t, 422, clientErr.StatusCode)
201
+ assert.Contains(t, clientErr.Msg, "tenant not found")
202
+ require.Nil(t, wrap)
203
+
204
+ wrap, err = client.Data().Creator().
205
+ WithClassName(className).
206
+ WithID(fixtures.PIZZA_FRUTTI_DI_MARE_ID).
207
+ WithProperties(map[string]interface{}{
208
+ "name": "Frutti di Mare",
209
+ "description": "Frutti di Mare is an Italian type of pizza that may be served with scampi, mussels or squid. It typically lacks cheese, with the seafood being served atop a tomato sauce.",
210
+ "price": float32(1.2),
211
+ "best_before": "2022-05-05T07:16:30+02:00",
212
+ }).
213
+ WithTenant("nonExistentTenant").
214
+ Do(context.Background())
215
+
216
+ require.NotNil(t, err)
217
+ clientErr = err.(*fault.WeaviateClientError)
218
+ assert.Equal(t, 422, clientErr.StatusCode)
219
+ assert.Contains(t, clientErr.Msg, "tenant not found")
220
+ require.Nil(t, wrap)
221
+
222
+ t.Run("verify not created", func(t *testing.T) {
223
+ for _, tenant := range tenants {
224
+ for _, id := range []string{
225
+ fixtures.PIZZA_QUATTRO_FORMAGGI_ID,
226
+ fixtures.PIZZA_FRUTTI_DI_MARE_ID,
227
+ } {
228
+ exists, err := client.Data().Checker().
229
+ WithID(id).
230
+ WithClassName(className).
231
+ WithTenant(tenant.Name).
232
+ Do(context.Background())
233
+
234
+ require.Nil(t, err)
235
+ require.False(t, exists)
236
+ }
237
+ }
238
+ })
239
+ })
240
+
241
+ t.Run("fails creating objects of non-MT class when tenant given", func(t *testing.T) {
242
+ defer cleanup()
243
+
244
+ className := "Pizza"
245
+
246
+ fixtures.CreateSchemaPizza(t, client)
247
+
248
+ wrap, err := client.Data().Creator().
249
+ WithClassName(className).
250
+ WithID(fixtures.PIZZA_QUATTRO_FORMAGGI_ID).
251
+ WithProperties(map[string]interface{}{
252
+ "name": "Quattro Formaggi",
253
+ "description": "Pizza quattro formaggi Italian: [ˈkwattro forˈmaddʒi] (four cheese pizza) is a variety of pizza in Italian cuisine that is topped with a combination of four kinds of cheese, usually melted together, with (rossa, red) or without (bianca, white) tomato sauce. It is popular worldwide, including in Italy,[1] and is one of the iconic items from pizzerias's menus.",
254
+ "price": float32(1.1),
255
+ "best_before": "2022-05-03T12:04:40+02:00",
256
+ }).
257
+ WithTenant("nonExistentTenant").
258
+ Do(context.Background())
259
+
260
+ require.NotNil(t, err)
261
+ clientErr := err.(*fault.WeaviateClientError)
262
+ assert.Equal(t, 422, clientErr.StatusCode)
263
+ assert.Contains(t, clientErr.Msg, "has multi-tenancy disabled, but request was with tenant")
264
+ require.Nil(t, wrap)
265
+
266
+ wrap, err = client.Data().Creator().
267
+ WithClassName(className).
268
+ WithID(fixtures.PIZZA_FRUTTI_DI_MARE_ID).
269
+ WithProperties(map[string]interface{}{
270
+ "name": "Frutti di Mare",
271
+ "description": "Frutti di Mare is an Italian type of pizza that may be served with scampi, mussels or squid. It typically lacks cheese, with the seafood being served atop a tomato sauce.",
272
+ "price": float32(1.2),
273
+ "best_before": "2022-05-05T07:16:30+02:00",
274
+ }).
275
+ WithTenant("nonExistentTenant").
276
+ Do(context.Background())
277
+
278
+ require.NotNil(t, err)
279
+ clientErr = err.(*fault.WeaviateClientError)
280
+ assert.Equal(t, 422, clientErr.StatusCode)
281
+ assert.Contains(t, clientErr.Msg, "has multi-tenancy disabled, but request was with tenant")
282
+ require.Nil(t, wrap)
283
+
284
+ t.Run("verify not created", func(t *testing.T) {
285
+ objects, err := client.Data().ObjectsGetter().
286
+ Do(context.Background())
287
+
288
+ require.Nil(t, err)
289
+ require.NotNil(t, objects)
290
+ assert.Len(t, objects, 0)
291
+ })
292
+ })
293
+
294
+ t.Run("gets objects of MT class", func(t *testing.T) {
295
+ defer cleanup()
296
+
297
+ tenants := fixtures.Tenants{
298
+ {Name: "tenantNo1"},
299
+ {Name: "tenantNo2"},
300
+ }
301
+
302
+ fixtures.CreateSchemaFoodForTenants(t, client)
303
+ fixtures.CreateTenantsFood(t, client, tenants...)
304
+ fixtures.CreateDataFoodForTenants(t, client, tenants.Names()...)
305
+
306
+ extractIds := func(objs []*models.Object) []string {
307
+ ids := make([]string, len(objs))
308
+ for i, obj := range objs {
309
+ ids[i] = obj.ID.String()
310
+ }
311
+ return ids
312
+ }
313
+
314
+ for _, tenant := range tenants {
315
+ for className, ids := range fixtures.IdsByClass {
316
+ for _, id := range ids {
317
+ t.Run("single object by class+id", func(t *testing.T) {
318
+ objects, err := client.Data().ObjectsGetter().
319
+ WithID(id).
320
+ WithClassName(className).
321
+ WithTenant(tenant.Name).
322
+ Do(context.Background())
323
+
324
+ require.Nil(t, err)
325
+ require.NotNil(t, objects)
326
+ require.Len(t, objects, 1)
327
+ assert.Equal(t, strfmt.UUID(id), objects[0].ID)
328
+ assert.Equal(t, tenant.Name, objects[0].Tenant)
329
+ })
330
+ }
331
+
332
+ t.Run("list objects by class", func(t *testing.T) {
333
+ objects, err := client.Data().ObjectsGetter().
334
+ WithClassName(className).
335
+ WithTenant(tenant.Name).
336
+ Do(context.Background())
337
+
338
+ require.Nil(t, err)
339
+ require.NotNil(t, objects)
340
+ require.Len(t, objects, len(ids))
341
+ assert.ElementsMatch(t, ids, extractIds(objects))
342
+ })
343
+ }
344
+
345
+ t.Run("list all objects", func(t *testing.T) {
346
+ objects, err := client.Data().ObjectsGetter().
347
+ WithTenant(tenant.Name).
348
+ Do(context.Background())
349
+
350
+ require.Nil(t, err)
351
+ require.NotNil(t, objects)
352
+ require.Len(t, objects, len(fixtures.AllIds))
353
+ assert.ElementsMatch(t, fixtures.AllIds, extractIds(objects))
354
+ })
355
+ }
356
+ })
357
+
358
+ t.Run("fails getting objects of MT class without tenant", func(t *testing.T) {
359
+ defer cleanup()
360
+
361
+ tenants := fixtures.Tenants{
362
+ {Name: "tenantNo1"},
363
+ {Name: "tenantNo2"},
364
+ }
365
+
366
+ fixtures.CreateSchemaFoodForTenants(t, client)
367
+ fixtures.CreateTenantsFood(t, client, tenants...)
368
+ fixtures.CreateDataFoodForTenants(t, client, tenants.Names()...)
369
+
370
+ for className, ids := range fixtures.IdsByClass {
371
+ for _, id := range ids {
372
+ t.Run("single object by class+id", func(t *testing.T) {
373
+ objects, err := client.Data().ObjectsGetter().
374
+ WithID(id).
375
+ WithClassName(className).
376
+ Do(context.Background())
377
+
378
+ require.NotNil(t, err)
379
+ clientErr := err.(*fault.WeaviateClientError)
380
+ assert.Equal(t, 422, clientErr.StatusCode)
381
+ assert.Contains(t, clientErr.Msg, "has multi-tenancy enabled, but request was without tenant")
382
+ assert.Nil(t, objects)
383
+ })
384
+ }
385
+
386
+ t.Run("list objects by class", func(t *testing.T) {
387
+ objects, err := client.Data().ObjectsGetter().
388
+ WithClassName(className).
389
+ Do(context.Background())
390
+
391
+ require.NotNil(t, err)
392
+ clientErr := err.(*fault.WeaviateClientError)
393
+ assert.Equal(t, 422, clientErr.StatusCode)
394
+ assert.Contains(t, clientErr.Msg, "has multi-tenancy enabled, but request was without tenant")
395
+ assert.Nil(t, objects)
396
+ })
397
+ }
398
+
399
+ t.Run("list all objects", func(t *testing.T) {
400
+ objects, err := client.Data().ObjectsGetter().
401
+ Do(context.Background())
402
+
403
+ require.Nil(t, err)
404
+ require.NotNil(t, objects)
405
+ assert.Len(t, objects, 0)
406
+ })
407
+ })
408
+
409
+ t.Run("fails getting objects of MT class with non existent tenant", func(t *testing.T) {
410
+ defer cleanup()
411
+
412
+ tenants := fixtures.Tenants{
413
+ {Name: "tenantNo1"},
414
+ {Name: "tenantNo2"},
415
+ }
416
+
417
+ fixtures.CreateSchemaFoodForTenants(t, client)
418
+ fixtures.CreateTenantsFood(t, client, tenants...)
419
+ fixtures.CreateDataFoodForTenants(t, client, tenants.Names()...)
420
+
421
+ for className, ids := range fixtures.IdsByClass {
422
+ for _, id := range ids {
423
+ t.Run("single object by class+id", func(t *testing.T) {
424
+ objects, err := client.Data().ObjectsGetter().
425
+ WithID(id).
426
+ WithClassName(className).
427
+ WithTenant("nonExistentTenant").
428
+ Do(context.Background())
429
+
430
+ require.NotNil(t, err)
431
+ clientErr := err.(*fault.WeaviateClientError)
432
+ assert.Equal(t, 422, clientErr.StatusCode)
433
+ assert.Contains(t, clientErr.Msg, "tenant not found")
434
+ assert.Nil(t, objects)
435
+ })
436
+ }
437
+
438
+ t.Run("list objects by class", func(t *testing.T) {
439
+ objects, err := client.Data().ObjectsGetter().
440
+ WithClassName(className).
441
+ WithTenant("nonExistentTenant").
442
+ Do(context.Background())
443
+
444
+ require.NotNil(t, err)
445
+ clientErr := err.(*fault.WeaviateClientError)
446
+ assert.Equal(t, 422, clientErr.StatusCode)
447
+ assert.Contains(t, clientErr.Msg, "tenant not found")
448
+ assert.Nil(t, objects)
449
+ })
450
+ }
451
+
452
+ t.Run("list all objects", func(t *testing.T) {
453
+ objects, err := client.Data().ObjectsGetter().
454
+ WithTenant("nonExistentTenant").
455
+ Do(context.Background())
456
+
457
+ require.Nil(t, err)
458
+ require.NotNil(t, objects)
459
+ assert.Len(t, objects, 0)
460
+ })
461
+ })
462
+
463
+ t.Run("fails getting objects of non-MT class when tenant given", func(t *testing.T) {
464
+ defer cleanup()
465
+
466
+ fixtures.CreateSchemaFood(t, client)
467
+ fixtures.CreateDataFood(t, client)
468
+
469
+ for className, ids := range fixtures.IdsByClass {
470
+ for _, id := range ids {
471
+ t.Run("single object by class+id", func(t *testing.T) {
472
+ objects, err := client.Data().ObjectsGetter().
473
+ WithID(id).
474
+ WithClassName(className).
475
+ WithTenant("nonExistentTenant").
476
+ Do(context.Background())
477
+
478
+ require.NotNil(t, err)
479
+ clientErr := err.(*fault.WeaviateClientError)
480
+ assert.Equal(t, 422, clientErr.StatusCode)
481
+ assert.Contains(t, clientErr.Msg, "has multi-tenancy disabled, but request was with tenant")
482
+ require.Nil(t, objects)
483
+ })
484
+ }
485
+
486
+ t.Run("list objects by class", func(t *testing.T) {
487
+ objects, err := client.Data().ObjectsGetter().
488
+ WithClassName(className).
489
+ WithTenant("nonExistentTenant").
490
+ Do(context.Background())
491
+
492
+ require.NotNil(t, err)
493
+ clientErr := err.(*fault.WeaviateClientError)
494
+ assert.Equal(t, 422, clientErr.StatusCode)
495
+ assert.Contains(t, clientErr.Msg, "has multi-tenancy disabled, but request was with tenant")
496
+ require.Nil(t, objects)
497
+ })
498
+ }
499
+
500
+ t.Run("list all objects", func(t *testing.T) {
501
+ objects, err := client.Data().ObjectsGetter().
502
+ WithTenant("nonExistentTenant").
503
+ Do(context.Background())
504
+
505
+ require.Nil(t, err)
506
+ require.NotNil(t, objects)
507
+ assert.Len(t, objects, 0)
508
+ })
509
+ })
510
+
511
+ t.Run("checks objects of MT class", func(t *testing.T) {
512
+ defer cleanup()
513
+
514
+ tenants := fixtures.Tenants{
515
+ {Name: "tenantNo1"},
516
+ {Name: "tenantNo2"},
517
+ }
518
+
519
+ fixtures.CreateSchemaFoodForTenants(t, client)
520
+ fixtures.CreateTenantsFood(t, client, tenants...)
521
+ fixtures.CreateDataFoodForTenants(t, client, tenants.Names()...)
522
+
523
+ for _, tenant := range tenants {
524
+ for className, ids := range fixtures.IdsByClass {
525
+ for _, id := range ids {
526
+ exists, err := client.Data().Checker().
527
+ WithID(id).
528
+ WithClassName(className).
529
+ WithTenant(tenant.Name).
530
+ Do(context.Background())
531
+
532
+ require.Nil(t, err)
533
+ require.True(t, exists)
534
+ }
535
+ }
536
+ }
537
+ })
538
+
539
+ t.Run("fails checking objects of MT class without tenant", func(t *testing.T) {
540
+ defer cleanup()
541
+
542
+ tenants := fixtures.Tenants{
543
+ {Name: "tenantNo1"},
544
+ {Name: "tenantNo2"},
545
+ }
546
+
547
+ fixtures.CreateSchemaFoodForTenants(t, client)
548
+ fixtures.CreateTenantsFood(t, client, tenants...)
549
+ fixtures.CreateDataFoodForTenants(t, client, tenants.Names()...)
550
+
551
+ for className, ids := range fixtures.IdsByClass {
552
+ for _, id := range ids {
553
+ exists, err := client.Data().Checker().
554
+ WithID(id).
555
+ WithClassName(className).
556
+ Do(context.Background())
557
+
558
+ require.NotNil(t, err)
559
+ clientErr := err.(*fault.WeaviateClientError)
560
+ assert.Equal(t, 422, clientErr.StatusCode)
561
+ assert.Empty(t, clientErr.Msg) // no body in HEAD
562
+ assert.False(t, exists)
563
+ }
564
+ }
565
+ })
566
+
567
+ t.Run("fails checking objects of MT class with non existent tenant", func(t *testing.T) {
568
+ defer cleanup()
569
+
570
+ tenants := fixtures.Tenants{
571
+ {Name: "tenantNo1"},
572
+ {Name: "tenantNo2"},
573
+ }
574
+
575
+ fixtures.CreateSchemaFoodForTenants(t, client)
576
+ fixtures.CreateTenantsFood(t, client, tenants...)
577
+ fixtures.CreateDataFoodForTenants(t, client, tenants.Names()...)
578
+
579
+ for className, ids := range fixtures.IdsByClass {
580
+ for _, id := range ids {
581
+ exists, err := client.Data().Checker().
582
+ WithID(id).
583
+ WithClassName(className).
584
+ WithTenant("nonExistentTenant").
585
+ Do(context.Background())
586
+
587
+ require.NotNil(t, err)
588
+ clientErr := err.(*fault.WeaviateClientError)
589
+ assert.Equal(t, 422, clientErr.StatusCode)
590
+ assert.Empty(t, clientErr.Msg) // no body in HEAD
591
+ assert.False(t, exists)
592
+ }
593
+ }
594
+ })
595
+
596
+ t.Run("fails checking objects of non-MT class when tenant given", func(t *testing.T) {
597
+ defer cleanup()
598
+
599
+ fixtures.CreateSchemaFood(t, client)
600
+ fixtures.CreateDataFood(t, client)
601
+
602
+ for className, ids := range fixtures.IdsByClass {
603
+ for _, id := range ids {
604
+ exists, err := client.Data().Checker().
605
+ WithID(id).
606
+ WithClassName(className).
607
+ WithTenant("nonExistentTenant").
608
+ Do(context.Background())
609
+
610
+ require.NotNil(t, err)
611
+ clientErr := err.(*fault.WeaviateClientError)
612
+ assert.Equal(t, 422, clientErr.StatusCode)
613
+ assert.Empty(t, clientErr.Msg) // no body in HEAD
614
+ require.False(t, exists)
615
+ }
616
+ }
617
+ })
618
+
619
+ t.Run("deletes objects from MT class", func(t *testing.T) {
620
+ defer cleanup()
621
+
622
+ tenants := fixtures.Tenants{
623
+ {Name: "tenantNo1"},
624
+ {Name: "tenantNo2"},
625
+ }
626
+
627
+ fixtures.CreateSchemaFoodForTenants(t, client)
628
+ fixtures.CreateTenantsFood(t, client, tenants...)
629
+ fixtures.CreateDataFoodForTenants(t, client, tenants.Names()...)
630
+
631
+ for _, tenant := range tenants {
632
+ for className, ids := range fixtures.IdsByClass {
633
+ expectedLeft := len(ids)
634
+
635
+ for _, id := range ids {
636
+ err := client.Data().Deleter().
637
+ WithID(id).
638
+ WithClassName(className).
639
+ WithTenant(tenant.Name).
640
+ Do(context.Background())
641
+
642
+ require.Nil(t, err)
643
+ expectedLeft--
644
+
645
+ t.Run("verify deleted", func(t *testing.T) {
646
+ exists, err := client.Data().Checker().
647
+ WithID(id).
648
+ WithClassName(className).
649
+ WithTenant(tenant.Name).
650
+ Do(context.Background())
651
+
652
+ require.Nil(t, err)
653
+ require.False(t, exists)
654
+ })
655
+
656
+ t.Run("verify left", func(t *testing.T) {
657
+ objects, err := client.Data().ObjectsGetter().
658
+ WithClassName(className).
659
+ WithTenant(tenant.Name).
660
+ Do(context.Background())
661
+
662
+ require.Nil(t, err)
663
+ require.NotNil(t, objects)
664
+ assert.Len(t, objects, expectedLeft)
665
+ })
666
+ }
667
+ }
668
+ }
669
+ })
670
+
671
+ t.Run("fails deleting objects from MT class without tenant", func(t *testing.T) {
672
+ defer cleanup()
673
+
674
+ tenants := fixtures.Tenants{
675
+ {Name: "tenantNo1"},
676
+ {Name: "tenantNo2"},
677
+ }
678
+
679
+ fixtures.CreateSchemaFoodForTenants(t, client)
680
+ fixtures.CreateTenantsFood(t, client, tenants...)
681
+ fixtures.CreateDataFoodForTenants(t, client, tenants.Names()...)
682
+
683
+ for className, ids := range fixtures.IdsByClass {
684
+ for _, id := range ids {
685
+ err := client.Data().Deleter().
686
+ WithID(id).
687
+ WithClassName(className).
688
+ Do(context.Background())
689
+
690
+ require.NotNil(t, err)
691
+ clientErr := err.(*fault.WeaviateClientError)
692
+ assert.Equal(t, 422, clientErr.StatusCode)
693
+ assert.Contains(t, clientErr.Msg, "has multi-tenancy enabled, but request was without tenant")
694
+
695
+ t.Run("verify not deleted", func(t *testing.T) {
696
+ for _, tenant := range tenants {
697
+ exists, err := client.Data().Checker().
698
+ WithID(id).
699
+ WithClassName(className).
700
+ WithTenant(tenant.Name).
701
+ Do(context.Background())
702
+
703
+ require.Nil(t, err)
704
+ require.True(t, exists)
705
+ }
706
+ })
707
+ }
708
+ }
709
+
710
+ t.Run("verify not deleted", func(t *testing.T) {
711
+ for _, tenant := range tenants {
712
+ objects, err := client.Data().ObjectsGetter().
713
+ WithTenant(tenant.Name).
714
+ Do(context.Background())
715
+
716
+ require.Nil(t, err)
717
+ require.NotNil(t, objects)
718
+ assert.Len(t, objects, len(fixtures.AllIds))
719
+ }
720
+ })
721
+ })
722
+
723
+ t.Run("fails deleting objects from MT class with non existent tenant", func(t *testing.T) {
724
+ defer cleanup()
725
+
726
+ tenants := fixtures.Tenants{
727
+ {Name: "tenantNo1"},
728
+ {Name: "tenantNo2"},
729
+ }
730
+
731
+ fixtures.CreateSchemaFoodForTenants(t, client)
732
+ fixtures.CreateTenantsFood(t, client, tenants...)
733
+ fixtures.CreateDataFoodForTenants(t, client, tenants.Names()...)
734
+
735
+ for className, ids := range fixtures.IdsByClass {
736
+ for _, id := range ids {
737
+ err := client.Data().Deleter().
738
+ WithID(id).
739
+ WithClassName(className).
740
+ WithTenant("nonExistentTenant").
741
+ Do(context.Background())
742
+
743
+ require.NotNil(t, err)
744
+ clientErr := err.(*fault.WeaviateClientError)
745
+ assert.Equal(t, 422, clientErr.StatusCode)
746
+ assert.Contains(t, clientErr.Msg, "tenant not found")
747
+
748
+ t.Run("verify not deleted", func(t *testing.T) {
749
+ for _, tenant := range tenants {
750
+ exists, err := client.Data().Checker().
751
+ WithID(id).
752
+ WithClassName(className).
753
+ WithTenant(tenant.Name).
754
+ Do(context.Background())
755
+
756
+ require.Nil(t, err)
757
+ require.True(t, exists)
758
+ }
759
+ })
760
+ }
761
+ }
762
+
763
+ t.Run("verify not deleted", func(t *testing.T) {
764
+ for _, tenant := range tenants {
765
+ objects, err := client.Data().ObjectsGetter().
766
+ WithTenant(tenant.Name).
767
+ Do(context.Background())
768
+
769
+ require.Nil(t, err)
770
+ require.NotNil(t, objects)
771
+ assert.Len(t, objects, len(fixtures.AllIds))
772
+ }
773
+ })
774
+ })
775
+
776
+ t.Run("fails deleting objects from non-MT class when tenant given", func(t *testing.T) {
777
+ defer cleanup()
778
+
779
+ fixtures.CreateSchemaFood(t, client)
780
+ fixtures.CreateDataFood(t, client)
781
+
782
+ for className, ids := range fixtures.IdsByClass {
783
+ for _, id := range ids {
784
+ err := client.Data().Deleter().
785
+ WithID(id).
786
+ WithClassName(className).
787
+ WithTenant("nonExistentTenant").
788
+ Do(context.Background())
789
+
790
+ require.NotNil(t, err)
791
+ clientErr := err.(*fault.WeaviateClientError)
792
+ assert.Equal(t, 422, clientErr.StatusCode)
793
+ assert.Contains(t, clientErr.Msg, "has multi-tenancy disabled, but request was with tenant")
794
+
795
+ t.Run("verify not deleted", func(t *testing.T) {
796
+ exists, err := client.Data().Checker().
797
+ WithID(id).
798
+ WithClassName(className).
799
+ Do(context.Background())
800
+
801
+ require.Nil(t, err)
802
+ require.True(t, exists)
803
+ })
804
+ }
805
+ }
806
+
807
+ t.Run("verify not deleted", func(t *testing.T) {
808
+ objects, err := client.Data().ObjectsGetter().
809
+ Do(context.Background())
810
+
811
+ require.Nil(t, err)
812
+ require.NotNil(t, objects)
813
+ assert.Len(t, objects, len(fixtures.AllIds))
814
+ })
815
+ })
816
+
817
+ t.Run("updates objects of MT class", func(t *testing.T) {
818
+ defer cleanup()
819
+
820
+ className := "Soup"
821
+ tenants := fixtures.Tenants{
822
+ {Name: "tenantNo1"},
823
+ {Name: "tenantNo2"},
824
+ }
825
+
826
+ fixtures.CreateSchemaSoupForTenants(t, client)
827
+ fixtures.CreateTenantsSoup(t, client, tenants...)
828
+ fixtures.CreateDataSoupForTenants(t, client, tenants.Names()...)
829
+
830
+ for _, tenant := range tenants {
831
+ err := client.Data().Updater().
832
+ WithClassName(className).
833
+ WithID(fixtures.SOUP_CHICKENSOUP_ID).
834
+ WithProperties(map[string]interface{}{
835
+ "name": "ChickenSoup",
836
+ "description": fmt.Sprintf("updated ChickenSoup description [%s]", tenant),
837
+ "price": float32(2.1),
838
+ }).
839
+ WithTenant(tenant.Name).
840
+ Do(context.Background())
841
+
842
+ require.Nil(t, err)
843
+
844
+ err = client.Data().Updater().
845
+ WithClassName(className).
846
+ WithID(fixtures.SOUP_BEAUTIFUL_ID).
847
+ WithProperties(map[string]interface{}{
848
+ "name": "Beautiful",
849
+ "description": fmt.Sprintf("updated Beautiful description [%s]", tenant),
850
+ "price": float32(2.2),
851
+ }).
852
+ WithTenant(tenant.Name).
853
+ Do(context.Background())
854
+
855
+ require.Nil(t, err)
856
+ }
857
+
858
+ t.Run("verify updated", func(t *testing.T) {
859
+ for _, tenant := range tenants {
860
+ objects, err := client.Data().ObjectsGetter().
861
+ WithID(fixtures.SOUP_CHICKENSOUP_ID).
862
+ WithClassName(className).
863
+ WithTenant(tenant.Name).
864
+ Do(context.Background())
865
+
866
+ require.Nil(t, err)
867
+ require.NotNil(t, objects)
868
+ require.Len(t, objects, 1)
869
+ assert.Equal(t, tenant.Name, objects[0].Tenant)
870
+ assert.Equal(t, fmt.Sprintf("updated ChickenSoup description [%s]", tenant),
871
+ objects[0].Properties.(map[string]interface{})["description"])
872
+
873
+ objects, err = client.Data().ObjectsGetter().
874
+ WithID(fixtures.SOUP_BEAUTIFUL_ID).
875
+ WithClassName(className).
876
+ WithTenant(tenant.Name).
877
+ Do(context.Background())
878
+
879
+ require.Nil(t, err)
880
+ require.NotNil(t, objects)
881
+ require.Len(t, objects, 1)
882
+ assert.Equal(t, tenant.Name, objects[0].Tenant)
883
+ assert.Equal(t, fmt.Sprintf("updated Beautiful description [%s]", tenant),
884
+ objects[0].Properties.(map[string]interface{})["description"])
885
+ }
886
+ })
887
+ })
888
+
889
+ t.Run("fails updating objects of MT class without tenant", func(t *testing.T) {
890
+ defer cleanup()
891
+
892
+ className := "Soup"
893
+ tenants := fixtures.Tenants{
894
+ {Name: "tenantNo1"},
895
+ {Name: "tenantNo2"},
896
+ }
897
+
898
+ fixtures.CreateSchemaSoupForTenants(t, client)
899
+ fixtures.CreateTenantsSoup(t, client, tenants...)
900
+ fixtures.CreateDataSoupForTenants(t, client, tenants.Names()...)
901
+
902
+ err := client.Data().Updater().
903
+ WithClassName(className).
904
+ WithID(fixtures.SOUP_CHICKENSOUP_ID).
905
+ WithProperties(map[string]interface{}{
906
+ "name": "ChickenSoup",
907
+ "description": "updated ChickenSoup description",
908
+ "price": float32(2.1),
909
+ }).
910
+ Do(context.Background())
911
+
912
+ require.NotNil(t, err)
913
+ clientErr := err.(*fault.WeaviateClientError)
914
+ assert.Equal(t, 422, clientErr.StatusCode)
915
+ assert.Contains(t, clientErr.Msg, "has multi-tenancy enabled, but request was without tenant")
916
+
917
+ err = client.Data().Updater().
918
+ WithClassName(className).
919
+ WithID(fixtures.SOUP_BEAUTIFUL_ID).
920
+ WithProperties(map[string]interface{}{
921
+ "name": "Beautiful",
922
+ "description": "updated Beautiful description",
923
+ "price": float32(2.2),
924
+ }).
925
+ Do(context.Background())
926
+
927
+ require.NotNil(t, err)
928
+ clientErr = err.(*fault.WeaviateClientError)
929
+ assert.Equal(t, 422, clientErr.StatusCode)
930
+ assert.Contains(t, clientErr.Msg, "has multi-tenancy enabled, but request was without tenant")
931
+
932
+ t.Run("verify not updated", func(t *testing.T) {
933
+ for _, tenant := range tenants {
934
+ objects, err := client.Data().ObjectsGetter().
935
+ WithID(fixtures.SOUP_CHICKENSOUP_ID).
936
+ WithClassName(className).
937
+ WithTenant(tenant.Name).
938
+ Do(context.Background())
939
+
940
+ require.Nil(t, err)
941
+ require.NotNil(t, objects)
942
+ require.Len(t, objects, 1)
943
+ assert.Equal(t, tenant.Name, objects[0].Tenant)
944
+ assert.Equal(t, "Used by humans when their inferior genetics are attacked by microscopic organisms.",
945
+ objects[0].Properties.(map[string]interface{})["description"])
946
+
947
+ objects, err = client.Data().ObjectsGetter().
948
+ WithID(fixtures.SOUP_BEAUTIFUL_ID).
949
+ WithClassName(className).
950
+ WithTenant(tenant.Name).
951
+ Do(context.Background())
952
+
953
+ require.Nil(t, err)
954
+ require.NotNil(t, objects)
955
+ require.Len(t, objects, 1)
956
+ assert.Equal(t, tenant.Name, objects[0].Tenant)
957
+ assert.Equal(t, "Putting the game of letter soups to a whole new level.",
958
+ objects[0].Properties.(map[string]interface{})["description"])
959
+ }
960
+ })
961
+ })
962
+
963
+ t.Run("fails updating objects of MT class with non existent tenant", func(t *testing.T) {
964
+ defer cleanup()
965
+
966
+ className := "Soup"
967
+ tenants := fixtures.Tenants{
968
+ {Name: "tenantNo1"},
969
+ {Name: "tenantNo2"},
970
+ }
971
+
972
+ fixtures.CreateSchemaSoupForTenants(t, client)
973
+ fixtures.CreateTenantsSoup(t, client, tenants...)
974
+ fixtures.CreateDataSoupForTenants(t, client, tenants.Names()...)
975
+
976
+ err := client.Data().Updater().
977
+ WithClassName(className).
978
+ WithID(fixtures.SOUP_CHICKENSOUP_ID).
979
+ WithProperties(map[string]interface{}{
980
+ "name": "ChickenSoup",
981
+ "description": "updated ChickenSoup description",
982
+ "price": float32(2.1),
983
+ }).
984
+ WithTenant("nonExistentTenant").
985
+ Do(context.Background())
986
+
987
+ require.NotNil(t, err)
988
+ clientErr := err.(*fault.WeaviateClientError)
989
+ assert.Equal(t, 422, clientErr.StatusCode)
990
+ assert.Contains(t, clientErr.Msg, "tenant not found")
991
+
992
+ err = client.Data().Updater().
993
+ WithClassName(className).
994
+ WithID(fixtures.SOUP_BEAUTIFUL_ID).
995
+ WithProperties(map[string]interface{}{
996
+ "name": "Beautiful",
997
+ "description": "updated Beautiful description",
998
+ "price": float32(2.2),
999
+ }).
1000
+ WithTenant("nonExistentTenant").
1001
+ Do(context.Background())
1002
+
1003
+ require.NotNil(t, err)
1004
+ clientErr = err.(*fault.WeaviateClientError)
1005
+ assert.Equal(t, 422, clientErr.StatusCode)
1006
+ assert.Contains(t, clientErr.Msg, "tenant not found")
1007
+
1008
+ t.Run("verify not updated", func(t *testing.T) {
1009
+ for _, tenant := range tenants {
1010
+ objects, err := client.Data().ObjectsGetter().
1011
+ WithID(fixtures.SOUP_CHICKENSOUP_ID).
1012
+ WithClassName(className).
1013
+ WithTenant(tenant.Name).
1014
+ Do(context.Background())
1015
+
1016
+ require.Nil(t, err)
1017
+ require.NotNil(t, objects)
1018
+ require.Len(t, objects, 1)
1019
+ assert.Equal(t, tenant.Name, objects[0].Tenant)
1020
+ assert.Equal(t, "Used by humans when their inferior genetics are attacked by microscopic organisms.",
1021
+ objects[0].Properties.(map[string]interface{})["description"])
1022
+
1023
+ objects, err = client.Data().ObjectsGetter().
1024
+ WithID(fixtures.SOUP_BEAUTIFUL_ID).
1025
+ WithClassName(className).
1026
+ WithTenant(tenant.Name).
1027
+ Do(context.Background())
1028
+
1029
+ require.Nil(t, err)
1030
+ require.NotNil(t, objects)
1031
+ require.Len(t, objects, 1)
1032
+ assert.Equal(t, tenant.Name, objects[0].Tenant)
1033
+ assert.Equal(t, "Putting the game of letter soups to a whole new level.",
1034
+ objects[0].Properties.(map[string]interface{})["description"])
1035
+ }
1036
+ })
1037
+ })
1038
+
1039
+ t.Run("fails updating objects of non-MT class when tenant given", func(t *testing.T) {
1040
+ defer cleanup()
1041
+
1042
+ className := "Soup"
1043
+
1044
+ fixtures.CreateSchemaSoup(t, client)
1045
+ fixtures.CreateDataSoup(t, client)
1046
+
1047
+ err := client.Data().Updater().
1048
+ WithClassName(className).
1049
+ WithID(fixtures.SOUP_CHICKENSOUP_ID).
1050
+ WithProperties(map[string]interface{}{
1051
+ "name": "ChickenSoup",
1052
+ "description": "updated ChickenSoup description",
1053
+ "price": float32(2.1),
1054
+ }).
1055
+ WithTenant("nonExistentTenant").
1056
+ Do(context.Background())
1057
+
1058
+ require.NotNil(t, err)
1059
+ clientErr := err.(*fault.WeaviateClientError)
1060
+ assert.Equal(t, 422, clientErr.StatusCode)
1061
+ assert.Contains(t, clientErr.Msg, "has multi-tenancy disabled, but request was with tenant")
1062
+
1063
+ err = client.Data().Updater().
1064
+ WithClassName(className).
1065
+ WithID(fixtures.SOUP_BEAUTIFUL_ID).
1066
+ WithProperties(map[string]interface{}{
1067
+ "name": "Beautiful",
1068
+ "description": "updated Beautiful description",
1069
+ "price": float32(2.2),
1070
+ }).
1071
+ WithTenant("nonExistentTenant").
1072
+ Do(context.Background())
1073
+
1074
+ require.NotNil(t, err)
1075
+ clientErr = err.(*fault.WeaviateClientError)
1076
+ assert.Equal(t, 422, clientErr.StatusCode)
1077
+ assert.Contains(t, clientErr.Msg, "has multi-tenancy disabled, but request was with tenant")
1078
+
1079
+ t.Run("verify not updated", func(t *testing.T) {
1080
+ objects, err := client.Data().ObjectsGetter().
1081
+ WithID(fixtures.SOUP_CHICKENSOUP_ID).
1082
+ WithClassName(className).
1083
+ Do(context.Background())
1084
+
1085
+ require.Nil(t, err)
1086
+ require.NotNil(t, objects)
1087
+ require.Len(t, objects, 1)
1088
+ assert.Equal(t, "Used by humans when their inferior genetics are attacked by microscopic organisms.",
1089
+ objects[0].Properties.(map[string]interface{})["description"])
1090
+
1091
+ objects, err = client.Data().ObjectsGetter().
1092
+ WithID(fixtures.SOUP_BEAUTIFUL_ID).
1093
+ WithClassName(className).
1094
+ Do(context.Background())
1095
+
1096
+ require.Nil(t, err)
1097
+ require.NotNil(t, objects)
1098
+ require.Len(t, objects, 1)
1099
+ assert.Equal(t, "Putting the game of letter soups to a whole new level.",
1100
+ objects[0].Properties.(map[string]interface{})["description"])
1101
+ })
1102
+ })
1103
+
1104
+ t.Run("merges objects of MT class", func(t *testing.T) {
1105
+ defer cleanup()
1106
+
1107
+ className := "Soup"
1108
+ tenants := fixtures.Tenants{
1109
+ {Name: "tenantNo1"},
1110
+ {Name: "tenantNo2"},
1111
+ }
1112
+
1113
+ fixtures.CreateSchemaSoupForTenants(t, client)
1114
+ fixtures.CreateTenantsSoup(t, client, tenants...)
1115
+ fixtures.CreateDataSoupForTenants(t, client, tenants.Names()...)
1116
+
1117
+ for _, tenant := range tenants {
1118
+ err := client.Data().Updater().
1119
+ WithClassName(className).
1120
+ WithID(fixtures.SOUP_CHICKENSOUP_ID).
1121
+ WithProperties(map[string]interface{}{
1122
+ "description": fmt.Sprintf("merged ChickenSoup description [%s]", tenant),
1123
+ }).
1124
+ WithTenant(tenant.Name).
1125
+ WithMerge().
1126
+ Do(context.Background())
1127
+
1128
+ require.Nil(t, err)
1129
+
1130
+ err = client.Data().Updater().
1131
+ WithClassName(className).
1132
+ WithID(fixtures.SOUP_BEAUTIFUL_ID).
1133
+ WithProperties(map[string]interface{}{
1134
+ "description": fmt.Sprintf("merged Beautiful description [%s]", tenant),
1135
+ }).
1136
+ WithTenant(tenant.Name).
1137
+ WithMerge().
1138
+ Do(context.Background())
1139
+
1140
+ require.Nil(t, err)
1141
+ }
1142
+
1143
+ t.Run("verify merged", func(t *testing.T) {
1144
+ for _, tenant := range tenants {
1145
+ objects, err := client.Data().ObjectsGetter().
1146
+ WithID(fixtures.SOUP_CHICKENSOUP_ID).
1147
+ WithClassName(className).
1148
+ WithTenant(tenant.Name).
1149
+ Do(context.Background())
1150
+
1151
+ require.Nil(t, err)
1152
+ require.NotNil(t, objects)
1153
+ require.Len(t, objects, 1)
1154
+ assert.Equal(t, tenant.Name, objects[0].Tenant)
1155
+ assert.Equal(t, fmt.Sprintf("merged ChickenSoup description [%s]", tenant),
1156
+ objects[0].Properties.(map[string]interface{})["description"])
1157
+
1158
+ objects, err = client.Data().ObjectsGetter().
1159
+ WithID(fixtures.SOUP_BEAUTIFUL_ID).
1160
+ WithClassName(className).
1161
+ WithTenant(tenant.Name).
1162
+ Do(context.Background())
1163
+
1164
+ require.Nil(t, err)
1165
+ require.NotNil(t, objects)
1166
+ require.Len(t, objects, 1)
1167
+ assert.Equal(t, tenant.Name, objects[0].Tenant)
1168
+ assert.Equal(t, fmt.Sprintf("merged Beautiful description [%s]", tenant),
1169
+ objects[0].Properties.(map[string]interface{})["description"])
1170
+ }
1171
+ })
1172
+ })
1173
+
1174
+ t.Run("fails merging objects of MT class without tenant", func(t *testing.T) {
1175
+ defer cleanup()
1176
+
1177
+ className := "Soup"
1178
+ tenants := fixtures.Tenants{
1179
+ {Name: "tenantNo1"},
1180
+ {Name: "tenantNo2"},
1181
+ }
1182
+
1183
+ fixtures.CreateSchemaSoupForTenants(t, client)
1184
+ fixtures.CreateTenantsSoup(t, client, tenants...)
1185
+ fixtures.CreateDataSoupForTenants(t, client, tenants.Names()...)
1186
+
1187
+ err := client.Data().Updater().
1188
+ WithClassName(className).
1189
+ WithID(fixtures.SOUP_CHICKENSOUP_ID).
1190
+ WithProperties(map[string]interface{}{
1191
+ "description": "merged ChickenSoup description",
1192
+ }).
1193
+ WithMerge().
1194
+ Do(context.Background())
1195
+
1196
+ require.NotNil(t, err)
1197
+ clientErr := err.(*fault.WeaviateClientError)
1198
+ assert.Equal(t, 422, clientErr.StatusCode)
1199
+ assert.Contains(t, clientErr.Msg, "has multi-tenancy enabled, but request was without tenant")
1200
+
1201
+ err = client.Data().Updater().
1202
+ WithClassName(className).
1203
+ WithID(fixtures.SOUP_BEAUTIFUL_ID).
1204
+ WithProperties(map[string]interface{}{
1205
+ "description": "merged Beautiful description",
1206
+ }).
1207
+ WithMerge().
1208
+ Do(context.Background())
1209
+
1210
+ require.NotNil(t, err)
1211
+ clientErr = err.(*fault.WeaviateClientError)
1212
+ assert.Equal(t, 422, clientErr.StatusCode)
1213
+ assert.Contains(t, clientErr.Msg, "has multi-tenancy enabled, but request was without tenant")
1214
+
1215
+ t.Run("verify not merged", func(t *testing.T) {
1216
+ for _, tenant := range tenants {
1217
+ objects, err := client.Data().ObjectsGetter().
1218
+ WithID(fixtures.SOUP_CHICKENSOUP_ID).
1219
+ WithClassName(className).
1220
+ WithTenant(tenant.Name).
1221
+ Do(context.Background())
1222
+
1223
+ require.Nil(t, err)
1224
+ require.NotNil(t, objects)
1225
+ require.Len(t, objects, 1)
1226
+ assert.Equal(t, tenant.Name, objects[0].Tenant)
1227
+ assert.Equal(t, "Used by humans when their inferior genetics are attacked by microscopic organisms.",
1228
+ objects[0].Properties.(map[string]interface{})["description"])
1229
+
1230
+ objects, err = client.Data().ObjectsGetter().
1231
+ WithID(fixtures.SOUP_BEAUTIFUL_ID).
1232
+ WithClassName(className).
1233
+ WithTenant(tenant.Name).
1234
+ Do(context.Background())
1235
+
1236
+ require.Nil(t, err)
1237
+ require.NotNil(t, objects)
1238
+ require.Len(t, objects, 1)
1239
+ assert.Equal(t, tenant.Name, objects[0].Tenant)
1240
+ assert.Equal(t, "Putting the game of letter soups to a whole new level.",
1241
+ objects[0].Properties.(map[string]interface{})["description"])
1242
+ }
1243
+ })
1244
+ })
1245
+
1246
+ t.Run("fails merging objects of MT class with non existent tenant", func(t *testing.T) {
1247
+ defer cleanup()
1248
+
1249
+ className := "Soup"
1250
+ tenants := fixtures.Tenants{
1251
+ {Name: "tenantNo1"},
1252
+ {Name: "tenantNo2"},
1253
+ }
1254
+
1255
+ fixtures.CreateSchemaSoupForTenants(t, client)
1256
+ fixtures.CreateTenantsSoup(t, client, tenants...)
1257
+ fixtures.CreateDataSoupForTenants(t, client, tenants.Names()...)
1258
+
1259
+ err := client.Data().Updater().
1260
+ WithClassName(className).
1261
+ WithID(fixtures.SOUP_CHICKENSOUP_ID).
1262
+ WithProperties(map[string]interface{}{
1263
+ "description": "merged ChickenSoup description",
1264
+ }).
1265
+ WithMerge().
1266
+ WithTenant("nonExistentTenant").
1267
+ Do(context.Background())
1268
+
1269
+ require.NotNil(t, err)
1270
+ clientErr := err.(*fault.WeaviateClientError)
1271
+ assert.Equal(t, 422, clientErr.StatusCode)
1272
+ assert.Contains(t, clientErr.Msg, "tenant not found")
1273
+
1274
+ err = client.Data().Updater().
1275
+ WithClassName(className).
1276
+ WithID(fixtures.SOUP_BEAUTIFUL_ID).
1277
+ WithProperties(map[string]interface{}{
1278
+ "description": "merged Beautiful description",
1279
+ }).
1280
+ WithMerge().
1281
+ WithTenant("nonExistentTenant").
1282
+ Do(context.Background())
1283
+
1284
+ require.NotNil(t, err)
1285
+ clientErr = err.(*fault.WeaviateClientError)
1286
+ assert.Equal(t, 422, clientErr.StatusCode)
1287
+ assert.Contains(t, clientErr.Msg, "tenant not found")
1288
+
1289
+ t.Run("verify not merged", func(t *testing.T) {
1290
+ for _, tenant := range tenants {
1291
+ objects, err := client.Data().ObjectsGetter().
1292
+ WithID(fixtures.SOUP_CHICKENSOUP_ID).
1293
+ WithClassName(className).
1294
+ WithTenant(tenant.Name).
1295
+ Do(context.Background())
1296
+
1297
+ require.Nil(t, err)
1298
+ require.NotNil(t, objects)
1299
+ require.Len(t, objects, 1)
1300
+ assert.Equal(t, tenant.Name, objects[0].Tenant)
1301
+ assert.Equal(t, "Used by humans when their inferior genetics are attacked by microscopic organisms.",
1302
+ objects[0].Properties.(map[string]interface{})["description"])
1303
+
1304
+ objects, err = client.Data().ObjectsGetter().
1305
+ WithID(fixtures.SOUP_BEAUTIFUL_ID).
1306
+ WithClassName(className).
1307
+ WithTenant(tenant.Name).
1308
+ Do(context.Background())
1309
+
1310
+ require.Nil(t, err)
1311
+ require.NotNil(t, objects)
1312
+ require.Len(t, objects, 1)
1313
+ assert.Equal(t, tenant.Name, objects[0].Tenant)
1314
+ assert.Equal(t, "Putting the game of letter soups to a whole new level.",
1315
+ objects[0].Properties.(map[string]interface{})["description"])
1316
+ }
1317
+ })
1318
+ })
1319
+
1320
+ t.Run("fails merging objects of non-MT class when tenant given", func(t *testing.T) {
1321
+ defer cleanup()
1322
+
1323
+ className := "Soup"
1324
+
1325
+ fixtures.CreateSchemaSoup(t, client)
1326
+ fixtures.CreateDataSoup(t, client)
1327
+
1328
+ err := client.Data().Updater().
1329
+ WithClassName(className).
1330
+ WithID(fixtures.SOUP_CHICKENSOUP_ID).
1331
+ WithProperties(map[string]interface{}{
1332
+ "description": "merged ChickenSoup description [%s]",
1333
+ }).
1334
+ WithTenant("nonExistentTenant").
1335
+ WithMerge().
1336
+ Do(context.Background())
1337
+
1338
+ require.NotNil(t, err)
1339
+ clientErr := err.(*fault.WeaviateClientError)
1340
+ assert.Equal(t, 422, clientErr.StatusCode)
1341
+ assert.Contains(t, clientErr.Msg, "has multi-tenancy disabled, but request was with tenant")
1342
+
1343
+ err = client.Data().Updater().
1344
+ WithClassName(className).
1345
+ WithID(fixtures.SOUP_BEAUTIFUL_ID).
1346
+ WithProperties(map[string]interface{}{
1347
+ "description": "merged Beautiful description [%s]",
1348
+ }).
1349
+ WithTenant("nonExistentTenant").
1350
+ WithMerge().
1351
+ Do(context.Background())
1352
+
1353
+ require.NotNil(t, err)
1354
+ clientErr = err.(*fault.WeaviateClientError)
1355
+ assert.Equal(t, 422, clientErr.StatusCode)
1356
+ assert.Contains(t, clientErr.Msg, "has multi-tenancy disabled, but request was with tenant")
1357
+
1358
+ t.Run("verify not merged", func(t *testing.T) {
1359
+ objects, err := client.Data().ObjectsGetter().
1360
+ WithID(fixtures.SOUP_CHICKENSOUP_ID).
1361
+ WithClassName(className).
1362
+ Do(context.Background())
1363
+
1364
+ require.Nil(t, err)
1365
+ require.NotNil(t, objects)
1366
+ require.Len(t, objects, 1)
1367
+ assert.Equal(t, "Used by humans when their inferior genetics are attacked by microscopic organisms.",
1368
+ objects[0].Properties.(map[string]interface{})["description"])
1369
+
1370
+ objects, err = client.Data().ObjectsGetter().
1371
+ WithID(fixtures.SOUP_BEAUTIFUL_ID).
1372
+ WithClassName(className).
1373
+ Do(context.Background())
1374
+
1375
+ require.Nil(t, err)
1376
+ require.NotNil(t, objects)
1377
+ require.Len(t, objects, 1)
1378
+ assert.Equal(t, "Putting the game of letter soups to a whole new level.",
1379
+ objects[0].Properties.(map[string]interface{})["description"])
1380
+ })
1381
+ })
1382
+ }
platform/dbops/binaries/weaviate-src/test/acceptance_with_go_client/multi_tenancy_tests/graphql_test.go ADDED
@@ -0,0 +1,514 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // _ _
2
+ // __ _____ __ ___ ___ __ _| |_ ___
3
+ // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4
+ // \ V V / __/ (_| |\ V /| | (_| | || __/
5
+ // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6
+ //
7
+ // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved.
8
+ //
9
+ // CONTACT: hello@weaviate.io
10
+ //
11
+
12
+ package multi_tenancy_tests
13
+
14
+ import (
15
+ "context"
16
+ "fmt"
17
+ "testing"
18
+
19
+ "github.com/go-openapi/strfmt"
20
+ "github.com/weaviate/weaviate/entities/schema"
21
+
22
+ "acceptance_tests_with_client/fixtures"
23
+
24
+ "github.com/stretchr/testify/assert"
25
+ "github.com/stretchr/testify/require"
26
+ wvt "github.com/weaviate/weaviate-go-client/v5/weaviate"
27
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/filters"
28
+ "github.com/weaviate/weaviate-go-client/v5/weaviate/graphql"
29
+ "github.com/weaviate/weaviate/entities/models"
30
+ )
31
+
32
+ func TestGraphQL_MultiTenancy(t *testing.T) {
33
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: "localhost:8080"})
34
+ require.Nil(t, err)
35
+
36
+ cleanup := func() {
37
+ err := client.Schema().AllDeleter().Do(context.Background())
38
+ require.Nil(t, err)
39
+ }
40
+
41
+ t.Run("GraphQL Get", func(t *testing.T) {
42
+ defer cleanup()
43
+
44
+ tenant1 := models.Tenant{Name: "tenantNo1"}
45
+ tenant2 := models.Tenant{Name: "tenantNo2"}
46
+
47
+ assertGetContainsIds := func(t *testing.T, response *models.GraphQLResponse,
48
+ className string, expectedIds []string,
49
+ ) {
50
+ require.NotNil(t, response)
51
+ assert.Nil(t, response.Errors)
52
+ require.NotNil(t, response.Data)
53
+
54
+ get := response.Data["Get"].(map[string]interface{})
55
+ objects := get[className].([]interface{})
56
+ require.Len(t, objects, len(expectedIds))
57
+
58
+ ids := []string{}
59
+ for i := range objects {
60
+ ids = append(ids, objects[i].(map[string]interface{})["_additional"].(map[string]interface{})["id"].(string))
61
+ }
62
+ assert.ElementsMatch(t, expectedIds, ids)
63
+ }
64
+
65
+ t.Run("add data", func(t *testing.T) {
66
+ fixtures.CreateSchemaPizzaForTenants(t, client)
67
+ fixtures.CreateTenantsPizza(t, client, tenant1, tenant2)
68
+ fixtures.CreateDataPizzaQuattroFormaggiForTenants(t, client, tenant1.Name)
69
+ fixtures.CreateDataPizzaFruttiDiMareForTenants(t, client, tenant1.Name)
70
+ fixtures.CreateDataPizzaHawaiiForTenants(t, client, tenant2.Name)
71
+ fixtures.CreateDataPizzaDoenerForTenants(t, client, tenant2.Name)
72
+ })
73
+
74
+ t.Run("get all data for tenant", func(t *testing.T) {
75
+ expectedIdsByTenant := map[string][]string{
76
+ tenant1.Name: {
77
+ fixtures.PIZZA_QUATTRO_FORMAGGI_ID,
78
+ fixtures.PIZZA_FRUTTI_DI_MARE_ID,
79
+ },
80
+ tenant2.Name: {
81
+ fixtures.PIZZA_HAWAII_ID,
82
+ fixtures.PIZZA_DOENER_ID,
83
+ },
84
+ }
85
+
86
+ for tenant, expectedIds := range expectedIdsByTenant {
87
+ resp, err := client.GraphQL().Get().
88
+ WithClassName("Pizza").
89
+ WithTenant(tenant).
90
+ WithFields(graphql.Field{
91
+ Name: "_additional",
92
+ Fields: []graphql.Field{{Name: "id"}},
93
+ }).
94
+ Do(context.Background())
95
+
96
+ assert.Nil(t, err)
97
+ assertGetContainsIds(t, resp, "Pizza", expectedIds)
98
+ }
99
+ })
100
+
101
+ t.Run("get limited data for tenant", func(t *testing.T) {
102
+ expectedIdsByTenant := map[string][]string{
103
+ tenant1.Name: {
104
+ fixtures.PIZZA_QUATTRO_FORMAGGI_ID,
105
+ },
106
+ tenant2.Name: {
107
+ fixtures.PIZZA_HAWAII_ID,
108
+ },
109
+ }
110
+
111
+ for tenant, expectedIds := range expectedIdsByTenant {
112
+ resp, err := client.GraphQL().Get().
113
+ WithClassName("Pizza").
114
+ WithTenant(tenant).
115
+ WithLimit(1).
116
+ WithFields(graphql.Field{
117
+ Name: "_additional",
118
+ Fields: []graphql.Field{{Name: "id"}},
119
+ }).
120
+ Do(context.Background())
121
+
122
+ assert.Nil(t, err)
123
+ assertGetContainsIds(t, resp, "Pizza", expectedIds)
124
+ }
125
+ })
126
+
127
+ t.Run("get filtered data for tenant", func(t *testing.T) {
128
+ expectedIdsByTenant := map[string][]string{
129
+ tenant1.Name: {},
130
+ tenant2.Name: {
131
+ fixtures.PIZZA_DOENER_ID,
132
+ },
133
+ }
134
+ where := filters.Where().
135
+ WithPath([]string{"price"}).
136
+ WithOperator(filters.GreaterThan).
137
+ WithValueNumber(1.3)
138
+
139
+ for tenant, expectedIds := range expectedIdsByTenant {
140
+ resp, err := client.GraphQL().Get().
141
+ WithClassName("Pizza").
142
+ WithTenant(tenant).
143
+ WithWhere(where).
144
+ WithFields(graphql.Field{
145
+ Name: "_additional",
146
+ Fields: []graphql.Field{{Name: "id"}},
147
+ }).
148
+ Do(context.Background())
149
+
150
+ assert.Nil(t, err)
151
+ assertGetContainsIds(t, resp, "Pizza", expectedIds)
152
+ }
153
+ })
154
+ })
155
+
156
+ t.Run("GraphQL Get referenced class", func(t *testing.T) {
157
+ defer cleanup()
158
+
159
+ tenant1 := models.Tenant{Name: "tenantNo1"}
160
+ tenant2 := models.Tenant{Name: "tenantNo2"}
161
+ soupIdByTenantAndPizza := map[string]map[string]string{
162
+ tenant1.Name: {
163
+ fixtures.PIZZA_QUATTRO_FORMAGGI_ID: fixtures.SOUP_CHICKENSOUP_ID,
164
+ fixtures.PIZZA_FRUTTI_DI_MARE_ID: fixtures.SOUP_CHICKENSOUP_ID,
165
+ },
166
+ tenant2.Name: {
167
+ fixtures.PIZZA_HAWAII_ID: fixtures.SOUP_BEAUTIFUL_ID,
168
+ fixtures.PIZZA_DOENER_ID: fixtures.SOUP_BEAUTIFUL_ID,
169
+ },
170
+ }
171
+
172
+ assertGetContainsIds := func(t *testing.T, response *models.GraphQLResponse,
173
+ className string, expectedIds ...string,
174
+ ) {
175
+ require.NotNil(t, response)
176
+ assert.Nil(t, response.Errors)
177
+ require.NotNil(t, response.Data)
178
+
179
+ get := response.Data["Get"].(map[string]interface{})
180
+ objects := get[className].([]interface{})
181
+ require.Len(t, objects, len(expectedIds))
182
+
183
+ ids := []string{}
184
+ for i := range objects {
185
+ ids = append(ids, objects[i].(map[string]interface{})["_additional"].(map[string]interface{})["id"].(string))
186
+ }
187
+ assert.ElementsMatch(t, expectedIds, ids)
188
+ }
189
+
190
+ t.Run("add data", func(t *testing.T) {
191
+ fixtures.CreateSchemaPizzaForTenants(t, client)
192
+ fixtures.CreateTenantsPizza(t, client, tenant1, tenant2)
193
+ fixtures.CreateDataPizzaQuattroFormaggiForTenants(t, client, tenant1.Name)
194
+ fixtures.CreateDataPizzaFruttiDiMareForTenants(t, client, tenant1.Name)
195
+ fixtures.CreateDataPizzaHawaiiForTenants(t, client, tenant2.Name)
196
+ fixtures.CreateDataPizzaDoenerForTenants(t, client, tenant2.Name)
197
+
198
+ fixtures.CreateSchemaSoupForTenants(t, client)
199
+ fixtures.CreateTenantsSoup(t, client, tenant1, tenant2)
200
+ fixtures.CreateDataSoupChickenForTenants(t, client, tenant1.Name)
201
+ fixtures.CreateDataSoupBeautifulForTenants(t, client, tenant2.Name)
202
+ })
203
+
204
+ t.Run("create ref property", func(t *testing.T) {
205
+ err := client.Schema().PropertyCreator().
206
+ WithClassName("Soup").
207
+ WithProperty(&models.Property{
208
+ Name: "relatedToPizza",
209
+ DataType: []string{"Pizza"},
210
+ }).
211
+ Do(context.Background())
212
+
213
+ require.Nil(t, err)
214
+ })
215
+
216
+ t.Run("create refs", func(t *testing.T) {
217
+ references := []*models.BatchReference{}
218
+
219
+ for tenant, pizzaToSoup := range soupIdByTenantAndPizza {
220
+ for pizzaId, soupId := range pizzaToSoup {
221
+ rpb := client.Batch().ReferencePayloadBuilder().
222
+ WithFromClassName("Soup").
223
+ WithFromRefProp("relatedToPizza").
224
+ WithFromID(soupId).
225
+ WithToClassName("Pizza").
226
+ WithToID(pizzaId).
227
+ WithTenant(tenant)
228
+
229
+ references = append(references, rpb.Payload())
230
+ }
231
+ }
232
+
233
+ resp, err := client.Batch().ReferencesBatcher().
234
+ WithReferences(references...).
235
+ Do(context.Background())
236
+
237
+ require.Nil(t, err)
238
+ require.NotNil(t, resp)
239
+ assert.Len(t, resp, len(references))
240
+ for i := range resp {
241
+ require.NotNil(t, resp[i].Result)
242
+ assert.Nil(t, resp[i].Result.Errors)
243
+ }
244
+ })
245
+
246
+ for tenant, pizzaToSoup := range soupIdByTenantAndPizza {
247
+ for pizzaId, expectedSoupId := range pizzaToSoup {
248
+ resp, err := client.GraphQL().Get().
249
+ WithClassName("Soup").
250
+ WithTenant(tenant).
251
+ WithFields(graphql.Field{
252
+ Name: "_additional",
253
+ Fields: []graphql.Field{{Name: "id"}},
254
+ }).
255
+ WithWhere(filters.Where().
256
+ WithOperator(filters.Equal).
257
+ WithPath([]string{"relatedToPizza", "Pizza", "_id"}).
258
+ WithValueText(pizzaId)).
259
+ Do(context.Background())
260
+
261
+ assert.Nil(t, err)
262
+ assertGetContainsIds(t, resp, "Soup", expectedSoupId)
263
+ }
264
+ }
265
+ })
266
+
267
+ t.Run("GraphQL Aggregate", func(t *testing.T) {
268
+ defer cleanup()
269
+
270
+ tenant1 := models.Tenant{Name: "tenantNo1"}
271
+ tenant2 := models.Tenant{Name: "tenantNo2"}
272
+
273
+ assertAggregateNumFieldHasValues := func(t *testing.T, response *models.GraphQLResponse,
274
+ className string, fieldName string, expectedAggValues map[string]*float64,
275
+ ) {
276
+ require.NotNil(t, response)
277
+ assert.Nil(t, response.Errors)
278
+ require.NotNil(t, response.Data)
279
+
280
+ agg := response.Data["Aggregate"].(map[string]interface{})
281
+ require.NotNil(t, agg)
282
+
283
+ objects := agg[className].([]interface{})
284
+ require.Len(t, objects, 1)
285
+ obj := objects[0].(map[string]interface{})[fieldName].(map[string]interface{})
286
+
287
+ for name, value := range expectedAggValues {
288
+ if value == nil {
289
+ assert.Nil(t, obj[name])
290
+ } else {
291
+ assert.Equal(t, *value, obj[name])
292
+ }
293
+ }
294
+ }
295
+ ptr := func(f float64) *float64 {
296
+ return &f
297
+ }
298
+
299
+ t.Run("add data", func(t *testing.T) {
300
+ fixtures.CreateSchemaPizzaForTenants(t, client)
301
+ fixtures.CreateTenantsPizza(t, client, tenant1, tenant2)
302
+ fixtures.CreateDataPizzaQuattroFormaggiForTenants(t, client, tenant1.Name)
303
+ fixtures.CreateDataPizzaFruttiDiMareForTenants(t, client, tenant1.Name)
304
+ fixtures.CreateDataPizzaHawaiiForTenants(t, client, tenant2.Name)
305
+ fixtures.CreateDataPizzaDoenerForTenants(t, client, tenant2.Name)
306
+ })
307
+
308
+ t.Run("aggregate all data for tenant", func(t *testing.T) {
309
+ expectedAggValuesByTenant := map[string]map[string]*float64{
310
+ tenant1.Name: {
311
+ "count": ptr(2),
312
+ "maximum": ptr(1.2),
313
+ "minimum": ptr(1.1),
314
+ "median": ptr(1.15),
315
+ "mean": ptr(1.15),
316
+ "mode": ptr(1.1),
317
+ "sum": ptr(2.3),
318
+ },
319
+ tenant2.Name: {
320
+ "count": ptr(2),
321
+ "maximum": ptr(1.4),
322
+ "minimum": ptr(1.3),
323
+ "median": ptr(1.35),
324
+ "mean": ptr(1.35),
325
+ "mode": ptr(1.3),
326
+ "sum": ptr(2.7),
327
+ },
328
+ }
329
+
330
+ for tenant, expectedAggValues := range expectedAggValuesByTenant {
331
+ resp, err := client.GraphQL().Aggregate().
332
+ WithClassName("Pizza").
333
+ WithTenant(tenant).
334
+ WithFields(graphql.Field{
335
+ Name: "price",
336
+ Fields: []graphql.Field{
337
+ {Name: "count"},
338
+ {Name: "maximum"},
339
+ {Name: "minimum"},
340
+ {Name: "median"},
341
+ {Name: "mean"},
342
+ {Name: "mode"},
343
+ {Name: "sum"},
344
+ },
345
+ }).
346
+ Do(context.Background())
347
+
348
+ assert.Nil(t, err)
349
+ assertAggregateNumFieldHasValues(t, resp, "Pizza", "price", expectedAggValues)
350
+ }
351
+ })
352
+
353
+ t.Run("aggregate filtered data for tenant", func(t *testing.T) {
354
+ expectedAggValuesByTenant := map[string]map[string]*float64{
355
+ tenant1.Name: {
356
+ "count": ptr(0),
357
+ "maximum": nil,
358
+ "minimum": nil,
359
+ "median": nil,
360
+ "mean": nil,
361
+ "mode": nil,
362
+ "sum": nil,
363
+ },
364
+ tenant2.Name: {
365
+ "count": ptr(1),
366
+ "maximum": ptr(1.4),
367
+ "minimum": ptr(1.4),
368
+ "median": ptr(1.4),
369
+ "mean": ptr(1.4),
370
+ "mode": ptr(1.4),
371
+ "sum": ptr(1.4),
372
+ },
373
+ }
374
+ where := filters.Where().
375
+ WithPath([]string{"price"}).
376
+ WithOperator(filters.GreaterThan).
377
+ WithValueNumber(1.3)
378
+
379
+ for tenant, expectedAggValues := range expectedAggValuesByTenant {
380
+ resp, err := client.GraphQL().Aggregate().
381
+ WithClassName("Pizza").
382
+ WithTenant(tenant).
383
+ WithWhere(where).
384
+ WithFields(graphql.Field{
385
+ Name: "price",
386
+ Fields: []graphql.Field{
387
+ {Name: "count"},
388
+ {Name: "maximum"},
389
+ {Name: "minimum"},
390
+ {Name: "median"},
391
+ {Name: "mean"},
392
+ {Name: "mode"},
393
+ {Name: "sum"},
394
+ },
395
+ }).
396
+ Do(context.Background())
397
+
398
+ assert.Nil(t, err)
399
+ assertAggregateNumFieldHasValues(t, resp, "Pizza", "price", expectedAggValues)
400
+ }
401
+ })
402
+ })
403
+
404
+ t.Run("GraphQL Explore", func(t *testing.T) {
405
+ defer cleanup()
406
+
407
+ tenant1 := models.Tenant{Name: "tenantNo1"}
408
+ tenant2 := models.Tenant{Name: "tenantNo2"}
409
+
410
+ assertExploreContainsErrors := func(t *testing.T, response *models.GraphQLResponse,
411
+ expectedErrorMessage string,
412
+ ) {
413
+ require.NotNil(t, response)
414
+ require.NotNil(t, response.Errors)
415
+ require.Nil(t, response.Data["Explore"])
416
+ require.NotNil(t, response.Data)
417
+ require.Len(t, response.Errors, 1)
418
+ assert.NotEmpty(t, response.Errors[0].Message)
419
+ assert.Equal(t, expectedErrorMessage, response.Errors[0].Message)
420
+ }
421
+
422
+ t.Run("add data", func(t *testing.T) {
423
+ fixtures.CreateSchemaPizzaForTenants(t, client)
424
+ fixtures.CreateTenantsPizza(t, client, tenant1, tenant2)
425
+ fixtures.CreateDataPizzaQuattroFormaggiForTenants(t, client, tenant1.Name)
426
+ fixtures.CreateDataPizzaFruttiDiMareForTenants(t, client, tenant1.Name)
427
+ fixtures.CreateDataPizzaHawaiiForTenants(t, client, tenant2.Name)
428
+ fixtures.CreateDataPizzaDoenerForTenants(t, client, tenant2.Name)
429
+ })
430
+
431
+ t.Run("explore with nearText", func(t *testing.T) {
432
+ nearText := client.GraphQL().NearTextArgBuilder().
433
+ WithConcepts([]string{"Italian"})
434
+
435
+ resp, err := client.GraphQL().Explore().
436
+ WithNearText(nearText).
437
+ WithFields(graphql.Beacon, graphql.Certainty, graphql.ClassName).
438
+ Do(context.Background())
439
+
440
+ require.Nil(t, err)
441
+ assertExploreContainsErrors(t, resp,
442
+ "vector search: search index pizza: class Pizza has multi-tenancy enabled, but request was without tenant",
443
+ )
444
+ })
445
+ })
446
+ }
447
+
448
+ func TestGroupByMultiTenancy(t *testing.T) {
449
+ client, err := wvt.NewClient(wvt.Config{Scheme: "http", Host: "localhost:8080"})
450
+ require.Nil(t, err)
451
+
452
+ ctx := context.Background()
453
+
454
+ defer client.Schema().ClassDeleter().WithClassName("TextContent").Do(ctx)
455
+ defer client.Schema().ClassDeleter().WithClassName("Document").Do(ctx)
456
+
457
+ err = client.Schema().ClassCreator().WithClass(
458
+ &models.Class{
459
+ Class: "TextContent",
460
+ MultiTenancyConfig: &models.MultiTenancyConfig{Enabled: true},
461
+ Vectorizer: "text2vec-contextionary",
462
+ Properties: []*models.Property{
463
+ {
464
+ Name: "text",
465
+ DataType: schema.DataTypeText.PropString(),
466
+ },
467
+ },
468
+ },
469
+ ).Do(ctx)
470
+ require.Nil(t, err)
471
+
472
+ err = client.Schema().ClassCreator().WithClass(
473
+ &models.Class{
474
+ Class: "Document",
475
+ MultiTenancyConfig: &models.MultiTenancyConfig{Enabled: true},
476
+ Vectorizer: "text2vec-contextionary",
477
+ Properties: []*models.Property{
478
+ {
479
+ Name: "textContents",
480
+ DataType: []string{"TextContent"},
481
+ },
482
+ {
483
+ Name: "title",
484
+ DataType: schema.DataTypeText.PropString(),
485
+ },
486
+ },
487
+ },
488
+ ).Do(ctx)
489
+ require.Nil(t, err)
490
+
491
+ require.Nil(t, client.Schema().PropertyCreator().WithClassName("TextContent").WithProperty(&models.Property{
492
+ Name: "contentOf",
493
+ DataType: []string{"Document"},
494
+ }).Do(ctx))
495
+
496
+ require.Nil(t, client.Schema().TenantsCreator().WithClassName("TextContent").WithTenants(models.Tenant{Name: "1"}).Do(ctx))
497
+ require.Nil(t, client.Schema().TenantsCreator().WithClassName("Document").WithTenants(models.Tenant{Name: "1"}).Do(ctx))
498
+
499
+ docCreator := client.Data().Creator().WithClassName("Document").WithTenant("1")
500
+ doc1, err := docCreator.WithProperties(map[string]interface{}{"title": "Foo"}).Do(ctx)
501
+ require.Nil(t, err)
502
+
503
+ textCreator := client.Data().Creator().WithClassName("TextContent").WithTenant("1")
504
+ text1, err := textCreator.WithProperties(map[string]interface{}{"text": "Text from Foo"}).Do(ctx)
505
+ require.Nil(t, err)
506
+
507
+ require.Nil(t, client.Data().ReferenceCreator().WithTenant("1").WithClassName("Document").WithID(doc1.Object.ID.String()).WithReferenceProperty("textContents").WithReference(&models.SingleRef{Beacon: strfmt.URI(fmt.Sprintf("weaviate://localhost/TextContent/%s", text1.Object.ID.String()))}).Do(ctx))
508
+ require.Nil(t, client.Data().ReferenceCreator().WithTenant("1").WithClassName("TextContent").WithID(text1.Object.ID.String()).WithReferenceProperty("contentOf").WithReference(&models.SingleRef{Beacon: strfmt.URI(fmt.Sprintf("weaviate://localhost/Document/%s", doc1.Object.ID.String()))}).Do(ctx))
509
+
510
+ result, err := client.GraphQL().Raw().WithQuery("{Get{TextContent(nearText: {concepts: [\"Foo\"] distance: 1.0} groupBy:{path:[\"contentOf\"], groups:2, objectsPerGroup:1}tenant: \"1\"){contentOf{... on Document{title}}}}}").Do(ctx)
511
+ require.Nil(t, err)
512
+ require.NotNil(t, result)
513
+ require.Nil(t, result.Errors)
514
+ }