-
-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4d56ba
commit ec31708
Showing
9 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Weaviate Module | ||
|
||
[Weaviate](https://weaviate.io//) is an open source, AI-native vector database that helps | ||
developers create intuitive and reliable AI-powered applications.. | ||
|
||
## Install | ||
|
||
```bash | ||
npm install @testcontainers/weaviate --save-dev | ||
``` | ||
|
||
## Examples | ||
|
||
<!--codeinclude--> | ||
[Connect to Weaviate:](../../packages/modules/weaviate/src/weaviate-container.test.ts) | ||
inside_block:connect | ||
<!--/codeinclude--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { Config } from "jest"; | ||
import * as path from "path"; | ||
|
||
const config: Config = { | ||
preset: "ts-jest", | ||
moduleNameMapper: { | ||
"^testcontainers$": path.resolve(__dirname, "../../testcontainers/src"), | ||
}, | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "@testcontainers/weaviate", | ||
"version": "10.7.2", | ||
"license": "MIT", | ||
"keywords": [ | ||
"weaviate", | ||
"testing", | ||
"docker", | ||
"testcontainers" | ||
], | ||
"description": "Weaviate module for Testcontainers", | ||
"homepage": "https://github.com/testcontainers/testcontainers-node#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/testcontainers/testcontainers-node" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/testcontainers/testcontainers-node/issues" | ||
}, | ||
"main": "build/index.js", | ||
"files": [ | ||
"build" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"prepack": "shx cp ../../../README.md . && shx cp ../../../LICENSE .", | ||
"build": "tsc --project tsconfig.build.json" | ||
}, | ||
|
||
"devDependencies": { | ||
"weaviate-ts-client": "^2.1.0" | ||
}, | ||
"dependencies": { | ||
"testcontainers": "^10.7.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { WeaviateContainer, StartedWeaviateContainer } from "./weaviate-container"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { WeaviateContainer } from "./weaviate-container"; | ||
import weaviate from "weaviate-ts-client"; | ||
|
||
describe("WeaviateContainer", () => { | ||
jest.setTimeout(100_000); | ||
|
||
// expose { | ||
it("should expose ports", async () => { | ||
const container = await new WeaviateContainer().start(); | ||
|
||
expect(container.getRestHostAddress()).toBeDefined() | ||
expect(container.getGrpcHostAddress()).toBeDefined() | ||
|
||
await container.stop(); | ||
}); | ||
// } | ||
|
||
// connect { | ||
it("should connect to Weaviate", async () => { | ||
const container = await new WeaviateContainer().start(); | ||
|
||
const client = weaviate.client({ | ||
scheme: 'http', | ||
host: container.getRestHostAddress(), | ||
}); | ||
|
||
client.misc | ||
.metaGetter() | ||
.do() | ||
.then((res: any) => { | ||
expect(res.version).toBeDefined(); | ||
}) | ||
.catch((e: any) => { | ||
throw new Error('it should not have errord: ' + e); | ||
}); | ||
|
||
await container.stop(); | ||
}); | ||
// } | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { AbstractStartedContainer, GenericContainer, StartedTestContainer, Wait } from "testcontainers"; | ||
|
||
const WEAVIATE_REST_PORT = 8080; | ||
const WEAVIATE_GRPC_PORT = 50051; | ||
|
||
export class WeaviateContainer extends GenericContainer { | ||
constructor(image = "semitechnologies/weaviate:1.24.5") { | ||
super(image); | ||
this.withCommand(["--host", "0.0.0.0", "--scheme", "http", "--port", "8080"]) | ||
this.withExposedPorts(WEAVIATE_REST_PORT, WEAVIATE_GRPC_PORT); | ||
this.withEnvironment({ | ||
QUERY_DEFAULTS_LIMIT: "25", | ||
AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: "true", | ||
PERSISTENCE_DATA_PATH: "/var/lib/weaviate", | ||
DEFAULT_VECTORIZER_MODULE: "none", | ||
CLUSTER_HOSTNAME: "node1", | ||
}) | ||
this.withWaitStrategy( | ||
Wait.forAll([ | ||
Wait.forListeningPorts(), | ||
Wait.forHttp("/v1/.well-known/ready", WEAVIATE_REST_PORT), | ||
]).withStartupTimeout(5_000) | ||
); | ||
} | ||
|
||
public override async start(): Promise<StartedWeaviateContainer> { | ||
return new StartedWeaviateContainer(await super.start()); | ||
} | ||
} | ||
|
||
export class StartedWeaviateContainer extends AbstractStartedContainer { | ||
constructor(startedTestContainer: StartedTestContainer) { | ||
super(startedTestContainer); | ||
} | ||
|
||
public getRestHostAddress(): string { | ||
return `${this.getHost()}:${this.getMappedPort(WEAVIATE_REST_PORT)}` | ||
} | ||
|
||
public getGrpcHostAddress(): string { | ||
return `${this.getHost()}:${this.getMappedPort(WEAVIATE_GRPC_PORT)}` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"exclude": [ | ||
"build", | ||
"jest.config.ts", | ||
"src/**/*.test.ts", | ||
"src/test_config.yaml" | ||
], | ||
"references": [ | ||
{ | ||
"path": "../../testcontainers" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"extends": "../../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "build", | ||
"paths": { | ||
"testcontainers": [ | ||
"../../testcontainers/src" | ||
] | ||
} | ||
}, | ||
"exclude": [ | ||
"build", | ||
"jest.config.ts" | ||
], | ||
"references": [ | ||
{ | ||
"path": "../../testcontainers" | ||
} | ||
] | ||
} |