Skip to content

Commit 37dd210

Browse files
build: get the build passing (#17)
1 parent 80f618f commit 37dd210

File tree

3 files changed

+57
-25
lines changed

3 files changed

+57
-25
lines changed

cloud-game-servers/snippets/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"devDependencies": {
1919
"c8": "^5.0.1",
2020
"chai": "^4.2.0",
21-
"mocha": "^6.1.4"
21+
"mocha": "^6.1.4",
22+
"uuid": "^7.0.1"
2223
}
2324
}

cloud-game-servers/snippets/quickstart.js

+32-19
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,50 @@
1313

1414
'use strict';
1515

16+
// sample-metadata:
17+
// title: Create Game Server Realm
18+
// description: Creates a new Realm within Cloud Game Servers
19+
// usage: node quickstart.js <project_id> <location> <realmId>
20+
1621
/**
1722
* Create a Game Servers realm.
1823
* @param {string} projectId string project identifier.
1924
* @param {string} location Compute Engine region.
2025
*/
21-
async function main(projectId, location) {
26+
async function main(projectId, location, realmId) {
2227
// [START game_servers_quickstart]
2328
const {RealmsServiceClient} = require('@google-cloud/game-servers');
2429

25-
const client = new RealmsServiceClient();
30+
async function quickstart() {
31+
const client = new RealmsServiceClient();
32+
33+
// TODO(developer): uncomment the following section, and add values
34+
// const projectId = 'YOUR_PROJECT_ID';
35+
// const location = 'us-central1;
36+
// const realIm = 'DESIRED_REALM_ID';
2637

27-
const request = {
28-
parent: `projects/${projectId}/locations/${location}`,
29-
realmId: 'my-realm',
30-
realm: {
31-
// Must use a valid support time zone.
32-
// See https://cloud.google.com/dataprep/docs/html/Supported-Time-Zone-Values_66194188
33-
timeZone: 'US/Pacific',
34-
description: 'My Game Server realm',
35-
},
36-
};
38+
const request = {
39+
parent: `projects/${projectId}/locations/${location}`,
40+
realmId,
41+
realm: {
42+
// Must use a valid support time zone.
43+
// See https://cloud.google.com/dataprep/docs/html/Supported-Time-Zone-Values_66194188
44+
timeZone: 'US/Pacific',
45+
description: 'My Game Server realm',
46+
},
47+
};
3748

38-
const [operation] = await client.createRealm(request);
39-
const results = await operation.promise();
40-
const [realm] = results;
49+
const [operation] = await client.createRealm(request);
50+
const results = await operation.promise();
51+
const [realm] = results;
4152

42-
console.log('Realm created:');
53+
console.log('Realm created:');
4354

44-
console.log(`\tRealm name: ${realm.name}`);
45-
console.log(`\tRealm description: ${realm.description}`);
46-
console.log(`\tRealm time zone: ${realm.timeZone}`);
55+
console.log(`\tRealm name: ${realm.name}`);
56+
console.log(`\tRealm description: ${realm.description}`);
57+
console.log(`\tRealm time zone: ${realm.timeZone}`);
58+
}
59+
quickstart();
4760
// [END game_servers_quickstart]
4861
}
4962

cloud-game-servers/snippets/test/quickstart.js

+23-5
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,35 @@
1818

1919
'use strict';
2020

21-
const path = require('path');
2221
const {assert} = require('chai');
2322
const cp = require('child_process');
24-
const {describe, it} = require('mocha');
23+
const {describe, it, after, before} = require('mocha');
24+
const uuid = require('uuid');
25+
const {RealmsServiceClient} = require('@google-cloud/game-servers');
2526

2627
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2728

28-
const cwd = path.join(__dirname, '..');
29-
3029
describe('Quickstart', () => {
30+
let projectId;
31+
let client;
32+
const location = 'us-central1';
33+
const realmId = `realm-${uuid.v4().split('-')[0]}`;
34+
35+
before(async () => {
36+
client = new RealmsServiceClient();
37+
projectId = await client.getProjectId();
38+
});
39+
3140
it('should run quickstart', async () => {
32-
const stdout = execSync(`node quickstart.js`, {cwd});
41+
const stdout = execSync(
42+
`node quickstart.js ${projectId} ${location} ${realmId}`
43+
);
44+
assert.include(stdout, 'Realm created:');
45+
});
46+
47+
after(async () => {
48+
await client.deleteRealm({
49+
name: client.realmPath(projectId, location, realmId),
50+
});
3351
});
3452
});

0 commit comments

Comments
 (0)