github.com/weaviate/weaviate@v1.24.6/test/helper/operations_client.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 // This file contains the Client(t *testing.T) function, that can be used to construct a client that talks to 13 // the Weaviate server that is configured using command line arguments (see init.go). 14 // 15 // We pass in the test (*testing.T), to be able to log HTTP traffic to that specific test case. 16 // This allows us to get detailed logs of the performed HTTP requests if a acceptance test fails. 17 18 // The CreateAuth returns a function that attaches the key and token headers to each HTTP call. 19 20 // Example: 21 // func TestSomething(t *testing.T) { 22 // // Use specific key & token 23 // auth := helper.CreateAuth(key, token) 24 // helper.Client(t).SomeScope.SomeOperation(&someParams, auth) 25 // 26 // // Use root key & token 27 // helper.Client(t).SomeScope.SomeOperation(&someParams, helper.RootAuth) 28 // } 29 30 package helper 31 32 import ( 33 "fmt" 34 "testing" 35 36 httptransport "github.com/go-openapi/runtime/client" 37 "github.com/go-openapi/strfmt" 38 "github.com/weaviate/weaviate/client/batch" 39 operations_apiclient "github.com/weaviate/weaviate/client/operations" 40 ) 41 42 // Create a client that logs with t.Logf, if a *testing.T is provided. 43 // If there is no test case at hand, pass in nil to disable logging. 44 func OperationsClient(t *testing.T) operations_apiclient.ClientService { 45 transport := httptransport.New(fmt.Sprintf("%s:%s", ServerHost, ServerPort), "/v1", []string{ServerScheme}) 46 47 // If a test case is provided, and we want to dump HTTP traffic, 48 // create a simple logger that logs HTTP traffic to the test case. 49 if t != nil && DebugHTTP { 50 transport.SetDebug(true) 51 transport.SetLogger(&testLogger{t: t}) 52 } 53 54 client := operations_apiclient.New(transport, strfmt.Default) 55 return client 56 } 57 58 // Create a client that logs with t.Logf, if a *testing.T is provided. 59 // If there is no test case at hand, pass in nil to disable logging. 60 func BatchClient(t *testing.T) batch.ClientService { 61 transport := httptransport.New(fmt.Sprintf("%s:%s", ServerHost, ServerPort), "/v1", []string{ServerScheme}) 62 63 // If a test case is provided, and we want to dump HTTP traffic, 64 // create a simple logger that logs HTTP traffic to the test case. 65 if t != nil && DebugHTTP { 66 transport.SetDebug(true) 67 transport.SetLogger(&testLogger{t: t}) 68 } 69 70 client := batch.New(transport, strfmt.Default) 71 return client 72 }