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 Mar 1, 2020
1 parent cf12904 commit dc4a335
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 25 deletions.
50 changes: 50 additions & 0 deletions generated,README.md/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[//]: # "This README.md file is auto-generated, all changes to this file will be lost."
[//]: # "To regenerate it, use `python -m synthtool`."
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>

# [Google Cloud Game Servers: Node.js Samples](https://github.com/googleapis/nodejs-game-servers)

[![Open in Cloud Shell][shell_img]][shell_link]



## Table of Contents

* [Before you begin](#before-you-begin)
* [Samples](#samples)
* [Quickstart](#quickstart)

## Before you begin

Before running the samples, make sure you've followed the steps outlined in
[Using the client library](https://github.com/googleapis/nodejs-game-servers#using-the-client-library).

`cd samples`

`npm install`

`cd ..`

## Samples



### Quickstart

View the [source code](https://github.com/googleapis/nodejs-game-servers/blob/master/samples/quickstart.js).

[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-game-servers&page=editor&open_in_editor=samples/quickstart.js,samples/README.md)

__Usage:__


`node samples/quickstart.js`






[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png
[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-game-servers&page=editor&open_in_editor=samples/README.md
[product-docs]: https://cloud.google.com/game-servers/
3 changes: 2 additions & 1 deletion generated,README.md/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 generated,README.md/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 generated,README.md/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 dc4a335

Please sign in to comment.