Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type WeaviateContainer ¶
type WeaviateContainer struct {
testcontainers.Container
}
WeaviateContainer represents the Weaviate container type used in the module
func Run ¶ added in v0.32.0
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*WeaviateContainer, error)
Run creates an instance of the Weaviate container type
Example ¶
// runWeaviateContainer {
ctx := context.Background()
weaviateContainer, err := tcweaviate.Run(ctx, "semitechnologies/weaviate:1.29.0")
defer func() {
if err := testcontainers.TerminateContainer(weaviateContainer); err != nil {
log.Printf("failed to terminate container: %s", err)
}
}()
if err != nil {
log.Printf("failed to start container: %s", err)
return
}
// }
state, err := weaviateContainer.State(ctx)
if err != nil {
log.Printf("failed to get container state: %s", err)
return
}
fmt.Println(state.Running)
Output: true
Example (ConnectWithClient) ¶
// createClientNoModules {
ctx := context.Background()
weaviateContainer, err := tcweaviate.Run(ctx, "semitechnologies/weaviate:1.28.7")
defer func() {
if err := testcontainers.TerminateContainer(weaviateContainer); err != nil {
log.Printf("failed to terminate container: %s", err)
}
}()
if err != nil {
log.Printf("failed to start container: %s", err)
return
}
scheme, host, err := weaviateContainer.HttpHostAddress(ctx)
if err != nil {
log.Printf("failed to get http schema and host: %s", err)
return
}
grpcHost, err := weaviateContainer.GrpcHostAddress(ctx)
if err != nil {
log.Printf("failed to get gRPC host: %s", err)
return
}
connectionClient := &http.Client{}
headers := map[string]string{
// put here the custom API key, e.g. for OpenAPI
"Authorization": "Bearer custom-api-key",
}
cli := weaviate.New(weaviate.Config{
Scheme: scheme,
Host: host,
GrpcConfig: &grpc.Config{
Secured: false, // set true if gRPC connection is secured
Host: grpcHost,
},
Headers: headers,
AuthConfig: nil, // put here the weaviate auth.Config, if you need it
ConnectionClient: connectionClient,
})
err = cli.WaitForWeavaite(5 * time.Second)
// }
fmt.Println(err)
Output: <nil>
Example (ConnectWithClientWithModules) ¶
// createClientAndModules {
ctx := context.Background()
enableModules := []string{
"backup-filesystem",
"text2vec-openai",
"text2vec-cohere",
"text2vec-huggingface",
"generative-openai",
}
envs := map[string]string{
"ENABLE_MODULES": strings.Join(enableModules, ","),
"BACKUP_FILESYSTEM_PATH": "/tmp/backups",
}
opts := []testcontainers.ContainerCustomizer{
testcontainers.WithEnv(envs),
}
weaviateContainer, err := tcweaviate.Run(ctx, "semitechnologies/weaviate:1.25.5", opts...)
defer func() {
if err := testcontainers.TerminateContainer(weaviateContainer); err != nil {
log.Printf("failed to terminate container: %s", err)
}
}()
if err != nil {
log.Printf("failed to start container: %s", err)
return
}
// httpHostAddress {
scheme, host, err := weaviateContainer.HttpHostAddress(ctx)
if err != nil {
log.Printf("failed to get http schema and host: %s", err)
return
}
// }
// grpcHostAddress {
grpcHost, err := weaviateContainer.GrpcHostAddress(ctx)
if err != nil {
log.Printf("failed to get gRPC host: %s", err)
return
}
// }
connectionClient := &http.Client{}
headers := map[string]string{
// put here the custom API key, e.g. for OpenAPI
"Authorization": "Bearer custom-api-key",
}
cli := weaviate.New(weaviate.Config{
Scheme: scheme,
Host: host,
GrpcConfig: &grpc.Config{
Secured: false, // set true if gRPC connection is secured
Host: grpcHost,
},
Headers: headers,
AuthConfig: nil, // put here the weaviate auth.Config, if you need it
ConnectionClient: connectionClient,
})
err = cli.WaitForWeavaite(5 * time.Second)
// }
fmt.Println(err)
Output: <nil>
func RunContainer
deprecated
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*WeaviateContainer, error)
Deprecated: use Run instead RunContainer creates an instance of the Weaviate container type
func (*WeaviateContainer) GrpcHostAddress ¶ added in v0.30.0
func (c *WeaviateContainer) GrpcHostAddress(ctx context.Context) (string, error)
GrpcHostAddress returns the gRPC host of the Weaviate container. At the moment, it only supports unsecured gRPC connection.
func (*WeaviateContainer) HttpHostAddress ¶
HttpHostAddress returns the schema and host of the Weaviate container. At the moment, it only supports the http scheme.
Click to show internal directories.
Click to hide internal directories.