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: modernize sample tests #484

Merged
merged 1 commit into from
Dec 18, 2018
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
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