github.com/weaviate/weaviate@v1.24.6/test/acceptance/graphql_resolvers/local_get_shadow_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 import ( 15 "encoding/json" 16 "testing" 17 18 "github.com/stretchr/testify/assert" 19 "github.com/weaviate/weaviate/test/helper" 20 graphqlhelper "github.com/weaviate/weaviate/test/helper/graphql" 21 ) 22 23 // run by setup_test.go 24 func runningGetNearObjectWithShadowedObjects(t *testing.T) { 25 t.Run("running Get nearObject against shadow class", func(t *testing.T) { 26 query := ` 27 { 28 Get { 29 NearObjectSearch ( 30 nearObject: { 31 id : "aa44bbee-ca5f-4db7-a412-5fc6a2300001" 32 certainty: 0.98 33 } 34 ) { 35 name 36 } 37 } 38 } 39 ` 40 41 for i := 0; i < 50; i++ { 42 result := graphqlhelper.AssertGraphQL(t, helper.RootAuth, query) 43 objs := result.Get("Get", "NearObjectSearch").AsSlice() 44 45 expected := []interface{}{ 46 map[string]interface{}{"name": "Mount Everest"}, 47 } 48 49 assert.Len(t, objs, 1) 50 assert.ElementsMatch(t, expected, objs) 51 } 52 }) 53 } 54 55 func runningAggregateNearObjectWithShadowedObjects(t *testing.T) { 56 t.Run("running Aggregate nearObject against shadow class", func(t *testing.T) { 57 query := ` 58 { 59 Aggregate { 60 NearObjectSearch ( 61 nearObject: { 62 id : "aa44bbee-ca5f-4db7-a412-5fc6a2300001" 63 certainty: 0.98 64 } 65 ) { 66 meta { 67 count 68 } 69 } 70 } 71 } 72 ` 73 74 for i := 0; i < 50; i++ { 75 result := graphqlhelper.AssertGraphQL(t, helper.RootAuth, query) 76 meta := result.Get("Aggregate", "NearObjectSearch").AsSlice()[0].(map[string]interface{})["meta"] 77 count := meta.(map[string]interface{})["count"] 78 expected := json.Number("1") 79 assert.Equal(t, expected, count) 80 } 81 }) 82 } 83 84 func runningExploreNearObjectWithShadowedObjects(t *testing.T) { 85 t.Run("running Explore nearObject against shadow class with same contents", func(t *testing.T) { 86 query := ` 87 { 88 Explore ( 89 nearObject: { 90 id : "aa44bbee-ca5f-4db7-a412-5fc6a2300011" 91 certainty: 0.98 92 } 93 ) { 94 beacon 95 } 96 } 97 ` 98 99 for i := 0; i < 50; i++ { 100 result := graphqlhelper.AssertGraphQL(t, helper.RootAuth, query) 101 objs := result.Get("Explore").AsSlice() 102 103 expected := []interface{}{ 104 map[string]interface{}{"beacon": "weaviate://localhost/NearObjectSearch/aa44bbee-ca5f-4db7-a412-5fc6a2300011"}, 105 map[string]interface{}{"beacon": "weaviate://localhost/NearObjectSearchShadow/aa44bbee-ca5f-4db7-a412-5fc6a2300011"}, 106 } 107 108 assert.Len(t, objs, 2) 109 assert.ElementsMatch(t, expected, objs) 110 } 111 }) 112 113 t.Run("running Explore nearObject against shadow class with different contents", func(t *testing.T) { 114 query := ` 115 { 116 Explore ( 117 nearObject: { 118 id : "aa44bbee-ca5f-4db7-a412-5fc6a2300001" 119 certainty: 0.98 120 } 121 ) { 122 beacon 123 } 124 } 125 ` 126 127 for i := 0; i < 50; i++ { 128 result := graphqlhelper.AssertGraphQL(t, helper.RootAuth, query) 129 objs := result.Get("Explore").AsSlice() 130 131 expected := []interface{}{ 132 map[string]interface{}{"beacon": "weaviate://localhost/NearObjectSearch/aa44bbee-ca5f-4db7-a412-5fc6a2300001"}, 133 map[string]interface{}{"beacon": "weaviate://localhost/NearObjectSearchShadow/aa44bbee-ca5f-4db7-a412-5fc6a2300001"}, 134 } 135 136 assert.Len(t, objs, 2) 137 assert.ElementsMatch(t, expected, objs) 138 } 139 }) 140 }