Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor for completely parallel tests. #90

Merged
merged 1 commit into from
Mar 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ test/encrypted/nodejs-docs-samples.json
dump.rdb
logs/
*.iml
.idea/
.idea/
.nyc_output
19 changes: 5 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ cache:
- appengine/mailgun/node_modules/
- appengine/memcached/node_modules/
- appengine/mongodb/node_modules/
- appengine/parse-server/node_modules/
- appengine/pubsub/node_modules/
- appengine/redis/node_modules/
- appengine/restify/node_modules/
- appengine/sails/node_modules/
Expand All @@ -50,7 +52,9 @@ cache:
- appengine/websockets/node_modules/
- computeengine/sendgrid/node_modules/
- datastore/node_modules/
- functions/uuid/node_modules/
- logging/node_modules/
- monitoring/node_modules/
- prediction/node_modules/
- pubsub/node_modules/
- storage/node_modules/
Expand All @@ -61,26 +65,13 @@ services:

env:
global:
- PATH=$PATH:$HOME/gcloud/google-cloud-sdk/bin
- GOOGLE_APPLICATION_CREDENTIALS=$TRAVIS_BUILD_DIR/test/encrypted/nodejs-docs-samples.json
- TEST_BUCKET_NAME=nodejs-docs-samples
- GCLOUD_PROJECT=nodejs-docs-samples

before_install:
- if [ ! -d $HOME/gcloud/google-cloud-sdk ]; then
mkdir -p $HOME/gcloud &&
wget https://dl.google.com/dl/cloudsdk/channels/rapid/google-cloud-sdk.tar.gz --directory-prefix=$HOME/gcloud &&
cd $HOME/gcloud &&
tar xzf google-cloud-sdk.tar.gz &&
printf '\ny\n\ny\ny\n' | ./google-cloud-sdk/install.sh &&
source $HOME/.bashrc &&
cd $TRAVIS_BUILD_DIR;
fi
- openssl aes-256-cbc -K $encrypted_fda0b707c7d5_key -iv $encrypted_fda0b707c7d5_iv -in test/encrypted/nodejs-docs-samples.json.enc -out test/encrypted/nodejs-docs-samples.json -d
- if [ -a test/encrypted/nodejs-docs-samples.json ]; then
gcloud auth activate-service-account --key-file test/encrypted/nodejs-docs-samples.json;
fi
- npm set progress=false

after_success:
- npm run coveralls
- npm run report
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,30 +129,29 @@ a service account file. You can download one from your Google project's
"permissions" page.
1. `npm test`

Since the tests use [Mocha.js](https://mochajs.org/), you can use the `--grep`
option to run only the tests that match a provided pattern. The `--invert`
option causes the matched tests to be excluded instead of included.
Since the tests use [AVA](https://github.com/sindresorhus/ava), you can use the
`--match` option to run only the tests that match a provided pattern.

__Run only the tests that match a pattern:__


npm test -- -- --grep <pattern>
npm test -- -- --match="<pattern>"

__Only run the tests for the `datastore` sample:__

npm test -- -- --grep datastore
npm test -- -- --match="datastore"

__Skip the tests that match a pattern:__

npm test -- -- --grep <pattern> --invert
npm test -- -- --match="!<pattern>"

__Run all but the `datastore` tests:__

npm test -- -- --grep datastore --invert
npm test -- -- --match="!datastore"

__Skip the tests that require Redis and Memcached:__

npm test -- -- --grep "express-memcached-session|redis" --invert
npm test -- -- --match="express-memcached-session|redis"

## License

Expand Down
3 changes: 1 addition & 2 deletions datastore/concepts.js
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,7 @@ Query.prototype.testRunQueryProjection = function(callback) {

self.datastore.runQuery(query, function(err) {
if (err) {
callback(err);
return;
return callback(err);
}

queryCallback.apply(null, arguments);
Expand Down
2 changes: 1 addition & 1 deletion datastore/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ function runQuery(cb) {
exports.runQuery = runQuery;

if (module === require.main) {
runQuery(function () {});
runQuery(console.log);
}
95 changes: 64 additions & 31 deletions logging/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,70 +28,103 @@ var logging = gcloud.logging();
// [END setup]

// [START listSinks]
function listSinks(callback) {
/**
* @param {Function} callback Callback function.
*/
function listSinksExample(callback) {
// list all sinks in the authenticated project
logging.getSinks(callback);
logging.getSinks(function (err, sinks) {
if (err) {
return callback(err);
}

// Should have received all sinks
console.log('Found ' + sinks.length + ' sinks');
callback(null, sinks);
});
}
// [END listSinks]

// [START createSink]
function createSink(callback) {
// Get a reference to the Cloud Storage component
var gcs = gcloud.storage();

/**
* @param {string} sinkName Name of the new sink.
* @param {Object} config Configuration options for the new sink.
* @param {Function} callback Callback function.
*/
function createSinkExample(sinkName, config, callback) {
// create a new sink in the authenticated project
//
// This method only works if you are authenticated as yourself, e.g. using the
// gcloud SDK.
logging.createSink('mySink', {
destination: gcs.bucket('logging-bucket')
}, callback);
logging.createSink(sinkName, config, function (err, sink, apiResponse) {
if (err) {
return callback(err);
}

// Should have received newly created sink
console.log('Created ' + sinkName, sink);
callback(null, sink, apiResponse);
});
}
// [END createSink]

// [START updateSink]
function updateSink(callback) {
// Get a reference to the Cloud Storage component
var gcs = gcloud.storage();
/**
* @param {string} sinkName Name of the sink to update.
* @param {Object} config New configuration options for the sink.
* @param {Function} callback Callback function.
*/
function updateSinkExample(sinkName, config, callback) {
// Get a reference to an existing sink
var sink = logging.sink('mySink');
var sink = logging.sink(sinkName);

// update a sink
//
// This method only works if you are authenticated as yourself, e.g. using the
// gcloud SDK.
sink.setMetadata({
// change destination to something else
destination: gcs.bucket('other-logging-bucket')
}, callback);
sink.setMetadata(config, function (err, apiResponse) {
if (err) {
return callback(err);
}

console.log('Updated ' + sinkName);
callback(null, apiResponse);
});
}
// [END updateSink]

// [START deleteSink]
function deleteSink(callback) {
/**
* @param {string} sinkName Name of the sink to delete.
* @param {Function} callback Callback function.
*/
function deleteSinkExample(sinkName, callback) {
// Get a reference to an existing sink
var sink = logging.sink('mySink');
var sink = logging.sink(sinkName);

// delete a sink
//
// This method only works if you are authenticated as yourself, e.g. using the
// gcloud SDK.
sink.delete(callback);
sink.delete(function (err, apiResponse) {
if (err) {
return callback(err);
}

console.log('Deleted ' + sinkName);
callback(null, apiResponse);
});
}
// [END deleteSink]

exports.runExample = function (cb) {
listSinks(function (err, sinks, apiResponse) {
console.log(err, 'sinks:', sinks, 'apiResponse:', apiResponse);
if (typeof cb === 'function') {
cb(err, sinks);
}
});
// Run the examples
exports.main = function (cb) {
listSinksExample(cb || console.log);
};
exports.createSink = createSink;
exports.updateSink = updateSink;
exports.deleteSink = deleteSink;
exports.createSinkExample = createSinkExample;
exports.updateSinkExample = updateSinkExample;
exports.deleteSinkExample = deleteSinkExample;

if (module === require.main) {
exports.runExample();
exports.main();
}
37 changes: 23 additions & 14 deletions logging/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,33 @@ var gcloud = require('gcloud')({
// Get a reference to the logging component
var logging = gcloud.logging();

function list(callback) {
// Retrieve the latest 3 log entries from the authenticated project.
logging.getEntries({
pageSize: 3
}, callback);
}
// [END list]
/**
* @param {Object} [options] Configuration options for the request.
* @param {Function} callback Callback function.
*/
function listExample(options, callback) {
if (typeof options === 'function') {
callback = options;
}

exports.runExample = function (cb) {
console.log('retrieving latest 3 log entries...');
list(function (err, entries, apiResponse) {
console.log(err, 'entries:', entries, 'apiResponse:', apiResponse);
if (typeof cb === 'function') {
cb(err, entries, apiResponse);
// Retrieve the latest some log entries from the authenticated project.
logging.getEntries(options, function (err, entries, nextQuery, apiResponse) {
if (err) {
return callback(err);
}

// Should have received some log entries
console.log('Found ' + entries.length + ' entries');
callback(null, entries, nextQuery, apiResponse);
});
}
// [END list]

// Run the examples
exports.main = function (options, cb) {
listExample(options || { pageSize: 1 }, cb || console.log);
};

if (module === require.main) {
exports.runExample();
exports.main();
}
Loading