Skip to content

Commit

Permalink
refactor: modernize sample tests (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Dec 18, 2018
1 parent e869a92 commit db678f2
Show file tree
Hide file tree
Showing 4 changed files with 220 additions and 482 deletions.
6 changes: 3 additions & 3 deletions samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"yargs": "^12.0.1"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.0.0",
"ava": "^0.25.0",
"chai": "^4.2.0",
"execa": "^1.0.0",
"mocha": "^5.2.0",
"proxyquire": "^2.0.1",
"request": "^2.87.0",
"sinon": "^7.0.0"
}
}
69 changes: 32 additions & 37 deletions samples/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,36 @@
'use strict';

// [START spanner_quickstart]
// Imports the Google Cloud client library
const {Spanner} = require('@google-cloud/spanner');

// Your Google Cloud Platform project ID
const projectId = 'YOUR_PROJECT_ID';

// Creates a client
const spanner = new Spanner({
projectId: projectId,
});

// Your Cloud Spanner instance ID
const instanceId = 'my-instance';

// Your Cloud Spanner database ID
const databaseId = 'my-database';

// Gets a reference to a Cloud Spanner instance and database
const instance = spanner.instance(instanceId);
const database = instance.database(databaseId);

// The query to execute
const query = {
sql: 'SELECT 1',
};

// Execute a simple SQL statement
database
.run(query)
.then(results => {
const rows = results[0];

rows.forEach(row => console.log(row));
})
.catch(err => {
console.error('ERROR:', err);
});
async function quickstart(projectId) {
// Imports the Google Cloud client library
const {Spanner} = require('@google-cloud/spanner');

// Your Google Cloud Platform project ID
projectId = projectId || process.env.GCLOUD_PROJECT;

// Creates a client
const spanner = new Spanner({projectId});

// Your Cloud Spanner instance ID
const instanceId = 'my-instance';

// Your Cloud Spanner database ID
const databaseId = 'my-database';

// Gets a reference to a Cloud Spanner instance and database
const instance = spanner.instance(instanceId);
const database = instance.database(databaseId);

// The query to execute
const query = {
sql: 'SELECT 1',
};

// Execute a simple SQL statement
const [rows] = await database.run(query);
rows.forEach(row => console.log(row));
}
// [END spanner_quickstart]

const args = process.argv.slice(2);
quickstart(...args).catch(console.error);
4 changes: 0 additions & 4 deletions samples/system-test/quickstart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@
const proxyquire = require(`proxyquire`).noPreserveCache();
const sinon = require(`sinon`);
const assert = require(`assert`);
const tools = require(`@google-cloud/nodejs-repo-tools`);

describe('QuickStart', () => {
before(tools.stubConsole);
after(tools.restoreConsole);

it(`should query a table`, async () => {
const databaseMock = {
run: async _query => {
Expand Down
Loading

0 comments on commit db678f2

Please sign in to comment.