-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Uptime Check Config API samples.
- Loading branch information
Showing
7 changed files
with
460 additions
and
43 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
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
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
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,80 @@ | ||
/** | ||
* Copyright 2017, Google, Inc. | ||
* 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'; | ||
|
||
const client = require(`@google-cloud/monitoring`).uptimeCheck(); | ||
const path = require(`path`); | ||
const test = require(`ava`); | ||
const tools = require(`@google-cloud/nodejs-repo-tools`); | ||
|
||
const cmd = `node uptime.js`; | ||
const cwd = path.join(__dirname, `..`); | ||
const projectId = process.env.GCLOUD_PROJECT; | ||
const instanceId = 'uptime-test-' + Date.now(); | ||
|
||
test.before(tools.checkCredentials); | ||
|
||
test(`should get an uptime check`, async (t) => { | ||
t.regex(await tools.runAsync(`${cmd} list-ips`, cwd), /USA/); | ||
}); | ||
|
||
let id; | ||
|
||
test.serial(`should create an uptime check`, async (t) => { | ||
const results = await tools.runAsyncWithIO(`${cmd} create ${instanceId}`, cwd); | ||
const output = results.stdout + results.stderr; | ||
const matches = output.match(new RegExp(`ID: projects/${projectId}/uptimeCheckConfigs/(.+)`)); | ||
id = matches[1]; | ||
t.regex(output, /Uptime check created:/); | ||
t.regex(output, new RegExp(`Resource: {"type":"gce_instance","labels":{"instance_id":"${instanceId}"}}`)); | ||
t.regex(output, /Display Name: My GCE Instance Uptime Check/); | ||
}); | ||
|
||
test.serial(`should get an uptime check`, async (t) => { | ||
const results = await tools.runAsyncWithIO(`${cmd} get ${id}`, cwd); | ||
const output = results.stdout + results.stderr; | ||
t.regex(output, new RegExp(`Retrieving projects/${projectId}/uptimeCheckConfigs/${id}`)); | ||
t.regex(output, new RegExp(`Resource: {"type":"gce_instance","labels":{"instance_id":"${instanceId}"}}`)); | ||
}); | ||
|
||
let allLength; | ||
|
||
test.serial(`should list uptime checks`, async (t) => { | ||
t.plan(0); | ||
await tools.tryTest(async (assert) => { | ||
const results = await tools.runAsyncWithIO(`${cmd} list`, cwd); | ||
const output = results.stdout + results.stderr; | ||
allLength = output.match(/ID:/gi).length; | ||
assert((new RegExp(`Resource: {"type":"gce_instance","labels":{"instance_id":"${instanceId}"}}`)).test(output)); | ||
assert(/Display Name: My GCE Instance Uptime Check/.test(output)); | ||
}).start(); | ||
}); | ||
|
||
test.serial(`should list uptime checks with a filter`, async (t) => { | ||
const results = await tools.runAsyncWithIO(`${cmd} list "resource.type = gce_instance AND resource.label.instance_id = ${instanceId}"`, cwd); | ||
const output = results.stdout + results.stderr; | ||
t.true(output.match(/ID:/gi).length <= allLength); | ||
t.regex(output, new RegExp(`Resource: {"type":"gce_instance","labels":{"instance_id":"${instanceId}"}}`)); | ||
t.regex(output, /Display Name: My GCE Instance Uptime Check/); | ||
}); | ||
|
||
test.serial(`should delete an uptime check`, async (t) => { | ||
const results = await tools.runAsyncWithIO(`${cmd} delete ${id}`, cwd); | ||
const output = results.stdout + results.stderr; | ||
t.regex(output, new RegExp(`Deleting projects/${projectId}/uptimeCheckConfigs/${id}`)); | ||
t.regex(output, new RegExp(`projects/${projectId}/uptimeCheckConfigs/${id} deleted.`)); | ||
}); | ||
|
Oops, something went wrong.