|
13 | 13 |
|
14 | 14 | 'use strict';
|
15 | 15 |
|
16 |
| -var customMetricsExample = require('../create_custom_metric'); |
| 16 | +require(`../../system-test/_setup`); |
| 17 | + |
| 18 | +const customMetricsExample = require('../create_custom_metric'); |
17 | 19 |
|
18 | 20 | /** Refactored out to keep lines shorter */
|
19 | 21 | function getPointValue (timeSeries) {
|
20 | 22 | return timeSeries.timeSeries[0].points[0].value.int64Value;
|
21 | 23 | }
|
22 | 24 |
|
23 |
| -describe('monitoring:create_custom_metric', function () { |
24 |
| - it('should create and read back a custom metric', function (done) { |
25 |
| - customMetricsExample.main( |
26 |
| - process.env.GCLOUD_PROJECT, |
27 |
| - Math.random().toString(36).substring(7), |
28 |
| - function (err, results) { |
29 |
| - assert.ifError(err); |
30 |
| - assert(results.length === 4); |
31 |
| - // Result of creating metric |
32 |
| - assert(typeof results[0].name === 'string'); |
33 |
| - // Result of writing time series |
34 |
| - assert.deepEqual(results[1], {}); |
35 |
| - // Result of reading time series |
36 |
| - assert(typeof getPointValue(results[2]) === 'string'); |
37 |
| - assert(!isNaN(parseInt(getPointValue(results[2]), 10))); |
38 |
| - // Result of deleting metric |
39 |
| - assert.deepEqual(results[3], {}); |
40 |
| - assert(console.log.calledWith('Created custom metric')); |
41 |
| - assert(console.log.calledWith('Wrote time series')); |
42 |
| - assert(console.log.calledWith('Reading metric type')); |
43 |
| - assert(console.log.calledWith('Time series')); |
44 |
| - assert(console.log.calledWith('Deleted metric')); |
45 |
| - done(); |
46 |
| - } |
47 |
| - ); |
48 |
| - }); |
| 25 | +test.before(stubConsole); |
| 26 | +test.after(restoreConsole); |
| 27 | + |
| 28 | +test.cb('should create and read back a custom metric', (t) => { |
| 29 | + customMetricsExample.main( |
| 30 | + process.env.GCLOUD_PROJECT, |
| 31 | + Math.random().toString(36).substring(7), |
| 32 | + (err, results) => { |
| 33 | + t.ifError(err); |
| 34 | + t.is(results.length, 4); |
| 35 | + // Result of creating metric |
| 36 | + t.is(typeof results[0].name, 'string'); |
| 37 | + // Result of writing time series |
| 38 | + t.deepEqual(results[1], {}); |
| 39 | + // Result of reading time series |
| 40 | + t.is(typeof getPointValue(results[2]), 'string'); |
| 41 | + t.false(isNaN(parseInt(getPointValue(results[2]), 10))); |
| 42 | + // Result of deleting metric |
| 43 | + t.deepEqual(results[3], {}); |
| 44 | + t.true(console.log.calledWith('Created custom metric')); |
| 45 | + t.true(console.log.calledWith('Wrote time series')); |
| 46 | + t.true(console.log.calledWith('Reading metric type')); |
| 47 | + t.true(console.log.calledWith('Time series')); |
| 48 | + t.true(console.log.calledWith('Deleted metric')); |
| 49 | + t.end(); |
| 50 | + } |
| 51 | + ); |
49 | 52 | });
|
0 commit comments