-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Testcontainers example with Node.js (#1620)
- Loading branch information
Showing
1 changed file
with
30 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,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 }); | ||
|
||
// ... | ||
``` |