-
-
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
678b44f
commit 155f8fa
Showing
10 changed files
with
343 additions
and
4 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,22 @@ | ||
# 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:connectWeaviateWithClient | ||
<!--/codeinclude--> | ||
|
||
<!--codeinclude--> | ||
[Connect to Weaviate with modules defined:](../../packages/modules/weaviate/src/weaviate-container.test.ts) | ||
inside_block:connectWeaviateWithModules | ||
<!--/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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,81 @@ | ||
import { Environment } from "testcontainers/src/types"; | ||
import { WeaviateContainer } from "./weaviate-container"; | ||
import weaviate from "weaviate-ts-client"; | ||
|
||
describe("WeaviateContainer", () => { | ||
jest.setTimeout(100_000); | ||
|
||
// connectWeaviate { | ||
it("should expose ports", async () => { | ||
const container = await new WeaviateContainer().start(); | ||
|
||
expect(container.getHttpHostAddress()).toBeDefined(); | ||
expect(container.getGrpcHostAddress()).toBeDefined(); | ||
|
||
await container.stop(); | ||
}); | ||
// } | ||
|
||
// connectWeaviateWithClient { | ||
it("should connect to Weaviate", async () => { | ||
const container = await new WeaviateContainer().start(); | ||
|
||
const client = weaviate.client({ | ||
scheme: "http", | ||
host: container.getHttpHostAddress(), | ||
}); | ||
|
||
client.misc | ||
.metaGetter() | ||
.do() | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
.then((res: any) => { | ||
expect(res.version).toBeDefined(); | ||
}) | ||
.catch((e: string) => { | ||
throw new Error(e); | ||
}); | ||
|
||
await container.stop(); | ||
}); | ||
// } | ||
|
||
// connectWeaviateWithModules { | ||
it("should connect to Weaviate with modules", async () => { | ||
const enableModules = [ | ||
"backup-filesystem", | ||
"text2vec-openai", | ||
"text2vec-cohere", | ||
"text2vec-huggingface", | ||
"generative-openai", | ||
]; | ||
const environment: Environment = { | ||
ENABLE_MODULES: enableModules.join(","), | ||
BACKUP_FILESYSTEM_PATH: "/tmp/backups", | ||
}; | ||
const container = await new WeaviateContainer().withEnvironment(environment).start(); | ||
|
||
const client = weaviate.client({ | ||
scheme: "http", | ||
host: container.getHttpHostAddress(), | ||
}); | ||
|
||
client.misc | ||
.metaGetter() | ||
.do() | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
.then((res: any) => { | ||
expect(res.version).toBeDefined(); | ||
expect(res.modules).toBeDefined(); | ||
enableModules.forEach((module) => { | ||
expect(res.modules[module]).toBeDefined(); | ||
}); | ||
}) | ||
.catch((e: string) => { | ||
throw new Error(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,40 @@ | ||
import { AbstractStartedContainer, GenericContainer, StartedTestContainer, Wait } from "testcontainers"; | ||
|
||
const WEAVIATE_HTTP_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", `${WEAVIATE_HTTP_PORT}`]); | ||
this.withExposedPorts(WEAVIATE_HTTP_PORT, WEAVIATE_GRPC_PORT); | ||
this.withEnvironment({ | ||
AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: "true", | ||
PERSISTENCE_DATA_PATH: "/var/lib/weaviate", | ||
}); | ||
this.withWaitStrategy( | ||
Wait.forAll([ | ||
Wait.forListeningPorts(), | ||
Wait.forHttp("/v1/.well-known/ready", WEAVIATE_HTTP_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 getHttpHostAddress(): string { | ||
return `${this.getHost()}:${this.getMappedPort(WEAVIATE_HTTP_PORT)}`; | ||
} | ||
|
||
public getGrpcHostAddress(): string { | ||
return `${this.getHost()}:${this.getMappedPort(WEAVIATE_GRPC_PORT)}`; | ||
} | ||
} |
Oops, something went wrong.