This repository has been archived by the owner on Jul 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds CRUD samples for GS realms (#21)
* Adds Game Servers realm samples * feat: adds realm CRUD tests * feat: adds quickstart test * fix: updates region tags
- Loading branch information
Showing
11 changed files
with
509 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,5 @@ system-test/*key.json | |
.DS_Store | ||
package-lock.json | ||
__pycache__ | ||
*.code-workspace | ||
launch.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2020, Google LLC. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
/** | ||
* Create a Game Servers realm. | ||
* @param {string} projectId string project identifier. | ||
* @param {string} location Compute Engine region. | ||
* @param {string} realmId a unique identifier for the new realm | ||
*/ | ||
function main( | ||
projectId = 'YOUR_PROJECT_ID', | ||
location = 'LOCATION_ID', | ||
realmId = 'REALM_ID' | ||
) { | ||
// [START cloud_game_servers_create_realm] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const projectId = 'Your Google Cloud Project ID'; | ||
// const location = 'A Compute Engine region, e.g. "us-central1"'; | ||
// const realmId = 'A unique identifier for the realm'; | ||
const {RealmsServiceClient} = require('@google-cloud/game-servers'); | ||
|
||
const client = new RealmsServiceClient(); | ||
|
||
async function createRealm() { | ||
const request = { | ||
parent: `projects/${projectId}/locations/${location}`, | ||
realmId: realmId, | ||
realm: { | ||
// Must use a supported time zone name. | ||
// 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; | ||
|
||
console.log('Realm created:'); | ||
|
||
console.log(`\tRealm name: ${realm.name}`); | ||
console.log(`\tRealm description: ${realm.description}`); | ||
console.log(`\tRealm time zone: ${realm.timeZone}`); | ||
// [END cloud_game_servers_create_realm] | ||
} | ||
|
||
createRealm(); | ||
} | ||
|
||
main(...process.argv.slice(2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2020, Google LLC. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
/** | ||
* Delete a realm by ID | ||
* @param {string} projectId string project identifier. | ||
* @param {string} location Compute Engine region. | ||
* @param {string} realmId the unique ID of the realm | ||
*/ | ||
function main( | ||
projectId = 'YOUR_PROJECT_ID', | ||
location = 'LOCATION_ID', | ||
realmId = 'REALM_ID' | ||
) { | ||
// [START cloud_game_servers_delete_realm] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const projectId = 'Your Google Cloud Project ID'; | ||
// const location = 'A Compute Engine region, e.g. "us-central1"'; | ||
// const realmId = 'Unique identifier of the realm'; | ||
const {RealmsServiceClient} = require('@google-cloud/game-servers'); | ||
|
||
const client = new RealmsServiceClient(); | ||
|
||
async function deleteRealm() { | ||
const request = { | ||
// Realm name is the full resource name including project ID,location, | ||
// and the realm ID. | ||
name: `projects/${projectId}/locations/${location}/realms/${realmId}`, | ||
}; | ||
|
||
const [operation] = await client.deleteRealm(request); | ||
await operation.promise(); | ||
console.log(`Realm with ID ${realmId} deleted.`); | ||
|
||
// [END cloud_game_servers_delete_realm] | ||
} | ||
|
||
deleteRealm(); | ||
} | ||
|
||
main(...process.argv.slice(2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2020, Google LLC. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
/** | ||
* Get a realm by ID | ||
* @param {string} projectId string project identifier. | ||
* @param {string} location Compute Engine region. | ||
* @param {string} realmId the unique ID of the realm | ||
*/ | ||
function main( | ||
projectId = 'YOUR_PROJECT_ID', | ||
location = 'LOCATION_ID', | ||
realmId = 'REALM_ID' | ||
) { | ||
// [START cloud_game_servers_get_realm] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const projectId = 'Your Google Cloud Project ID'; | ||
// const location = 'A Compute Engine region, e.g. "us-central1"'; | ||
// const realmId = 'Unique identifier of the realm'; | ||
const {RealmsServiceClient} = require('@google-cloud/game-servers'); | ||
|
||
const client = new RealmsServiceClient(); | ||
|
||
async function getRealm() { | ||
const request = { | ||
// Realm name is the full resource name including project ID and location | ||
name: `projects/${projectId}/locations/${location}/realms/${realmId}`, | ||
}; | ||
|
||
const [realm] = await client.getRealm(request); | ||
console.log(`Realm name: ${realm.name}`); | ||
console.log(`Realm description: ${realm.description}`); | ||
console.log(`Realm time zone: ${realm.timeZone}`); | ||
// [END cloud_game_servers_get_realm] | ||
} | ||
|
||
getRealm(); | ||
} | ||
|
||
main(...process.argv.slice(2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2020, Google LLC. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
/** | ||
* List all of the realms in a project. | ||
* @param {string} projectId string project identifier. | ||
* @param {string} location Compute Engine region. | ||
*/ | ||
function main(projectId = 'YOUR_PROJECT_ID', location = 'LOCATION_ID') { | ||
// [START cloud_game_servers_list_realms] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const projectId = 'Your Google Cloud Project ID'; | ||
// const location = 'A Compute Engine region, e.g. "us-central1"'; | ||
const {RealmsServiceClient} = require('@google-cloud/game-servers'); | ||
|
||
const client = new RealmsServiceClient(); | ||
|
||
async function listRealms() { | ||
const request = { | ||
parent: `projects/${projectId}/locations/${location}`, | ||
}; | ||
|
||
const [results] = await client.listRealms(request); | ||
for (const realm of results.realms) { | ||
console.log(`Realm name: ${realm.name}`); | ||
console.log(`Realm description: ${realm.description}`); | ||
console.log(`Realm time zone: ${realm.timeZone}\n`); | ||
} | ||
// [END cloud_game_servers_list_realms] | ||
} | ||
|
||
listRealms(); | ||
} | ||
|
||
main(...process.argv.slice(2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
const {assert} = require('chai'); | ||
const {describe, it, after} = require('mocha'); | ||
const {RealmsServiceClient} = require('@google-cloud/game-servers'); | ||
|
||
const cp = require('child_process'); | ||
const uuid = require('uuid'); | ||
|
||
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); | ||
|
||
const LOCATION = 'us-central1'; | ||
|
||
describe('Game Servers Create Realm Test', () => { | ||
const client = new RealmsServiceClient(); | ||
let realmId; | ||
|
||
it('should create a realm', async () => { | ||
const projectId = await client.getProjectId(); | ||
realmId = `test-${uuid.v4()}`; | ||
|
||
const create_output = execSync( | ||
`node create_realm.js ${projectId} ${LOCATION} ${realmId}` | ||
); | ||
assert.match(create_output, /Realm time zone:/); | ||
}); | ||
|
||
after(async () => { | ||
const projectId = await client.getProjectId(); | ||
const request = { | ||
name: `projects/${projectId}/locations/${LOCATION}/realms/${realmId}`, | ||
}; | ||
const [operation] = await client.deleteRealm(request); | ||
await operation.promise(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
const {assert} = require('chai'); | ||
const {describe, it, before} = require('mocha'); | ||
const {RealmsServiceClient} = require('@google-cloud/game-servers'); | ||
|
||
const cp = require('child_process'); | ||
const uuid = require('uuid'); | ||
|
||
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); | ||
|
||
const LOCATION = 'us-central1'; | ||
|
||
describe('Game Servers Delete Realm Test', () => { | ||
const client = new RealmsServiceClient(); | ||
let realmId; | ||
|
||
before(async () => { | ||
const projectId = await client.getProjectId(); | ||
realmId = `test-${uuid.v4()}`; | ||
|
||
await client.createRealm({ | ||
parent: `projects/${projectId}/locations/${LOCATION}`, | ||
realmId: realmId, | ||
realm: { | ||
timeZone: 'US/Pacific', | ||
description: 'Test Game Realm', | ||
}, | ||
}); | ||
}); | ||
|
||
it('should delete a realm', async () => { | ||
const projectId = await client.getProjectId(); | ||
|
||
const delete_output = execSync( | ||
`node delete_realm.js ${projectId} ${LOCATION} ${realmId}` | ||
); | ||
assert.match(delete_output, /deleted./); | ||
}); | ||
}); |
Oops, something went wrong.