Skip to content

Commit

Permalink
docs: add update samples (#230)
Browse files Browse the repository at this point in the history
* feat: Add update samples

* Address feedback

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
irataxy and gcf-owl-bot[bot] authored Nov 18, 2021
1 parent 984ad67 commit f4bc8b2
Show file tree
Hide file tree
Showing 7 changed files with 421 additions and 1 deletion.
11 changes: 11 additions & 0 deletions cloud-game-servers/snippets/test/crud_deployment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,22 @@ describe('Game Server Deployment Test', () => {
assert.match(create_output, /Deployment name:/);
});

it('should update a game server deployment', async () => {
const update_output = execSync(
`node update_deployment.js ${projectId} ${deploymentId}`
);
assert.match(update_output, /Deployment updated:/);
});

it('should get a game server deployment', async () => {
const get_output = execSync(
`node get_deployment.js ${projectId} ${deploymentId}`
);
assert.match(get_output, /Deployment name:/);
assert.match(
get_output,
/Deployment description: My updated Game Server deployment/
);
});

it('should list a game server deployment', async () => {
Expand Down
2 changes: 1 addition & 1 deletion cloud-game-servers/snippets/test/list_clusters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('Game Servers List Clusters Test', () => {
await operation2.promise();
});

it.only('should list Game Server clusters in a realm', async () => {
it('should list Game Server clusters in a realm', async () => {
const projectId = await realmsClient.getProjectId();

const create_output = execSync(
Expand Down
115 changes: 115 additions & 0 deletions cloud-game-servers/snippets/test/update_cluster_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Copyright 2021 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 cleanup = require('./clean.js');
const {describe, it, before, after} = require('mocha');
const {
RealmsServiceClient,
GameServerClustersServiceClient,
} = 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';
const GKE_CLUSTER_NAME =
process.env.SAMPLE_CLUSTER_NAME ||
'projects/217093627905/locations/us-central1/clusters/gke-shared-default';

describe('Game Servers Update Cluster Test', () => {
const realmsClient = new RealmsServiceClient();
const gameClustersClient = new GameServerClustersServiceClient();
let realmId, gameClusterId, projectId;

before(async () => {
await cleanup();

// Create a realm
projectId = await realmsClient.getProjectId();
realmId = `update-realm-${uuid.v4()}`;
gameClusterId = `test-${uuid.v4()}`;

const createRealmRequest = {
parent: `projects/${projectId}/locations/${LOCATION}`,
realmId: realmId,
realm: {
timeZone: 'US/Pacific',
description: 'Test Game Server realm',
},
};

const [operation1] = await realmsClient.createRealm(createRealmRequest);
await operation1.promise();

// Create a cluster
const createClusterRequest = {
parent: `projects/${projectId}/locations/${LOCATION}/realms/${realmId}`,
gameServerClusterId: gameClusterId,
gameServerCluster: {
description: 'My Game Server Cluster',
connectionInfo: {
gkeClusterReference: {
// Provide full resource name of a Kubernetes Engine cluster
cluster: GKE_CLUSTER_NAME,
},
namespace: 'default',
},
},
};

const [operation2] = await gameClustersClient.createGameServerCluster(
createClusterRequest
);
await operation2.promise();
});

it('should update a Game Server cluster in a realm', async () => {
const update_output = execSync(
`node update_cluster.js ${projectId} ${LOCATION} ${realmId} ${gameClusterId}`
);
assert.match(update_output, /Cluster updated:/);

const get_output = execSync(
`node get_cluster.js ${projectId} ${LOCATION} ${realmId} ${gameClusterId}`
);
assert.match(
get_output,
/Cluster description: My updated Game Server Cluster/
);
});

after(async () => {
// Delete the Game Server cluster
const deleteClusterRequest = {
// Provide full resource name of a Game Server Realm
name: `projects/${projectId}/locations/${LOCATION}/realms/${realmId}/gameServerClusters/${gameClusterId}`,
};
const [operation1] = await gameClustersClient.deleteGameServerCluster(
deleteClusterRequest
);
await operation1.promise();

// Delete the realm
const deleteRealmRequest = {
name: `projects/${projectId}/locations/${LOCATION}/realms/${realmId}`,
};
const [operation2] = await realmsClient.deleteRealm(deleteRealmRequest);
await operation2.promise();
});
});
70 changes: 70 additions & 0 deletions cloud-game-servers/snippets/test/update_realm_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2021 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 cleanup = require('./clean.js');
const {describe, it, before, 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 Update Realms Test', () => {
const client = new RealmsServiceClient();
let realmId, projectId;

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

// Clean up any stray realms
await cleanup();

realmId = `test-${uuid.v4()}`;

await client.createRealm({
parent: `projects/${projectId}/locations/${LOCATION}`,
realmId: realmId,
realm: {
timeZone: 'US/Pacific',
description: 'Test Game Realm',
},
});
});

it('should update a realm', async () => {
const update_output = execSync(
`node update_realm.js ${projectId} ${LOCATION} ${realmId}`
);
assert.match(update_output, /Realm updated:/);

const get_output = execSync(
`node get_realm.js ${projectId} ${LOCATION} ${realmId}`
);
assert.match(get_output, /Realm description: My updated Game Server realm/);
});

after(async () => {
const request = {
name: `projects/${projectId}/locations/${LOCATION}/realms/${realmId}`,
};
const [operation] = await client.deleteRealm(request);
await operation.promise();
});
});
80 changes: 80 additions & 0 deletions cloud-game-servers/snippets/update_cluster.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright 2021, 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';

/**
* Update a Game Servers cluster.
* @param {string} projectId string project identifier
* @param {string} location Compute Engine region for the realm
* @param {string} realmId the realm to use
* @param {string} gameClusterId unique identifier for the Game Cluster
*/
async function main(
projectId = 'YOUR_PROJECT_ID',
location = 'LOCATION_ID',
realmId = 'REALM_ID',
gameClusterId = 'GAME_CLUSTER_ID'
) {
// [START cloud_game_servers_cluster_update]
const {
GameServerClustersServiceClient,
} = require('@google-cloud/game-servers');

const client = new GameServerClustersServiceClient();

async function updateGameServerCluster() {
/**
* 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 = 'The ID of the realm of this cluster';
// const gameClusterId = 'A unique ID for this Game Server Cluster';
const request = {
// Provide full resource name of a Game Server Cluster
gameServerCluster: {
name: client.gameServerClusterPath(
projectId,
location,
realmId,
gameClusterId
),
labels: {
'label-key-1': 'label-value-1',
},
description: 'My updated Game Server Cluster',
},
updateMask: {
paths: ['labels', 'description'],
},
};

const [operation] = await client.updateGameServerCluster(request);
const [result] = await operation.promise();

console.log(`Cluster updated: ${result.name}`);
}

updateGameServerCluster();
// [END cloud_game_servers_cluster_update]
}

main(...process.argv.slice(2)).catch(err => {
console.error(err.message);
process.exitCode = 1;
});
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
73 changes: 73 additions & 0 deletions cloud-game-servers/snippets/update_deployment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright 2021, 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';

/**
* Update a Game Servers Deployment.
* @param {string} projectId string project identifier
* @param {string} deploymentId unique identifier for the Game Server Deployment
*/
async function main(
projectId = 'YOUR_PROJECT_ID',
deploymentId = 'DEPLOYMENT_ID'
) {
// [START cloud_game_servers_deployment_update]
const {
GameServerDeploymentsServiceClient,
} = require('@google-cloud/game-servers');

const client = new GameServerDeploymentsServiceClient();

async function updateGameServerDeployment() {
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'Your Google Cloud Project ID';
// const deploymentId = 'The unique ID for the Game Server Deployment';
const request = {
gameServerDeployment: {
name: client.gameServerDeploymentPath(
projectId,
'global',
deploymentId
),
labels: {
'label-key-1': 'label-value-1',
},
description: 'My updated Game Server deployment',
},
updateMask: {
paths: ['labels', 'description'],
},
};

const [operation] = await client.updateGameServerDeployment(request);
const [result] = await operation.promise();

console.log(`Deployment updated: ${result.name}`);
}

updateGameServerDeployment();

// [END cloud_game_servers_deployment_update]
}

main(...process.argv.slice(2)).catch(err => {
console.error(err.message);
process.exitCode = 1;
});
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
Loading

0 comments on commit f4bc8b2

Please sign in to comment.