Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Testcontainers example with Node.js #1620

Merged
merged 1 commit into from
May 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions examples/node/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
### Usage with Testcontainers

See [Java example's
README](https://github.com/fsouza/fake-gcs-server/tree/main/examples/java#resumable-upload-operations-and-containerised-fake-gcs-server)
for context.

```ts
import { Storage } from "@google-cloud/storage";
import ky from "ky";
import { GenericContainer } from "testcontainers";

const PORT = 4443;

const CONTAINER = await new GenericContainer("fsouza/fake-gcs-server:1.49.0")
.withEntrypoint(["/bin/fake-gcs-server", "-scheme", "http"])
.withExposedPorts(PORT)
.start();

const API_ENDPOINT = `http://${CONTAINER.getHost()}:${CONTAINER.getMappedPort(
PORT
)}`;

await ky.put(`${API_ENDPOINT}/_internal/config`, {
json: { externalUrl: API_ENDPOINT },
});

const STORAGE = new Storage({ apiEndpoint: API_ENDPOINT });

// ...
```