|
| 1 | +// Copyright 2020 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +'use strict'; |
| 16 | + |
| 17 | +const {assert} = require('chai'); |
| 18 | +const cleanup = require('./clean.js'); |
| 19 | +const {describe, before, after, it} = require('mocha'); |
| 20 | +const { |
| 21 | + GameServerConfigsServiceClient, |
| 22 | + GameServerDeploymentsServiceClient, |
| 23 | + RealmsServiceClient, |
| 24 | +} = require('@google-cloud/game-servers'); |
| 25 | + |
| 26 | +const cp = require('child_process'); |
| 27 | +const uuid = require('uuid'); |
| 28 | + |
| 29 | +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); |
| 30 | + |
| 31 | +describe('Game Server Rollout Test', () => { |
| 32 | + const configClient = new GameServerConfigsServiceClient(); |
| 33 | + const deploymentClient = new GameServerDeploymentsServiceClient(); |
| 34 | + const realmClient = new RealmsServiceClient(); |
| 35 | + let projectId; |
| 36 | + const deploymentId = `test-nodejs-${uuid.v4()}`; |
| 37 | + const configId = `test-nodejs-${uuid.v4()}`; |
| 38 | + const realmId = `test-nodejs-${uuid.v4()}`; |
| 39 | + const realmLocation = 'us-central1'; |
| 40 | + |
| 41 | + before(async () => { |
| 42 | + await cleanup(); |
| 43 | + |
| 44 | + projectId = await deploymentClient.getProjectId(); |
| 45 | + |
| 46 | + const request = { |
| 47 | + parent: `projects/${projectId}/locations/global`, |
| 48 | + deploymentId: deploymentId, |
| 49 | + }; |
| 50 | + const [operation] = await deploymentClient.createGameServerDeployment( |
| 51 | + request |
| 52 | + ); |
| 53 | + await operation.promise(); |
| 54 | + |
| 55 | + const request2 = { |
| 56 | + parent: configClient.gameServerDeploymentPath( |
| 57 | + projectId, |
| 58 | + 'global', |
| 59 | + deploymentId |
| 60 | + ), |
| 61 | + configId: configId, |
| 62 | + }; |
| 63 | + const [operation2] = await configClient.createGameServerConfig(request2); |
| 64 | + await operation2.promise(); |
| 65 | + |
| 66 | + const request3 = { |
| 67 | + parent: `projects/${projectId}/locations/${realmLocation}`, |
| 68 | + realmId: realmId, |
| 69 | + realm: { |
| 70 | + timeZone: 'US/Pacific', |
| 71 | + description: 'Test Game Server realm', |
| 72 | + }, |
| 73 | + }; |
| 74 | + |
| 75 | + const [operation3] = await realmClient.createRealm(request3); |
| 76 | + await operation3.promise(); |
| 77 | + }); |
| 78 | + |
| 79 | + it('should update rollout default', async () => { |
| 80 | + const updateDefaultOutput = execSync( |
| 81 | + `node update_rollout_default.js ${projectId} ${deploymentId} ${configId}` |
| 82 | + ); |
| 83 | + |
| 84 | + assert.match(updateDefaultOutput, /Deployment updated:/); |
| 85 | + |
| 86 | + const getRolloutOutput = execSync( |
| 87 | + `node get_rollout.js ${projectId} ${deploymentId} ${configId}` |
| 88 | + ); |
| 89 | + |
| 90 | + const configName = configClient.gameServerConfigPath( |
| 91 | + projectId, |
| 92 | + 'global', |
| 93 | + deploymentId, |
| 94 | + configId |
| 95 | + ); |
| 96 | + assert.match(getRolloutOutput, /Rollout name:/); |
| 97 | + assert.match( |
| 98 | + getRolloutOutput, |
| 99 | + new RegExp(`Rollout default: ${configName}`) |
| 100 | + ); |
| 101 | + }); |
| 102 | + |
| 103 | + it('should remove rollout default', async () => { |
| 104 | + const removeDefaultOutput = execSync( |
| 105 | + `node update_rollout_remove_default.js ${projectId} ${deploymentId} ${configId}` |
| 106 | + ); |
| 107 | + |
| 108 | + assert.match(removeDefaultOutput, /Deployment updated:/); |
| 109 | + |
| 110 | + const request = { |
| 111 | + // The full resource name |
| 112 | + name: deploymentClient.gameServerDeploymentPath( |
| 113 | + projectId, |
| 114 | + 'global', |
| 115 | + deploymentId |
| 116 | + ), |
| 117 | + }; |
| 118 | + |
| 119 | + const [rollout] = await deploymentClient.getGameServerDeploymentRollout( |
| 120 | + request |
| 121 | + ); |
| 122 | + assert.strictEqual(rollout.defaultGameServerConfig, ''); |
| 123 | + }); |
| 124 | + |
| 125 | + it('should update rollout override', async () => { |
| 126 | + const updateOverrideOutput = execSync( |
| 127 | + `node update_rollout_override.js ${projectId} ${deploymentId} ${configId} ${realmId} ${realmLocation}` |
| 128 | + ); |
| 129 | + assert.match(updateOverrideOutput, /Deployment updated:/); |
| 130 | + |
| 131 | + const getRolloutOutput = execSync( |
| 132 | + `node get_rollout.js ${projectId} ${deploymentId} ${configId}` |
| 133 | + ); |
| 134 | + |
| 135 | + const configName = configClient.gameServerConfigPath( |
| 136 | + projectId, |
| 137 | + 'global', |
| 138 | + deploymentId, |
| 139 | + configId |
| 140 | + ); |
| 141 | + const realmName = realmClient.realmPath(projectId, realmLocation, realmId); |
| 142 | + assert.match( |
| 143 | + getRolloutOutput, |
| 144 | + new RegExp(`Rollout config overrides: .*${configName}`) |
| 145 | + ); |
| 146 | + assert.match(getRolloutOutput, new RegExp(realmName)); |
| 147 | + }); |
| 148 | + |
| 149 | + it('should remove rollout override', async () => { |
| 150 | + const removeOverrideOutput = execSync( |
| 151 | + `node update_rollout_remove_override.js ${projectId} ${deploymentId}` |
| 152 | + ); |
| 153 | + |
| 154 | + assert.match(removeOverrideOutput, /Deployment updated:/); |
| 155 | + |
| 156 | + const request = { |
| 157 | + // The full resource name |
| 158 | + name: deploymentClient.gameServerDeploymentPath( |
| 159 | + projectId, |
| 160 | + 'global', |
| 161 | + deploymentId |
| 162 | + ), |
| 163 | + }; |
| 164 | + |
| 165 | + const [rollout] = await deploymentClient.getGameServerDeploymentRollout( |
| 166 | + request |
| 167 | + ); |
| 168 | + assert.strictEqual(rollout.gameServerConfigOverrides.length, 0); |
| 169 | + }); |
| 170 | + |
| 171 | + after(async () => { |
| 172 | + // Delete the Game Server Config |
| 173 | + const request = { |
| 174 | + // Provide full resource name of a Game Server Config |
| 175 | + name: configClient.gameServerConfigPath( |
| 176 | + projectId, |
| 177 | + 'global', |
| 178 | + deploymentId, |
| 179 | + configId |
| 180 | + ), |
| 181 | + }; |
| 182 | + const [operation] = await configClient.deleteGameServerConfig(request); |
| 183 | + await operation.promise(); |
| 184 | + |
| 185 | + // Delete the Game Server Deployment |
| 186 | + const request2 = { |
| 187 | + // Provide full resource name of a Game Server Deployment |
| 188 | + name: deploymentClient.gameServerDeploymentPath( |
| 189 | + projectId, |
| 190 | + 'global', |
| 191 | + deploymentId |
| 192 | + ), |
| 193 | + }; |
| 194 | + const [operation2] = await deploymentClient.deleteGameServerDeployment( |
| 195 | + request2 |
| 196 | + ); |
| 197 | + await operation2.promise(); |
| 198 | + |
| 199 | + // Delete the Realm |
| 200 | + const request3 = { |
| 201 | + // Provide full resource name of a Realm |
| 202 | + name: realmClient.realmPath(projectId, realmLocation, realmId), |
| 203 | + }; |
| 204 | + const [operation3] = await realmClient.deleteRealm(request3); |
| 205 | + await operation3.promise(); |
| 206 | + }); |
| 207 | +}); |
0 commit comments