github.com/weaviate/weaviate@v1.24.6/test/acceptance/objects/list_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 // Acceptance tests for things. 15 16 import ( 17 "testing" 18 19 "github.com/stretchr/testify/assert" 20 "github.com/stretchr/testify/require" 21 "github.com/weaviate/weaviate/client/objects" 22 "github.com/weaviate/weaviate/entities/models" 23 "github.com/weaviate/weaviate/test/helper" 24 ) 25 26 // Test that we can properly list objects. 27 // Create two objects, and check that the list all contains them all. 28 // This test is run by setup_test.go 29 func listingObjects(t *testing.T) { 30 params1 := objects.NewObjectsCreateParams().WithBody( 31 &models.Object{ 32 Class: "TestObject", 33 Properties: map[string]interface{}{ 34 "testString": "1", 35 }, 36 }) 37 resp1, err := helper.Client(t).Objects.ObjectsCreate(params1, nil) 38 require.Nil(t, err, "creation should succeed") 39 object1ID := resp1.Payload.ID 40 41 params2 := objects.NewObjectsCreateParams().WithBody( 42 &models.Object{ 43 Class: "TestObject", 44 Properties: map[string]interface{}{ 45 "testString": "2", 46 }, 47 }) 48 resp2, err := helper.Client(t).Objects.ObjectsCreate(params2, nil) 49 assert.Nil(t, err, "creation should succeed") 50 object2ID := resp2.Payload.ID 51 52 // wait for both Objects to be indexed 53 assertGetObjectEventually(t, object1ID) 54 assertGetObjectEventually(t, object2ID) 55 56 listParams := objects.NewObjectsListParams() 57 resp, err := helper.Client(t).Objects.ObjectsList(listParams, nil) 58 require.Nil(t, err, "should not error") 59 60 found1 := false 61 found2 := false 62 63 for _, object := range resp.Payload.Objects { 64 if object.ID == resp1.Payload.ID { 65 assert.False(t, found1, "found double ID for object 1!") 66 found1 = true 67 } 68 69 if object.ID == resp2.Payload.ID { 70 assert.False(t, found2, "found double ID for object 2!") 71 found2 = true 72 } 73 } 74 75 assert.True(t, found1, "Did not find object 1") 76 assert.True(t, found2, "Did not find object 2") 77 }