github.com/weaviate/weaviate@v1.24.6/test/acceptance/objects/setup_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 "context" 16 "fmt" 17 "testing" 18 19 "github.com/stretchr/testify/require" 20 "github.com/weaviate/weaviate/client/objects" 21 22 clschema "github.com/weaviate/weaviate/client/schema" 23 "github.com/weaviate/weaviate/entities/models" 24 "github.com/weaviate/weaviate/entities/schema" 25 "github.com/weaviate/weaviate/test/docker" 26 "github.com/weaviate/weaviate/test/helper" 27 ) 28 29 // Tests that sort parameters are validated with the correct class 30 func TestSort(t *testing.T) { 31 createObjectClass(t, &models.Class{ 32 Class: "ClassToSort", 33 Properties: []*models.Property{ 34 { 35 Name: "name", 36 DataType: schema.DataTypeText.PropString(), 37 Tokenization: models.PropertyTokenizationWhitespace, 38 }, 39 }, 40 }) 41 defer deleteObjectClass(t, "ClassToSort") 42 43 createObjectClass(t, &models.Class{ 44 Class: "OtherClass", 45 Properties: []*models.Property{ 46 { 47 Name: "ref", 48 DataType: []string{"ClassToSort"}, 49 }, 50 }, 51 }) 52 defer deleteObjectClass(t, "OtherClass") 53 54 listParams := objects.NewObjectsListParams() 55 nameClass := "ClassToSort" 56 nameProp := "name" 57 limit := int64(5) 58 listParams.Class = &nameClass 59 listParams.Sort = &nameProp 60 listParams.Limit = &limit 61 62 _, err := helper.Client(t).Objects.ObjectsList(listParams, nil) 63 require.Nil(t, err, "should not error") 64 } 65 66 func TestObjects_AsyncIndexing(t *testing.T) { 67 ctx := context.Background() 68 compose, err := docker.New(). 69 WithWeaviate(). 70 WithText2VecContextionary(). 71 WithWeaviateEnv("ASYNC_INDEXING", "true"). 72 Start(ctx) 73 require.NoError(t, err) 74 defer func() { 75 require.NoError(t, compose.Terminate(ctx)) 76 }() 77 78 defer helper.SetupClient(fmt.Sprintf("%s:%s", helper.ServerHost, helper.ServerPort)) 79 helper.SetupClient(compose.GetWeaviate().URI()) 80 81 testObjects(t) 82 } 83 84 func TestObjects_SyncIndexing(t *testing.T) { 85 testObjects(t) 86 } 87 88 func testObjects(t *testing.T) { 89 createObjectClass(t, &models.Class{ 90 Class: "TestObject", 91 ModuleConfig: map[string]interface{}{ 92 "text2vec-contextionary": map[string]interface{}{ 93 "vectorizeClassName": true, 94 }, 95 }, 96 Properties: []*models.Property{ 97 { 98 Name: "testString", 99 DataType: schema.DataTypeText.PropString(), 100 Tokenization: models.PropertyTokenizationWhitespace, 101 }, 102 { 103 Name: "testWholeNumber", 104 DataType: []string{"int"}, 105 }, 106 { 107 Name: "testNumber", 108 DataType: []string{"number"}, 109 }, 110 { 111 Name: "testDateTime", 112 DataType: []string{"date"}, 113 }, 114 { 115 Name: "testTrueFalse", 116 DataType: []string{"boolean"}, 117 }, 118 { 119 Name: "testPhoneNumber", 120 DataType: []string{"phoneNumber"}, 121 }, 122 }, 123 }) 124 createObjectClass(t, &models.Class{ 125 Class: "TestObjectCustomVector", 126 Vectorizer: "none", 127 Properties: []*models.Property{ 128 { 129 Name: "description", 130 DataType: []string{"text"}, 131 }, 132 }, 133 }) 134 createObjectClass(t, &models.Class{ 135 Class: "TestDeleteClassOne", 136 Vectorizer: "none", 137 Properties: []*models.Property{ 138 { 139 Name: "text", 140 DataType: []string{"text"}, 141 }, 142 }, 143 }) 144 createObjectClass(t, &models.Class{ 145 Class: "TestDeleteClassTwo", 146 Vectorizer: "none", 147 Properties: []*models.Property{ 148 { 149 Name: "text", 150 DataType: []string{"text"}, 151 }, 152 }, 153 }) 154 155 // tests 156 t.Run("listing objects", listingObjects) 157 t.Run("searching for neighbors", searchNeighbors) 158 t.Run("running a feature projection", featureProjection) 159 t.Run("creating objects", creatingObjects) 160 161 t.Run("custom vector journey", customVectors) 162 t.Run("auto schema", autoSchemaObjects) 163 t.Run("checking object's existence", checkObjects) 164 t.Run("delete request deletes all objects with a given ID", deleteAllObjectsFromAllClasses) 165 166 // tear down 167 deleteObjectClass(t, "TestObject") 168 deleteObjectClass(t, "TestObjectCustomVector") 169 deleteObjectClass(t, "NonExistingClass") 170 deleteObjectClass(t, "TestDeleteClassOne") 171 deleteObjectClass(t, "TestDeleteClassTwo") 172 } 173 174 func createObjectClass(t *testing.T, class *models.Class) { 175 params := clschema.NewSchemaObjectsCreateParams().WithObjectClass(class) 176 resp, err := helper.Client(t).Schema.SchemaObjectsCreate(params, nil) 177 helper.AssertRequestOk(t, resp, err, nil) 178 } 179 180 func deleteObjectClass(t *testing.T, class string) { 181 delParams := clschema.NewSchemaObjectsDeleteParams().WithClassName(class) 182 delRes, err := helper.Client(t).Schema.SchemaObjectsDelete(delParams, nil) 183 helper.AssertRequestOk(t, delRes, err, nil) 184 }