Skip to content

Commit

Permalink
Refactored tests (#159)
Browse files Browse the repository at this point in the history
* Refactor tests.

* Tweak build.

* Tweak build.

* More tests.

* Tweak build.

* Tweak build.

* Fix build.

* Fix build.

* Speed up build.

* Fix build.

* Remove extra dep.

* Investigate why 0.12 fails.

* Scripts.

* More tests.

* Upgrades

* Upgrades

* Update readme
  • Loading branch information
jmdobry authored Aug 3, 2016
1 parent b8290eb commit c67aeb3
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 4 deletions.
12 changes: 8 additions & 4 deletions monitoring/snippets/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{
"name": "nodejs-docs-samples-monitoring",
"description": "Samples For Cloud Monitoring v3 API",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
"engines": {
"node": ">=0.10.x"
"scripts": {
"test": "mocha -R spec -t 120000 --require intelli-espower-loader ../test/_setup.js test/*.test.js",
"system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js"
},
"dependencies": {
"async":"^1.5.2",
"googleapis": "^7.1.0"
"googleapis": "^12.0.0"
},
"devDependencies": {
"mocha": "^2.5.3"
}
}
52 changes: 52 additions & 0 deletions monitoring/snippets/system-test/create_custom_metric.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2015-2016, 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';

var customMetricsExample = require('../create_custom_metric');

/** Refactored out to keep lines shorter */
function getPointValue (timeSeries) {
return timeSeries.timeSeries[0].points[0].value.int64Value;
}

describe('monitoring:create_custom_metric', function () {
it('should create and read back a custom metric', function (done) {
customMetricsExample.main(
process.env.GCLOUD_PROJECT,
Math.random().toString(36).substring(7),
function (err, results) {
assert(!err);
// console.log('---------------------------------------------');
// console.log(JSON.stringify(results, null, 2));
// console.log('---------------------------------------------');
assert(results.length === 4);
// Result of creating metric
assert(typeof results[0].name === 'string');
// Result of writing time series
assert.deepEqual(results[1], {});
// Result of reading time series
assert(typeof getPointValue(results[2]) === 'string');
assert(!isNaN(parseInt(getPointValue(results[2]), 10)));
// Result of deleting metric
assert.deepEqual(results[3], {});
assert(console.log.calledWith('Created custom metric'));
assert(console.log.calledWith('Wrote time series'));
assert(console.log.calledWith('Reading metric type'));
assert(console.log.calledWith('Time series'));
assert(console.log.calledWith('Deleted metric'));
done();
}
);
});
});
38 changes: 38 additions & 0 deletions monitoring/snippets/system-test/list_resources.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2015-2016, 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';

var listResourcesExample = require('../list_resources');

describe('monitoring:list_resources', function () {
it('should list a bunch of stuff', function (done) {
listResourcesExample.main(
process.env.GCLOUD_PROJECT,
function (err, results) {
assert(!err);
assert(results.length === 3);
// Monitored resources
assert(Array.isArray(results[0].resourceDescriptors));
// Metric descriptors
assert(Array.isArray(results[1].metricDescriptors));
// Time series
assert(Array.isArray(results[2].timeSeries));
assert(console.log.calledWith('Monitored resources'));
assert(console.log.calledWith('Metric descriptors'));
assert(console.log.calledWith('Time series'));
done();
}
);
});
});
18 changes: 18 additions & 0 deletions monitoring/snippets/test/create_custom_metric.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2016, 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';

describe('monitoring:create_custom_metric', function () {
it('should be tested');
});
18 changes: 18 additions & 0 deletions monitoring/snippets/test/list_resources.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2016, 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';

describe('monitoring:list_resources', function () {
it('should be tested');
});

0 comments on commit c67aeb3

Please sign in to comment.