github.com/weaviate/weaviate@v1.24.6/test/acceptance/multi_tenancy/head_tenant_objects_test.go (about) 1 // _ _ 2 // __ _____ __ ___ ___ __ _| |_ ___ 3 // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \ 4 // \ V V / __/ (_| |\ V /| | (_| | || __/ 5 // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___| 6 // 7 // Copyright © 2016 - 2024 Weaviate B.V. All rights reserved. 8 // 9 // CONTACT: hello@weaviate.io 10 // 11 12 package test 13 14 import ( 15 "testing" 16 17 "github.com/stretchr/testify/assert" 18 "github.com/stretchr/testify/require" 19 "github.com/weaviate/weaviate/entities/models" 20 "github.com/weaviate/weaviate/entities/schema" 21 "github.com/weaviate/weaviate/test/helper" 22 ) 23 24 func TestHeadTenantObjects(t *testing.T) { 25 testClass := models.Class{ 26 Class: "MultiTenantClass", 27 MultiTenancyConfig: &models.MultiTenancyConfig{ 28 Enabled: true, 29 }, 30 Properties: []*models.Property{ 31 { 32 Name: "name", 33 DataType: schema.DataTypeText.PropString(), 34 }, 35 }, 36 } 37 tenantNames := []string{ 38 "Tenant1", "Tenant2", "Tenant3", 39 } 40 tenantObjects := []*models.Object{ 41 { 42 ID: "0927a1e0-398e-4e76-91fb-04a7a8f0405c", 43 Class: testClass.Class, 44 Properties: map[string]interface{}{ 45 "name": tenantNames[0], 46 }, 47 Tenant: tenantNames[0], 48 }, 49 { 50 ID: "831ae1d0-f441-44b1-bb2a-46548048e26f", 51 Class: testClass.Class, 52 Properties: map[string]interface{}{ 53 "name": tenantNames[1], 54 }, 55 Tenant: tenantNames[1], 56 }, 57 { 58 ID: "6f3363e0-c0a0-4618-bf1f-b6cad9cdff59", 59 Class: testClass.Class, 60 Properties: map[string]interface{}{ 61 "name": tenantNames[2], 62 }, 63 Tenant: tenantNames[2], 64 }, 65 } 66 67 defer func() { 68 helper.DeleteClass(t, testClass.Class) 69 }() 70 71 t.Run("create class with multi-tenancy enabled", func(t *testing.T) { 72 helper.CreateClass(t, &testClass) 73 }) 74 75 t.Run("create tenants", func(t *testing.T) { 76 tenants := make([]*models.Tenant, len(tenantNames)) 77 for i := range tenants { 78 tenants[i] = &models.Tenant{Name: tenantNames[i]} 79 } 80 helper.CreateTenants(t, testClass.Class, tenants) 81 }) 82 83 t.Run("add tenant objects", func(t *testing.T) { 84 for _, obj := range tenantObjects { 85 helper.CreateObject(t, obj) 86 } 87 }) 88 89 t.Run("head tenant objects", func(t *testing.T) { 90 for i, obj := range tenantObjects { 91 exists, err := helper.TenantObjectExists(t, obj.Class, obj.ID, tenantNames[i]) 92 require.Nil(t, err) 93 assert.True(t, exists) 94 } 95 }) 96 }