github.com/weaviate/weaviate@v1.24.6/test/acceptance/grpc/grpc_test_deprecated.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 "testing" 17 18 "github.com/stretchr/testify/assert" 19 "github.com/stretchr/testify/require" 20 pb "github.com/weaviate/weaviate/grpc/generated/protocol/v1" 21 "github.com/weaviate/weaviate/test/helper" 22 "github.com/weaviate/weaviate/test/helper/sample-schema/books" 23 "google.golang.org/grpc/health/grpc_health_v1" 24 ) 25 26 func TestGRPCDeprecated(t *testing.T) { 27 conn, err := helper.CreateGrpcConnectionClient(":50051") 28 require.NoError(t, err) 29 require.NotNil(t, conn) 30 grpcClient := helper.CreateGrpcWeaviateClient(conn) 31 require.NotNil(t, grpcClient) 32 33 // create Books class 34 booksClass := books.ClassContextionaryVectorizer() 35 helper.CreateClass(t, booksClass) 36 defer helper.DeleteClass(t, booksClass.Class) 37 38 t.Run("Health Check", func(t *testing.T) { 39 client := grpc_health_v1.NewHealthClient(conn) 40 check, err := client.Check(context.TODO(), &grpc_health_v1.HealthCheckRequest{}) 41 require.NoError(t, err) 42 require.NotNil(t, check) 43 assert.Equal(t, grpc_health_v1.HealthCheckResponse_SERVING.Enum().Number(), check.Status.Number()) 44 }) 45 46 t.Run("Batch import", func(t *testing.T) { 47 resp, err := grpcClient.BatchObjects(context.TODO(), &pb.BatchObjectsRequest{ 48 Objects: books.BatchObjects(), 49 }) 50 require.NoError(t, err) 51 require.NotNil(t, resp) 52 }) 53 54 tests := []struct { 55 name string 56 req *pb.SearchRequest 57 }{ 58 { 59 name: "Search with props", 60 req: &pb.SearchRequest{ 61 Collection: booksClass.Class, 62 Properties: &pb.PropertiesRequest{ 63 NonRefProperties: []string{"title"}, 64 ObjectProperties: []*pb.ObjectPropertiesRequest{ 65 { 66 PropName: "meta", 67 PrimitiveProperties: []string{"isbn"}, 68 ObjectProperties: []*pb.ObjectPropertiesRequest{ 69 { 70 PropName: "obj", 71 PrimitiveProperties: []string{"text"}, 72 }, 73 { 74 PropName: "objs", 75 PrimitiveProperties: []string{"text"}, 76 }, 77 }, 78 }, 79 {PropName: "reviews", PrimitiveProperties: []string{"tags"}}, 80 }, 81 }, 82 Metadata: &pb.MetadataRequest{ 83 Uuid: true, 84 }, 85 Uses_123Api: false, 86 }, 87 }, 88 { 89 name: "Search without props", 90 req: &pb.SearchRequest{ 91 Collection: booksClass.Class, 92 Metadata: &pb.MetadataRequest{ 93 Uuid: true, 94 }, 95 Uses_123Api: false, 96 }, 97 }, 98 } 99 for _, tt := range tests { 100 t.Run(tt.name, func(t *testing.T) { 101 scifi := "sci-fi" 102 resp, err := grpcClient.Search(context.TODO(), tt.req) 103 require.NoError(t, err) 104 require.NotNil(t, resp) 105 require.NotNil(t, resp.Results) 106 assert.Equal(t, len(books.BatchObjects()), len(resp.Results)) 107 for i := range resp.Results { 108 res := resp.Results[i] 109 id := res.Metadata.Id 110 111 assert.True(t, id == books.Dune.String() || id == books.ProjectHailMary.String() || id == books.TheLordOfTheIceGarden.String()) 112 title, ok := res.Properties.NonRefProperties.AsMap()["title"] 113 require.True(t, ok) 114 115 objProps := res.Properties.ObjectProperties 116 require.Len(t, objProps, 1) 117 isbn, ok := objProps[0].Value.NonRefProperties.AsMap()["isbn"] 118 require.True(t, ok) 119 120 nestedObjProps := objProps[0].Value.ObjectProperties 121 require.Len(t, nestedObjProps, 1) 122 nestedObj := nestedObjProps[0].Value.NonRefProperties.AsMap() 123 124 nestedObjArrayProps := objProps[0].Value.ObjectArrayProperties 125 require.Len(t, nestedObjArrayProps, 1) 126 nestedObjEntry := nestedObjArrayProps[0].Values[0].NonRefProperties.AsMap() 127 128 objArrayProps := res.Properties.ObjectArrayProperties 129 require.Len(t, objArrayProps, 1) 130 tags := objArrayProps[0].Values[0].TextArrayProperties[0].Values 131 require.True(t, ok) 132 133 expectedTitle := "" 134 expectedIsbn := "" 135 expectedTags := []string{} 136 if id == books.Dune.String() { 137 expectedTitle = "Dune" 138 expectedIsbn = "978-0593099322" 139 expectedTags = []string{scifi, "epic"} 140 } 141 if id == books.ProjectHailMary.String() { 142 expectedTitle = "Project Hail Mary" 143 expectedIsbn = "978-0593135204" 144 expectedTags = []string{scifi} 145 } 146 if id == books.TheLordOfTheIceGarden.String() { 147 expectedTitle = "The Lord of the Ice Garden" 148 expectedIsbn = "978-8374812962" 149 expectedTags = []string{scifi, "fantasy"} 150 } 151 assert.Equal(t, expectedTitle, title) 152 assert.Equal(t, expectedIsbn, isbn) 153 assert.Equal(t, expectedTags, tags) 154 assert.Equal(t, map[string]interface{}{"text": "some text"}, nestedObj) 155 assert.Equal(t, map[string]interface{}{"text": "some text"}, nestedObjEntry) 156 } 157 }) 158 } 159 160 t.Run("gRPC Search removed", func(t *testing.T) { 161 _, err := grpcClient.Search(context.TODO(), &pb.SearchRequest{}) 162 require.NotNil(t, err) 163 }) 164 }