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