Skip to content

Commit

Permalink
Add Testcontainers example with Node.js (#1620)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecmev authored May 30, 2024
1 parent 67b79bf commit a245b31
Showing 1 changed file with 30 additions and 0 deletions.
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 });

// ...
```

0 comments on commit a245b31

Please sign in to comment.