|
1 | 1 | import { Datastore } from "@google-cloud/datastore"; |
2 | 2 | import { getImage } from "../../../testcontainers/src/utils/test-helper"; |
3 | | -import { DatastoreEmulatorContainer, StartedDatastoreEmulatorContainer } from "./datastore-emulator-container"; |
| 3 | +import { DatastoreEmulatorContainer } from "./datastore-emulator-container"; |
4 | 4 |
|
5 | 5 | const IMAGE = getImage(__dirname); |
6 | 6 |
|
7 | 7 | describe("DatastoreEmulatorContainer", { timeout: 240_000 }, () => { |
8 | | - // datastore4 { |
9 | | - it("should work using default version", async () => { |
10 | | - await using datastoreEmulatorContainer = await new DatastoreEmulatorContainer(IMAGE).start(); |
11 | | - |
12 | | - await checkDatastore(datastoreEmulatorContainer); |
13 | | - }); |
14 | | - // } |
15 | | - |
16 | | - // datastore5 { |
17 | | - it("should work using version 468.0.0", async () => { |
18 | | - await using datastoreEmulatorContainer = await new DatastoreEmulatorContainer( |
19 | | - "gcr.io/google.com/cloudsdktool/google-cloud-cli:468.0.0-emulators" |
20 | | - ).start(); |
21 | | - |
22 | | - await checkDatastore(datastoreEmulatorContainer); |
23 | | - }); |
24 | | - |
25 | | - // } |
26 | | - |
27 | | - async function checkDatastore(datastoreEmulatorContainer: StartedDatastoreEmulatorContainer) { |
28 | | - expect(datastoreEmulatorContainer).toBeDefined(); |
29 | | - const testProjectId = "test-project"; |
30 | | - const testKind = "test-kind"; |
31 | | - const testId = "123"; |
32 | | - const databaseConfig = { |
33 | | - projectId: testProjectId, |
34 | | - apiEndpoint: datastoreEmulatorContainer.getEmulatorEndpoint(), |
35 | | - }; |
36 | | - const datastore = new Datastore(databaseConfig); |
37 | | - |
38 | | - const key = datastore.key([testKind, testId]); |
39 | | - const data = { message: "Hello, Datastore!" }; |
40 | | - await datastore.save({ key, data }); |
41 | | - const [entity] = await datastore.get(key); |
42 | | - |
43 | | - expect(entity).toEqual({ |
44 | | - message: "Hello, Datastore!", |
45 | | - [Datastore.KEY]: key, |
46 | | - }); |
47 | | - } |
| 8 | + it.each([IMAGE, "gcr.io/google.com/cloudsdktool/google-cloud-cli:468.0.0-emulators"])( |
| 9 | + "should work with %s", |
| 10 | + async (image) => { |
| 11 | + // datastoreExample { |
| 12 | + await using container = await new DatastoreEmulatorContainer(image).start(); |
| 13 | + |
| 14 | + const datastore = new Datastore({ |
| 15 | + projectId: "test-project", |
| 16 | + apiEndpoint: container.getEmulatorEndpoint(), |
| 17 | + }); |
| 18 | + |
| 19 | + const key = datastore.key(["test-kind", "123"]); |
| 20 | + const data = { message: "Hello, Datastore!" }; |
| 21 | + await datastore.save({ key, data }); |
| 22 | + const [entity] = await datastore.get(key); |
| 23 | + |
| 24 | + expect(entity).toEqual({ message: "Hello, Datastore!", [Datastore.KEY]: key }); |
| 25 | + // } |
| 26 | + } |
| 27 | + ); |
48 | 28 | }); |
0 commit comments