diff --git a/modules/weaviate/weaviate.go b/modules/weaviate/weaviate.go index 0cd3b1c020..b844a9e2b5 100644 --- a/modules/weaviate/weaviate.go +++ b/modules/weaviate/weaviate.go @@ -5,14 +5,14 @@ import ( "fmt" "time" - "github.com/docker/go-connections/nat" "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" ) const ( - httpPort = nat.Port("8080/tcp") - grpcPort = nat.Port("50051/tcp") + image = "semitechnologies/weaviate:1.24.6" + httpPort = "8080/tcp" + grpcPort = "50051/tcp" ) // WeaviateContainer represents the Weaviate container type used in the module @@ -23,9 +23,9 @@ type WeaviateContainer struct { // RunContainer creates an instance of the Weaviate container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*WeaviateContainer, error) { req := testcontainers.ContainerRequest{ - Image: "semitechnologies/weaviate:1.24.5", - Cmd: []string{"--host", "0.0.0.0", "--scheme", "http", "--port", httpPort.Port()}, - ExposedPorts: []string{string(httpPort), string(grpcPort)}, + Image: image, + Cmd: []string{"--host", "0.0.0.0", "--scheme", "http", "--port", "8080"}, + ExposedPorts: []string{httpPort, grpcPort}, Env: map[string]string{ "AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED": "true", "PERSISTENCE_DATA_PATH": "/var/lib/weaviate", @@ -53,36 +53,34 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize return &WeaviateContainer{Container: container}, nil } -func (c *WeaviateContainer) getHostAddress(ctx context.Context, port nat.Port) (string, error) { - containerPort, err := c.MappedPort(ctx, port) +// HttpHostAddress returns the schema and host of the Weaviate container. +// At the moment, it only supports the http scheme. +func (c *WeaviateContainer) HttpHostAddress(ctx context.Context) (string, string, error) { + port, err := c.MappedPort(ctx, httpPort) if err != nil { - return "", fmt.Errorf("failed to get container port: %w", err) + return "", "", fmt.Errorf("failed to get container port: %w", err) } host, err := c.Host(ctx) if err != nil { - return "", fmt.Errorf("failed to get container host") + return "", "", fmt.Errorf("failed to get container host") } - return fmt.Sprintf("%s:%s", host, containerPort.Port()), nil -} - -// HttpHostAddress returns the schema and host of the Weaviate container. -// At the moment, it only supports the http scheme. -func (c *WeaviateContainer) HttpHostAddress(ctx context.Context) (string, string, error) { - httpHostAddress, err := c.getHostAddress(ctx, httpPort) - if err != nil { - return "", "", err - } - return "http", httpHostAddress, nil + return "http", fmt.Sprintf("%s:%s", host, port.Port()), nil } // GrpcHostAddress returns the gRPC host of the Weaviate container. // At the moment, it only supports unsecured gRPC connection. func (c *WeaviateContainer) GrpcHostAddress(ctx context.Context) (string, error) { - grpcHostAddress, err := c.getHostAddress(ctx, grpcPort) + port, err := c.MappedPort(ctx, grpcPort) if err != nil { - return "", err + return "", fmt.Errorf("failed to get container port: %w", err) } - return grpcHostAddress, nil + + host, err := c.Host(ctx) + if err != nil { + return "", fmt.Errorf("failed to get container host") + } + + return fmt.Sprintf("%s:%s", host, port.Port()), nil }