Skip to content

Commit

Permalink
build: get the build passing (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi-automation authored and NimJay committed Nov 11, 2022
1 parent f882c34 commit 67ac729
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 25 deletions.
3 changes: 2 additions & 1 deletion game-servers/snippets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"devDependencies": {
"c8": "^5.0.1",
"chai": "^4.2.0",
"mocha": "^6.1.4"
"mocha": "^6.1.4",
"uuid": "^7.0.1"
}
}
51 changes: 32 additions & 19 deletions game-servers/snippets/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,50 @@

'use strict';

// sample-metadata:
// title: Create Game Server Realm
// description: Creates a new Realm within Cloud Game Servers
// usage: node quickstart.js <project_id> <location> <realmId>

/**
* Create a Game Servers realm.
* @param {string} projectId string project identifier.
* @param {string} location Compute Engine region.
*/
async function main(projectId, location) {
async function main(projectId, location, realmId) {
// [START game_servers_quickstart]
const {RealmsServiceClient} = require('@google-cloud/game-servers');

const client = new RealmsServiceClient();
async function quickstart() {
const client = new RealmsServiceClient();

// TODO(developer): uncomment the following section, and add values
// const projectId = 'YOUR_PROJECT_ID';
// const location = 'us-central1;
// const realIm = 'DESIRED_REALM_ID';

const request = {
parent: `projects/${projectId}/locations/${location}`,
realmId: 'my-realm',
realm: {
// Must use a valid support time zone.
// See https://cloud.google.com/dataprep/docs/html/Supported-Time-Zone-Values_66194188
timeZone: 'US/Pacific',
description: 'My Game Server realm',
},
};
const request = {
parent: `projects/${projectId}/locations/${location}`,
realmId,
realm: {
// Must use a valid support time zone.
// See https://cloud.google.com/dataprep/docs/html/Supported-Time-Zone-Values_66194188
timeZone: 'US/Pacific',
description: 'My Game Server realm',
},
};

const [operation] = await client.createRealm(request);
const results = await operation.promise();
const [realm] = results;
const [operation] = await client.createRealm(request);
const results = await operation.promise();
const [realm] = results;

console.log('Realm created:');
console.log('Realm created:');

console.log(`\tRealm name: ${realm.name}`);
console.log(`\tRealm description: ${realm.description}`);
console.log(`\tRealm time zone: ${realm.timeZone}`);
console.log(`\tRealm name: ${realm.name}`);
console.log(`\tRealm description: ${realm.description}`);
console.log(`\tRealm time zone: ${realm.timeZone}`);
}
quickstart();
// [END game_servers_quickstart]
}

Expand Down
28 changes: 23 additions & 5 deletions game-servers/snippets/test/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,35 @@

'use strict';

const path = require('path');
const {assert} = require('chai');
const cp = require('child_process');
const {describe, it} = require('mocha');
const {describe, it, after, before} = require('mocha');
const uuid = require('uuid');
const {RealmsServiceClient} = require('@google-cloud/game-servers');

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

const cwd = path.join(__dirname, '..');

describe('Quickstart', () => {
let projectId;
let client;
const location = 'us-central1';
const realmId = `realm-${uuid.v4().split('-')[0]}`;

before(async () => {
client = new RealmsServiceClient();
projectId = await client.getProjectId();
});

it('should run quickstart', async () => {
const stdout = execSync(`node quickstart.js`, {cwd});
const stdout = execSync(
`node quickstart.js ${projectId} ${location} ${realmId}`
);
assert.include(stdout, 'Realm created:');
});

after(async () => {
await client.deleteRealm({
name: client.realmPath(projectId, location, realmId),
});
});
});

0 comments on commit 67ac729

Please sign in to comment.