From a245b316640ac9cff5e77c538d2e05ce03dd786b Mon Sep 17 00:00:00 2001 From: Alec Mev Date: Thu, 30 May 2024 03:18:34 +0100 Subject: [PATCH] Add Testcontainers example with Node.js (#1620) --- examples/node/README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 examples/node/README.md diff --git a/examples/node/README.md b/examples/node/README.md new file mode 100644 index 0000000000..527559517e --- /dev/null +++ b/examples/node/README.md @@ -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 }); + +// ... +```