github.com/weaviate/weaviate@v1.24.6/usecases/modulecomponents/arguments/nearImage/graphql_argument_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 nearImage 13 14 import ( 15 "testing" 16 17 "github.com/stretchr/testify/assert" 18 "github.com/tailor-inc/graphql" 19 ) 20 21 func TestNearImageGraphQLArgument(t *testing.T) { 22 t.Run("should generate nearImage argument properly", func(t *testing.T) { 23 // given 24 prefix := "Prefix" 25 classname := "Class" 26 // when 27 nearImage := nearImageArgument(prefix, classname) 28 29 // then 30 // the built graphQL field needs to support this structure: 31 // nearImage: { 32 // image: "base64;encoded,image", 33 // distance: 0.4, 34 // targetVectors: ["targetVector"] 35 // } 36 assert.NotNil(t, nearImage) 37 assert.Equal(t, "Img2VecImagePrefixClassNearImageInpObj", nearImage.Type.Name()) 38 answerFields, ok := nearImage.Type.(*graphql.InputObject) 39 assert.True(t, ok) 40 assert.NotNil(t, answerFields) 41 assert.Equal(t, 4, len(answerFields.Fields())) 42 fields := answerFields.Fields() 43 image := fields["image"] 44 imageNonNull, imageNonNullOK := image.Type.(*graphql.NonNull) 45 assert.True(t, imageNonNullOK) 46 assert.Equal(t, "String", imageNonNull.OfType.Name()) 47 assert.NotNil(t, image) 48 assert.NotNil(t, fields["certainty"]) 49 assert.NotNil(t, fields["distance"]) 50 targetVectors := fields["targetVectors"] 51 targetVectorsList, targetVectorsListOK := targetVectors.Type.(*graphql.List) 52 assert.True(t, targetVectorsListOK) 53 assert.Equal(t, "String", targetVectorsList.OfType.Name()) 54 assert.NotNil(t, targetVectors) 55 }) 56 }