github.com/weaviate/weaviate@v1.24.6/test/acceptance/batch_request_endpoints/actionscreate_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 // TODO: change this test to simulate a successful query response when the test dataset is implemented. 13 14 // Acceptance tests for the batch ObjectsCreate endpoint 15 package batch_request_endpoints 16 17 import ( 18 "fmt" 19 "testing" 20 21 "github.com/stretchr/testify/assert" 22 "github.com/weaviate/weaviate/client/batch" 23 "github.com/weaviate/weaviate/entities/models" 24 "github.com/weaviate/weaviate/test/helper" 25 ) 26 27 // Test if batching is working correctly. Sends an OK batch containing two batched requests that refer to non-existing classes. 28 // The expected outcome is a 200 batch response containing two batched responses. These batched responses should both contain errors. 29 func TestBatchObjectsCreateResultsOrder(t *testing.T) { 30 t.Parallel() 31 32 classOneName := "ItIsExtremelyUnlikelyThatThisClassActuallyExistsButJustToBeSureHereAreSomeRandomNumbers12987825624398509861298409782539802434516542" 33 classTwoName := "ItIsExtremelyUnlikelyThatThisClassActuallyExistsButJustToBeSureHereAreSomeRandomNumbers12987825624398509861298409782539802434516541" 34 expectedResult := "class '%s' not present in schema" 35 36 // generate objectcreate content 37 object1 := &models.Object{ 38 Class: classOneName, 39 Properties: map[string]interface{}{ 40 "testString": "Test string", 41 }, 42 } 43 object2 := &models.Object{ 44 Class: classTwoName, 45 Properties: map[string]interface{}{ 46 "testWholeNumber": 1, 47 }, 48 } 49 50 testFields := "ALL" 51 52 // generate request body 53 params := batch.NewBatchObjectsCreateParams().WithBody(batch.BatchObjectsCreateBody{ 54 Objects: []*models.Object{object1, object2}, 55 Fields: []*string{&testFields}, 56 }) 57 58 // perform the request 59 resp, err := helper.BatchClient(t).BatchObjectsCreate(params, nil) 60 // ensure that the response is OK 61 helper.AssertRequestOk(t, resp, err, func() { 62 objectsCreateResponse := resp.Payload 63 64 // check if the batch response contains two batched responses 65 assert.Equal(t, 2, len(objectsCreateResponse)) 66 67 // check if the error message matches the expected outcome (and are therefore returned in the correct order) 68 if len(objectsCreateResponse) == 2 { 69 responseOne := objectsCreateResponse[0].Result.Errors.Error[0].Message 70 responseTwo := objectsCreateResponse[1].Result.Errors.Error[0].Message 71 72 fullExpectedOutcomeOne := fmt.Sprintf(expectedResult, classOneName) 73 assert.Contains(t, responseOne, fullExpectedOutcomeOne) 74 75 fullExpectedOutcomeTwo := fmt.Sprintf(expectedResult, classTwoName) 76 assert.Contains(t, responseTwo, fullExpectedOutcomeTwo) 77 } 78 }) 79 }