Skip to content

Commit 78f01cf

Browse files
Gcloud WIP
1 parent b0e0fb3 commit 78f01cf

File tree

3 files changed

+26
-55
lines changed

3 files changed

+26
-55
lines changed

docs/modules/gcloud.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,11 @@ These examples use the following libraries:
3333
npm install @google-cloud/datastore
3434

3535
Choose an image from the [container registry](https://gcr.io/google.com/cloudsdktool/google-cloud-cli) and substitute `IMAGE`.
36-
37-
#### With default image
38-
39-
<!--codeinclude-->
40-
[](../../packages/modules/gcloud/src/datastore-emulator-container.test.ts) inside_block:datastore4
41-
<!--/codeinclude-->
42-
43-
#### With custom image
44-
36+
4537
<!--codeinclude-->
46-
[](../../packages/modules/gcloud/src/datastore-emulator-container.test.ts) inside_block:datastore5
38+
[](../../packages/modules/gcloud/src/datastore-emulator-container.test.ts) inside_block:datastoreExample
4739
<!--/codeinclude-->
48-
40+
4941
---
5042

5143
### Cloud PubSub
Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,28 @@
11
import { Datastore } from "@google-cloud/datastore";
22
import { getImage } from "../../../testcontainers/src/utils/test-helper";
3-
import { DatastoreEmulatorContainer, StartedDatastoreEmulatorContainer } from "./datastore-emulator-container";
3+
import { DatastoreEmulatorContainer } from "./datastore-emulator-container";
44

55
const IMAGE = getImage(__dirname);
66

77
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+
);
4828
});

packages/modules/gcloud/src/firestore-emulator-container.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ describe("FirestoreEmulatorContainer", { timeout: 240_000 }, () => {
1313
const collection = "test-collection";
1414
const document = "test-doc";
1515

16-
await using firestoreEmulatorContainer = await new FirestoreEmulatorContainer(image).start();
16+
await using container = await new FirestoreEmulatorContainer(image).start();
1717

1818
const firestore = admin.initializeApp({ projectId: "test-project" }, `test-app-${randomUuid()}`).firestore();
19-
2019
firestore.settings({
21-
host: firestoreEmulatorContainer.getEmulatorEndpoint(),
20+
host: container.getEmulatorEndpoint(),
2221
ssl: false,
2322
});
2423

0 commit comments

Comments
 (0)