github.com/weaviate/weaviate@v1.24.6/test/acceptance/cluster_api_auth/cluster_api_auth_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 "context" 16 "testing" 17 "time" 18 19 "github.com/stretchr/testify/assert" 20 "github.com/stretchr/testify/require" 21 "github.com/weaviate/weaviate/client/nodes" 22 "github.com/weaviate/weaviate/test/docker" 23 "github.com/weaviate/weaviate/test/helper" 24 graphqlhelper "github.com/weaviate/weaviate/test/helper/graphql" 25 "github.com/weaviate/weaviate/test/helper/sample-schema/books" 26 ) 27 28 func TestClusterAPIAuth(t *testing.T) { 29 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) 30 defer cancel() 31 32 compose, err := docker.New(). 33 WithWeaviateClusterWithBasicAuth("user", "pass"). 34 WithText2VecContextionary(). 35 Start(ctx) 36 require.Nil(t, err) 37 defer func() { 38 if err := compose.Terminate(ctx); err != nil { 39 t.Fatalf("failed to terminate test containers: %v", err) 40 } 41 }() 42 43 helper.SetupClient(compose.GetWeaviate().URI()) 44 45 t.Run("sanity checks", func(t *testing.T) { 46 t.Run("check nodes", func(t *testing.T) { 47 resp, err := helper.Client(t).Nodes.NodesGet(nodes.NewNodesGetParams(), nil) 48 require.Nil(t, err) 49 50 nodeStatusResp := resp.GetPayload() 51 require.NotNil(t, nodeStatusResp) 52 53 nodes := nodeStatusResp.Nodes 54 require.NotNil(t, nodes) 55 require.Len(t, nodes, 2) 56 }) 57 58 booksClass := books.ClassContextionaryVectorizer() 59 helper.CreateClass(t, booksClass) 60 defer helper.DeleteClass(t, booksClass.Class) 61 62 t.Run("import data", func(t *testing.T) { 63 helper.CreateObjectsBatch(t, books.Objects()) 64 }) 65 66 t.Run("nearText query", func(t *testing.T) { 67 query := ` 68 { 69 Get { 70 Books( 71 nearText: { 72 concepts: ["Frank Herbert"] 73 } 74 ){ 75 title 76 } 77 } 78 }` 79 result := graphqlhelper.AssertGraphQL(t, helper.RootAuth, query) 80 books := result.Get("Get", "Books").AsSlice() 81 require.True(t, len(books) > 0) 82 results, ok := books[0].(map[string]interface{}) 83 require.True(t, ok) 84 assert.True(t, results["title"] != nil) 85 }) 86 }) 87 }