github.com/weaviate/weaviate@v1.24.6/test/acceptance/objects/delete_objects_from_all_classes.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 // Acceptance tests for objects. 15 16 import ( 17 "testing" 18 19 "github.com/go-openapi/strfmt" 20 21 "github.com/stretchr/testify/assert" 22 "github.com/stretchr/testify/require" 23 24 "github.com/weaviate/weaviate/client/batch" 25 "github.com/weaviate/weaviate/client/objects" 26 "github.com/weaviate/weaviate/entities/models" 27 "github.com/weaviate/weaviate/test/helper" 28 ) 29 30 // run from setup_test.go 31 func deleteAllObjectsFromAllClasses(t *testing.T) { 32 // We can have a situation that objects in different classes 33 // have the same ID. This test is to ensure that the delete request 34 // deletes all of the objects with a given ID in all classes 35 // This test is connected with this issue: 36 // https://github.com/weaviate/weaviate/issues/1836 37 const fakeObjectId strfmt.UUID = "11111111-1111-1111-1111-111111111111" 38 39 t.Run("create objects with a specified id", func(t *testing.T) { 40 object1 := &models.Object{ 41 Class: "TestDeleteClassOne", 42 ID: fakeObjectId, 43 Properties: map[string]interface{}{ 44 "text": "Test string 1", 45 }, 46 } 47 object2 := &models.Object{ 48 Class: "TestDeleteClassTwo", 49 ID: fakeObjectId, 50 Properties: map[string]interface{}{ 51 "text": "Test string 2", 52 }, 53 } 54 55 testFields := "ALL" 56 // generate request body 57 params := batch.NewBatchObjectsCreateParams().WithBody(batch.BatchObjectsCreateBody{ 58 Objects: []*models.Object{object1, object2}, 59 Fields: []*string{&testFields}, 60 }) 61 62 // perform the request 63 resp, err := helper.BatchClient(t).BatchObjectsCreate(params, nil) 64 // ensure that the response is OK 65 helper.AssertRequestOk(t, resp, err, func() { 66 objectsCreateResponse := resp.Payload 67 68 // check if the batch response contains two batched responses 69 assert.Equal(t, 2, len(objectsCreateResponse)) 70 71 for _, elem := range resp.Payload { 72 assert.Nil(t, elem.Result.Errors) 73 } 74 }) 75 }) 76 77 t.Run("check that object exists", func(t *testing.T) { 78 // there are actually 2 objects in 2 classes with this ID 79 params := objects.NewObjectsGetParams().WithID(fakeObjectId) 80 resp, err := helper.Client(t).Objects.ObjectsGet(params, nil) 81 require.Nil(t, err, "get should succeed") 82 assert.NotNil(t, resp.Payload) 83 }) 84 85 t.Run("delete objects with a given ID from all classes", func(t *testing.T) { 86 params := objects.NewObjectsDeleteParams().WithID(fakeObjectId) 87 resp, err := helper.Client(t).Objects.ObjectsDelete(params, nil) 88 require.Nil(t, err, "delete should succeed") 89 assert.Equal(t, &objects.ObjectsDeleteNoContent{}, resp) 90 }) 91 92 t.Run("check that object with given ID is removed from all classes", func(t *testing.T) { 93 params := objects.NewObjectsGetParams().WithID(fakeObjectId) 94 resp, err := helper.Client(t).Objects.ObjectsGet(params, nil) 95 require.Equal(t, &objects.ObjectsGetNotFound{}, err) 96 assert.Nil(t, resp) 97 }) 98 }