diff --git a/samples/package.json b/samples/package.json index cb2947d6f..7d96e2f42 100644 --- a/samples/package.json +++ b/samples/package.json @@ -9,9 +9,7 @@ "node": ">=8" }, "scripts": { - "ava": "ava -T 5m --verbose test/*.test.js ./system-test/*.test.js", - "cover": "nyc --reporter=lcov --cache ava -T 5m --verbose test/*.test.js ./system-test/*.test.js && nyc report", - "test": "npm run cover" + "test": "mocha system-test/*.js --timeout 600000" }, "dependencies": { "@google-cloud/spanner": "^2.1.0", diff --git a/samples/system-test/.eslintrc.yml b/samples/system-test/.eslintrc.yml index c0289282a..752164361 100644 --- a/samples/system-test/.eslintrc.yml +++ b/samples/system-test/.eslintrc.yml @@ -1,4 +1,6 @@ --- +env: + mocha: true rules: node/no-unpublished-require: off node/no-unsupported-features: off diff --git a/samples/system-test/quickstart.test.js b/samples/system-test/quickstart.test.js index 8ea7986e2..e4415f7cb 100644 --- a/samples/system-test/quickstart.test.js +++ b/samples/system-test/quickstart.test.js @@ -17,42 +17,43 @@ const proxyquire = require(`proxyquire`).noPreserveCache(); const sinon = require(`sinon`); -const test = require(`ava`); +const assert = require(`assert`); const tools = require(`@google-cloud/nodejs-repo-tools`); -test.before(tools.stubConsole); -test.after.always(tools.restoreConsole); +describe('QuickStart', () => { + before(tools.stubConsole); + after(tools.restoreConsole); -test.cb(`should query a table`, t => { - const databaseMock = { - run: _query => { - t.deepEqual(_query, { - sql: `SELECT 1`, - }); - setTimeout(() => { - try { - t.deepEqual(console.log.getCall(0).args, [`test`]); - t.end(); - } catch (err) { - t.end(err); - } - }, 200); - return Promise.resolve([['test']]); - }, - }; - const instanceMock = { - database: sinon.stub().returns(databaseMock), - }; - const spannerMock = { - instance: sinon.stub().returns(instanceMock), - }; + it(`should query a table`, async () => { + const databaseMock = { + run: async _query => { + assert.deepStrictEqual(_query, { + sql: `SELECT 1`, + }); - proxyquire(`../quickstart`, { - '@google-cloud/spanner': { - Spanner: sinon.stub().returns(spannerMock), - }, - }); + await new Promise(r => setTimeout(r, 200)); + assert.deepStrictEqual(console.log.getCall(0).args, [`test`]); + return [['test']]; + }, + }; + const instanceMock = { + database: sinon.stub().returns(databaseMock), + }; + const spannerMock = { + instance: sinon.stub().returns(instanceMock), + }; + + proxyquire(`../quickstart`, { + '@google-cloud/spanner': { + Spanner: sinon.stub().returns(spannerMock), + }, + }); - t.deepEqual(spannerMock.instance.getCall(0).args, [`my-instance`]); - t.deepEqual(instanceMock.database.getCall(0).args, [`my-database`]); + assert.deepStrictEqual(spannerMock.instance.getCall(0).args, [ + `my-instance`, + ]); + assert.deepStrictEqual(instanceMock.database.getCall(0).args, [ + `my-database`, + ]); + }); }); diff --git a/samples/system-test/spanner.test.js b/samples/system-test/spanner.test.js index 3698657ff..6927838b2 100644 --- a/samples/system-test/spanner.test.js +++ b/samples/system-test/spanner.test.js @@ -18,7 +18,7 @@ const path = require(`path`); const request = require(`request`); const {Spanner} = require(`@google-cloud/spanner`); -const test = require(`ava`); +const assert = require('assert'); const tools = require(`@google-cloud/nodejs-repo-tools`); const batchCmd = `node batch.js`; @@ -41,624 +41,693 @@ const spanner = new Spanner({ projectId: PROJECT_ID, }); -test.before(tools.checkCredentials); - -test.before(async () => { - const instance = spanner.instance(INSTANCE_ID); - const database = instance.database(DATABASE_ID); - - try { - await instance.delete(); - } catch (err) { - // Ignore error - } - - try { - await database.delete(); - } catch (err) { - // Ignore error - } - - const [, operation] = await instance.create({ - config: 'regional-us-central1', - nodes: 1, - labels: { - 'gcloud-sample-tests': 'true', - }, - }); - - await operation.promise(); -}); - -test.before(async () => { - const [instances] = await spanner.getInstances({ - filter: 'labels.gcloud-sample-tests:true', - }); - - instances.forEach(async instance => { - const {operations} = await getOperations(instance.metadata.name); - - operations - .filter(operation => { - return operation.metadata['@type'].includes('CreateInstance'); - }) - .filter(operation => { - const yesterday = new Date(); - yesterday.setHours(-24); - - const instanceCreated = new Date(operation.metadata.startTime); - - return instanceCreated < yesterday; +describe('Spanner', () => { + before(async () => { + tools.checkCredentials(); + const instance = spanner.instance(INSTANCE_ID); + const database = instance.database(DATABASE_ID); + try { + await instance.delete(); + } catch (err) { + // Ignore error + } + try { + await database.delete(); + } catch (err) { + // Ignore error + } + + const [, operation] = await instance.create({ + config: 'regional-us-central1', + nodes: 1, + labels: { + 'gcloud-sample-tests': 'true', + }, + }); + + await operation.promise(); + + const [instances] = await spanner.getInstances({ + filter: 'labels.gcloud-sample-tests:true', + }); + + await Promise.all( + instances.map(async instance => { + const {operations} = await getOperations(instance.metadata.name); + + await Promise.all( + operations + .filter(operation => { + return operation.metadata['@type'].includes('CreateInstance'); + }) + .filter(operation => { + const yesterday = new Date(); + yesterday.setHours(-24); + + const instanceCreated = new Date(operation.metadata.startTime); + + return instanceCreated < yesterday; + }) + .map(instance.delete) + ); }) - .forEach(async () => await instance.delete()); + ); }); -}); -test.after.always(async () => { - const instance = spanner.instance(INSTANCE_ID); - const database = instance.database(DATABASE_ID); + after(async () => { + const instance = spanner.instance(INSTANCE_ID); + const database = instance.database(DATABASE_ID); - try { await database.delete(); - } catch (err) { - // Ignore error - } - - try { await instance.delete(); - } catch (err) { - // Ignore error - } -}); + }); -// create_database -test.serial(`should create an example database`, async t => { - const results = await tools.runAsyncWithIO( - `${schemaCmd} createDatabase "${INSTANCE_ID}" "${DATABASE_ID}" ${PROJECT_ID}`, - cwd - ); - const output = results.stdout + results.stderr; - t.regex( - output, - new RegExp(`Waiting for operation on ${DATABASE_ID} to complete...`) - ); - t.regex( - output, - new RegExp(`Created database ${DATABASE_ID} on instance ${INSTANCE_ID}.`) - ); -}); + // create_database + it(`should create an example database`, async () => { + const results = await tools.runAsyncWithIO( + `${schemaCmd} createDatabase "${INSTANCE_ID}" "${DATABASE_ID}" ${PROJECT_ID}`, + cwd + ); + const output = results.stdout + results.stderr; + assert.strictEqual( + new RegExp(`Waiting for operation on ${DATABASE_ID} to complete...`).test( + output + ), + true + ); + assert.strictEqual( + new RegExp( + `Created database ${DATABASE_ID} on instance ${INSTANCE_ID}.` + ).test(output), + true + ); + }); -// insert_data -test.serial(`should insert rows into an example table`, async t => { - const results = await tools.runAsyncWithIO( - `${crudCmd} insert ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, - cwd - ); - const output = results.stdout + results.stderr; - t.regex(output, /Inserted data\./); -}); + // insert_data + it(`should insert rows into an example table`, async () => { + const results = await tools.runAsyncWithIO( + `${crudCmd} insert ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, + cwd + ); + const output = results.stdout + results.stderr; + assert.strictEqual(new RegExp(/Inserted data\./).test(output), true); + }); -// query_data -test.serial( - `should query an example table and return matching rows`, - async t => { + // query_data + it(`should query an example table and return matching rows`, async () => { const results = await tools.runAsyncWithIO( `${crudCmd} query ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, cwd ); const output = results.stdout + results.stderr; - t.regex(output, /SingerId: 1, AlbumId: 1, AlbumTitle: Total Junk/); - } -); + assert.strictEqual( + new RegExp(/SingerId: 1, AlbumId: 1, AlbumTitle: Total Junk/).test( + output + ), + true + ); + }); -// read_data -test.serial(`should read an example table`, async t => { - const results = await tools.runAsyncWithIO( - `${crudCmd} read ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, - cwd - ); - const output = results.stdout + results.stderr; - t.regex(output, /SingerId: 1, AlbumId: 1, AlbumTitle: Total Junk/); -}); + // read_data + it(`should read an example table`, async () => { + const results = await tools.runAsyncWithIO( + `${crudCmd} read ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, + cwd + ); + const output = results.stdout + results.stderr; + assert.strictEqual( + new RegExp(/SingerId: 1, AlbumId: 1, AlbumTitle: Total Junk/).test( + output + ), + true + ); + }); -// add_column -test.serial(`should add a column to a table`, async t => { - const results = await tools.runAsyncWithIO( - `${schemaCmd} addColumn ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, - cwd - ); - const output = results.stdout + results.stderr; - t.regex(output, /Waiting for operation to complete\.\.\./); - t.regex(output, /Added the MarketingBudget column\./); -}); + // add_column + it(`should add a column to a table`, async () => { + const results = await tools.runAsyncWithIO( + `${schemaCmd} addColumn ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, + cwd + ); + const output = results.stdout + results.stderr; + assert.strictEqual( + new RegExp(/Waiting for operation to complete\.\.\./).test(output), + true + ); + assert.strictEqual( + new RegExp(/Added the MarketingBudget column\./).test(output), + true + ); + }); -// update_data -test.serial(`should update existing rows in an example table`, async t => { - const results = await tools.runAsyncWithIO( - `${crudCmd} update ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, - cwd - ); - const output = results.stdout + results.stderr; - t.regex(output, /Updated data\./); -}); + // update_data + it(`should update existing rows in an example table`, async () => { + const results = await tools.runAsyncWithIO( + `${crudCmd} update ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, + cwd + ); + const output = results.stdout + results.stderr; + assert.strictEqual(new RegExp(/Updated data\./).test(output), true); + }); -// read_stale_data -test.serial(`should read stale data from an example table`, t => { - t.plan(2); - // read-stale-data reads data that is exactly 15 seconds old. So, make sure - // 15 seconds have elapsed since the update_data test. - return new Promise(resolve => setTimeout(resolve, 16000)).then(async () => { + // read_stale_data + it(`should read stale data from an example table`, async () => { + // read-stale-data reads data that is exactly 15 seconds old. So, make sure + // 15 seconds have elapsed since the update_data test. + await new Promise(r => setTimeout(r, 16000)); const results = await tools.runAsyncWithIO( `${crudCmd} read-stale ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, cwd ); const output = results.stdout + results.stderr; - t.regex( - output, - /SingerId: 1, AlbumId: 1, AlbumTitle: Total Junk, MarketingBudget: 100000/ - ); - t.regex( - output, - /SingerId: 2, AlbumId: 2, AlbumTitle: Forever Hold your Peace, MarketingBudget: 500000/ + assert.strictEqual( + new RegExp( + /SingerId: 1, AlbumId: 1, AlbumTitle: Total Junk, MarketingBudget: 100000/ + ).test(output), + true + ); + assert.strictEqual( + new RegExp( + /SingerId: 2, AlbumId: 2, AlbumTitle: Forever Hold your Peace, MarketingBudget: 500000/ + ).test(output), + true ); }); -}); -// query_data_with_new_column -test.serial( - `should query an example table with an additional column and return matching rows`, - async t => { + // query_data_with_new_column + it(`should query an example table with an additional column and return matching rows`, async () => { const results = await tools.runAsyncWithIO( `${schemaCmd} queryNewColumn ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, cwd ); const output = results.stdout + results.stderr; - t.regex(output, /SingerId: 1, AlbumId: 1, MarketingBudget: 100000/); - t.regex(output, /SingerId: 2, AlbumId: 2, MarketingBudget: 500000/); - } -); + assert.strictEqual( + new RegExp(/SingerId: 1, AlbumId: 1, MarketingBudget: 100000/).test( + output + ), + true + ); + assert.strictEqual( + new RegExp(/SingerId: 2, AlbumId: 2, MarketingBudget: 500000/).test( + output + ), + true + ); + }); -// create_index -test.serial(`should create an index in an example table`, async t => { - const results = await tools.runAsyncWithIO( - `${indexingCmd} createIndex ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, - cwd - ); - const output = results.stdout + results.stderr; - t.regex(output, /Waiting for operation to complete\.\.\./); - t.regex(output, /Added the AlbumsByAlbumTitle index\./); -}); + // create_index + it(`should create an index in an example table`, async () => { + const results = await tools.runAsyncWithIO( + `${indexingCmd} createIndex ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, + cwd + ); + const output = results.stdout + results.stderr; + assert.strictEqual( + new RegExp(/Waiting for operation to complete\.\.\./).test(output), + true + ); + assert.strictEqual( + new RegExp(/Added the AlbumsByAlbumTitle index\./).test(output), + true + ); + }); -// create_storing_index -test.serial(`should create a storing index in an example table`, async t => { - const results = await tools.runAsyncWithIO( - `${indexingCmd} createStoringIndex ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, - cwd - ); - const output = results.stdout + results.stderr; - t.regex(output, /Waiting for operation to complete\.\.\./); - t.regex(output, /Added the AlbumsByAlbumTitle2 index\./); -}); + // create_storing_index + it(`should create a storing index in an example table`, async () => { + const results = await tools.runAsyncWithIO( + `${indexingCmd} createStoringIndex ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, + cwd + ); + const output = results.stdout + results.stderr; + assert.strictEqual( + new RegExp(/Waiting for operation to complete\.\.\./).test(output), + true + ); + assert.strictEqual( + new RegExp(/Added the AlbumsByAlbumTitle2 index\./).test(output), + true + ); + }); -// query_data_with_index -test.serial( - `should query an example table with an index and return matching rows`, - async t => { + // query_data_with_index + it(`should query an example table with an index and return matching rows`, async () => { const results = await tools.runAsyncWithIO( `${indexingCmd} queryIndex ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, cwd ); const output = results.stdout + results.stderr; - t.regex(output, /AlbumId: 2, AlbumTitle: Go, Go, Go, MarketingBudget:/); - t.false( - output.includes(`AlbumId: 1, AlbumTitle: Total Junk, MarketingBudget:`) + assert.strictEqual( + new RegExp(/AlbumId: 2, AlbumTitle: Go, Go, Go, MarketingBudget:/).test( + output + ), + true + ); + assert.deepStrictEqual( + output.includes(`AlbumId: 1, AlbumTitle: Total Junk, MarketingBudget:`), + false ); - } -); + }); -test.serial( - `should respect query boundaries when querying an example table with an index`, - async t => { + it(`should respect query boundaries when querying an example table with an index`, async () => { const results = await tools.runAsyncWithIO( `${indexingCmd} queryIndex ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID} -s Ardvark -e Zoo`, cwd ); const output = results.stdout + results.stderr; - t.regex(output, /AlbumId: 1, AlbumTitle: Total Junk, MarketingBudget:/); - t.regex(output, /AlbumId: 2, AlbumTitle: Go, Go, Go, MarketingBudget:/); - } -); + assert.strictEqual( + new RegExp(/AlbumId: 1, AlbumTitle: Total Junk, MarketingBudget:/).test( + output + ), + true + ); + assert.strictEqual( + new RegExp(/AlbumId: 2, AlbumTitle: Go, Go, Go, MarketingBudget:/).test( + output + ), + true + ); + }); -// read_data_with_index -test.serial(`should read an example table with an index`, async t => { - const results = await tools.runAsyncWithIO( - `${indexingCmd} readIndex ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, - cwd - ); - const output = results.stdout + results.stderr; - t.regex(output, /AlbumId: 1, AlbumTitle: Total Junk/); -}); + // read_data_with_index + it(`should read an example table with an index`, async () => { + const results = await tools.runAsyncWithIO( + `${indexingCmd} readIndex ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, + cwd + ); + const output = results.stdout + results.stderr; + assert.strictEqual( + new RegExp(/AlbumId: 1, AlbumTitle: Total Junk/).test(output), + true + ); + }); -// read_data_with_storing_index -test.serial(`should read an example table with a storing index`, async t => { - const results = await tools.runAsyncWithIO( - `${indexingCmd} readStoringIndex ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, - cwd - ); - const output = results.stdout + results.stderr; - t.regex(output, /AlbumId: 1, AlbumTitle: Total Junk/); -}); + // read_data_with_storing_index + it(`should read an example table with a storing index`, async () => { + const results = await tools.runAsyncWithIO( + `${indexingCmd} readStoringIndex ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, + cwd + ); + const output = results.stdout + results.stderr; + assert.strictEqual( + new RegExp(/AlbumId: 1, AlbumTitle: Total Junk/).test(output), + true + ); + }); -// read_only_transaction -test.serial(`should read an example table using transactions`, async t => { - const results = await tools.runAsyncWithIO( - `${transactionCmd} readOnly ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, - cwd - ); - const output = results.stdout + results.stderr; - t.regex(output, /SingerId: 1, AlbumId: 1, AlbumTitle: Total Junk/); - t.regex(output, /Successfully executed read-only transaction\./); -}); + // read_only_transaction + it(`should read an example table using transactions`, async () => { + const results = await tools.runAsyncWithIO( + `${transactionCmd} readOnly ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, + cwd + ); + const output = results.stdout + results.stderr; + assert.strictEqual( + new RegExp(/SingerId: 1, AlbumId: 1, AlbumTitle: Total Junk/).test( + output + ), + true + ); + assert.strictEqual( + new RegExp(/Successfully executed read-only transaction\./).test(output), + true + ); + }); -// read_write_transaction -test.serial( - `should read from and write to an example table using transactions`, - async t => { + // read_write_transaction + it(`should read from and write to an example table using transactions`, async () => { let results = await tools.runAsyncWithIO( `${transactionCmd} readWrite ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, cwd ); let output = results.stdout + results.stderr; - t.regex(output, /The first album's marketing budget: 100000/); - t.regex(output, /The second album's marketing budget: 500000/); - t.regex( - output, - /Successfully executed read-write transaction to transfer 200000 from Album 2 to Album 1./ + assert.strictEqual( + new RegExp(/The first album's marketing budget: 100000/).test(output), + true + ); + assert.strictEqual( + new RegExp(/The second album's marketing budget: 500000/).test(output), + true + ); + assert.strictEqual( + new RegExp( + /Successfully executed read-write transaction to transfer 200000 from Album 2 to Album 1./ + ).test(output), + true ); - results = await tools.runAsyncWithIO( `${schemaCmd} queryNewColumn ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, cwd ); + output = results.stdout + results.stderr; - t.regex(output, /SingerId: 1, AlbumId: 1, MarketingBudget: 300000/); - t.regex(output, /SingerId: 2, AlbumId: 2, MarketingBudget: 300000/); - } -); + assert.strictEqual( + new RegExp(/SingerId: 1, AlbumId: 1, MarketingBudget: 300000/).test( + output + ), + true + ); + assert.strictEqual( + new RegExp(/SingerId: 2, AlbumId: 2, MarketingBudget: 300000/).test( + output + ), + true + ); + }); -// create_query_partitions -test.serial(`should create query partitions`, async t => { - const instance = spanner.instance(INSTANCE_ID); - const database = instance.database(DATABASE_ID); - const [transaction] = await database.createBatchTransaction(); - const identifier = JSON.stringify(transaction.identifier()); + // create_query_partitions + it(`should create query partitions`, async () => { + const instance = spanner.instance(INSTANCE_ID); + const database = instance.database(DATABASE_ID); + const [transaction] = await database.createBatchTransaction(); + const identifier = JSON.stringify(transaction.identifier()); - const results = await tools.runAsyncWithIO( - `${batchCmd} create-query-partitions ${INSTANCE_ID} ${DATABASE_ID} '${identifier}' ${PROJECT_ID}`, - cwd - ); + const results = await tools.runAsyncWithIO( + `${batchCmd} create-query-partitions ${INSTANCE_ID} ${DATABASE_ID} '${identifier}' ${PROJECT_ID}`, + cwd + ); - const output = results.stdout + results.stderr; + const output = results.stdout + results.stderr; - t.regex(output, /Successfully created \d query partitions\./); + assert.strictEqual( + new RegExp(/Successfully created \d query partitions\./).test(output), + true + ); - await transaction.close(); -}); + await transaction.close(); + }); -// execute_partition -test.serial(`should execute a partition`, async t => { - const instance = spanner.instance(INSTANCE_ID); - const database = instance.database(DATABASE_ID); - const [transaction] = await database.createBatchTransaction(); - const identifier = JSON.stringify(transaction.identifier()); + // execute_partition + it(`should execute a partition`, async () => { + const instance = spanner.instance(INSTANCE_ID); + const database = instance.database(DATABASE_ID); + const [transaction] = await database.createBatchTransaction(); + const identifier = JSON.stringify(transaction.identifier()); - const query = `SELECT SingerId FROM Albums`; - const [partitions] = await transaction.createQueryPartitions(query); - const partition = JSON.stringify(partitions[0]); + const query = `SELECT SingerId FROM Albums`; + const [partitions] = await transaction.createQueryPartitions(query); + const partition = JSON.stringify(partitions[0]); - const results = await tools.runAsyncWithIO( - `${batchCmd} execute-partition ${INSTANCE_ID} ${DATABASE_ID} '${identifier}' '${partition}' ${PROJECT_ID}`, - cwd - ); + const results = await tools.runAsyncWithIO( + `${batchCmd} execute-partition ${INSTANCE_ID} ${DATABASE_ID} '${identifier}' '${partition}' ${PROJECT_ID}`, + cwd + ); - const output = results.stdout + results.stderr; + const output = results.stdout + results.stderr; - t.regex(output, /Successfully received \d from executed partition\./); + assert.strictEqual( + new RegExp(/Successfully received \d from executed partition\./).test( + output + ), + true + ); - await transaction.close(); -}); + await transaction.close(); + }); -// add_timestamp_column -test.serial(`should add a timestamp column to a table`, async t => { - const results = await tools.runAsyncWithIO( - `${timestampCmd} addTimestampColumn ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, - cwd - ); - const output = results.stdout + results.stderr; - t.regex(output, /Waiting for operation to complete\.\.\./); - t.regex( - output, - /Added LastUpdateTime as a commit timestamp column in Albums table\./ - ); -}); + // add_timestamp_column + it(`should add a timestamp column to a table`, async () => { + const results = await tools.runAsyncWithIO( + `${timestampCmd} addTimestampColumn ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, + cwd + ); + const output = results.stdout + results.stderr; + assert.strictEqual( + new RegExp(/Waiting for operation to complete\.\.\./).test(output), + true + ); + assert.strictEqual( + new RegExp( + /Added LastUpdateTime as a commit timestamp column in Albums table\./ + ).test(output), + true + ); + }); -// update_data_with_timestamp_column -test.serial( - `should update existing rows in an example table with commit timestamp column`, - async t => { + // update_data_with_timestamp_column + it(`should update existing rows in an example table with commit timestamp column`, async () => { const results = await tools.runAsyncWithIO( `${timestampCmd} updateWithTimestamp ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, cwd ); const output = results.stdout + results.stderr; - t.regex(output, /Updated data\./); - } -); + assert.strictEqual(new RegExp(/Updated data\./).test(output), true); + }); -// query_data_with_timestamp_column -test.serial( - `should query an example table with an additional timestamp column and return matching rows`, - async t => { + // query_data_with_timestamp_column + it(`should query an example table with an additional timestamp column and return matching rows`, async () => { const results = await tools.runAsyncWithIO( `${timestampCmd} queryWithTimestamp ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, cwd ); const output = results.stdout + results.stderr; - t.regex( - output, - /SingerId: 1, AlbumId: 1, MarketingBudget: 1000000, LastUpdateTime:/ + assert.strictEqual( + new RegExp( + /SingerId: 1, AlbumId: 1, MarketingBudget: 1000000, LastUpdateTime:/ + ).test(output), + true + ); + assert.strictEqual( + new RegExp( + /SingerId: 2, AlbumId: 2, MarketingBudget: 750000, LastUpdateTime:/ + ).test(output), + true ); - t.regex( - output, - /SingerId: 2, AlbumId: 2, MarketingBudget: 750000, LastUpdateTime:/ - ); - } -); + }); -// create_table_with_timestamp_column -test.serial( - `should create an example table with a timestamp column`, - async t => { + // create_table_with_timestamp_column + it(`should create an example table with a timestamp column`, async () => { const results = await tools.runAsyncWithIO( `${timestampCmd} createTableWithTimestamp "${INSTANCE_ID}" "${DATABASE_ID}" ${PROJECT_ID}`, cwd ); const output = results.stdout + results.stderr; - t.regex( - output, - new RegExp(`Waiting for operation on ${DATABASE_ID} to complete...`) - ); - t.regex( - output, - new RegExp(`Created table Performances in database ${DATABASE_ID}.`) + assert.strictEqual( + new RegExp(`Waiting for operation on ${DATABASE_ID} to complete...`).test( + output + ), + true + ); + assert.strictEqual( + new RegExp(`Created table Performances in database ${DATABASE_ID}.`).test( + output + ), + true ); - } -); + }); -// insert_data_with_timestamp -test.serial( - `should insert rows into an example table with timestamp column`, - async t => { + // insert_data_with_timestamp + it(`should insert rows into an example table with timestamp column`, async () => { const results = await tools.runAsyncWithIO( `${timestampCmd} insertWithTimestamp ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, cwd ); const output = results.stdout + results.stderr; - t.regex(output, /Inserted data\./); - } -); + assert.strictEqual(new RegExp(/Inserted data\./).test(output), true); + }); -// query_new_table_with_timestamp -test.serial( - `should query an example table with a non-null timestamp column and return matching rows`, - async t => { + // query_new_table_with_timestamp + it(`should query an example table with a non-null timestamp column and return matching rows`, async () => { const results = await tools.runAsyncWithIO( `${timestampCmd} queryTableWithTimestamp ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, cwd ); const output = results.stdout + results.stderr; - t.regex(output, /SingerId: 1, VenueId: 4, EventDate:/); - t.regex(output, /Revenue: 15000, LastUpdateTime:/); - } -); + assert.strictEqual( + new RegExp(/SingerId: 1, VenueId: 4, EventDate:/).test(output), + true + ); + assert.strictEqual( + new RegExp(/Revenue: 15000, LastUpdateTime:/).test(output), + true + ); + }); -// write_data_for_struct_queries -test.serial( - `should insert rows into an example table for use with struct query examples`, - async t => { + // write_data_for_struct_queries + it(`should insert rows into an example table for use with struct query examples`, async () => { const results = await tools.runAsyncWithIO( `${structCmd} writeDataForStructQueries ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, cwd ); const output = results.stdout + results.stderr; - t.regex(output, /Inserted data\./); - } -); + assert.strictEqual(new RegExp(/Inserted data\./).test(output), true); + }); -// query_with_struct_param -test.serial(`should query an example table with a STRUCT param`, async t => { - const results = await tools.runAsyncWithIO( - `${structCmd} queryDataWithStruct ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, - cwd - ); - const output = results.stdout + results.stderr; - t.regex(output, /SingerId: 6/); -}); + // query_with_struct_param + it(`should query an example table with a STRUCT param`, async () => { + const results = await tools.runAsyncWithIO( + `${structCmd} queryDataWithStruct ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, + cwd + ); + const output = results.stdout + results.stderr; + assert.strictEqual(new RegExp(/SingerId: 6/).test(output), true); + }); -// query_with_array_of_struct_param -test.serial( - `should query an example table with an array of STRUCT param`, - async t => { + // query_with_array_of_struct_param + it(`should query an example table with an array of STRUCT param`, async () => { const results = await tools.runAsyncWithIO( `${structCmd} queryWithArrayOfStruct ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, cwd ); const output = results.stdout + results.stderr; - t.regex(output, /SingerId: 6\nSingerId: 7/); - } -); + assert.strictEqual( + new RegExp(/SingerId: 6\nSingerId: 7/).test(output), + true + ); + }); -// query_with_struct_field_param -test.serial( - `should query an example table with a STRUCT field param`, - async t => { + // query_with_struct_field_param + it(`should query an example table with a STRUCT field param`, async () => { const results = await tools.runAsyncWithIO( `${structCmd} queryStructField ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, cwd ); const output = results.stdout + results.stderr; - t.regex(output, /SingerId: 6/); - } -); + assert.strictEqual(new RegExp(/SingerId: 6/).test(output), true); + }); -// query_with_nested_struct_param -test.serial( - `should query an example table with a nested STRUCT param`, - async t => { + // query_with_nested_struct_param + it(`should query an example table with a nested STRUCT param`, async () => { const results = await tools.runAsyncWithIO( `${structCmd} queryNestedStructField ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, cwd ); const output = results.stdout + results.stderr; - t.regex( - output, - /SingerId: 6, SongName: Imagination\nSingerId: 9, SongName: Imagination/ + assert.strictEqual( + new RegExp( + /SingerId: 6, SongName: Imagination\nSingerId: 9, SongName: Imagination/ + ).test(output), + true ); - } -); + }); -// dml_standard_insert -test.serial( - `should insert rows into an example table using a DML statement`, - async t => { + // dml_standard_insert + it(`should insert rows into an example table using a DML statement`, async () => { const results = await tools.runAsyncWithIO( `${dmlCmd} insertUsingDml ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, cwd ); const output = results.stdout + results.stderr; - t.regex(output, /Successfully inserted 1 record into the Singers table/); - } -); + assert.strictEqual( + new RegExp(/Successfully inserted 1 record into the Singers table/).test( + output + ), + true + ); + }); -// dml_standard_update -test.serial( - `should update a row in an example table using a DML statement`, - async t => { + // dml_standard_update + it(`should update a row in an example table using a DML statement`, async () => { const results = await tools.runAsyncWithIO( `${dmlCmd} updateUsingDml ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, cwd ); const output = results.stdout + results.stderr; - t.regex(output, /Successfully updated 1 record/); - } -); + assert.strictEqual( + new RegExp(/Successfully updated 1 record/).test(output), + true + ); + }); -// dml_standard_delete -test.serial( - `should delete a row from an example table using a DML statement`, - async t => { + // dml_standard_delete + it(`should delete a row from an example table using a DML statement`, async () => { const results = await tools.runAsyncWithIO( `${dmlCmd} deleteUsingDml ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, cwd ); const output = results.stdout + results.stderr; - t.regex(output, /Successfully deleted 1 record\./); - } -); + assert.strictEqual( + new RegExp(/Successfully deleted 1 record\./).test(output), + true + ); + }); -// dml_standard_update_with_timestamp -test.serial( - `should update the timestamp of multiple records in an example table using a DML statement`, - async t => { + // dml_standard_update_with_timestamp + it(`should update the timestamp of multiple records in an example table using a DML statement`, async () => { const results = await tools.runAsyncWithIO( `${dmlCmd} updateUsingDmlWithTimestamp ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, cwd ); const output = results.stdout + results.stderr; - t.regex(output, /Successfully updated 2 records/); - } -); + assert.strictEqual( + new RegExp(/Successfully updated 2 records/).test(output), + true + ); + }); -// dml_write_then_read -test.serial( - `should insert a record in an example table using a DML statement and then query the record`, - async t => { + // dml_write_then_read + it(`should insert a record in an example table using a DML statement and then query the record`, async () => { const results = await tools.runAsyncWithIO( `${dmlCmd} writeAndReadUsingDml ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, cwd ); const output = results.stdout + results.stderr; - t.regex(output, /Timothy Campbell/); - } -); + assert.strictEqual(new RegExp(/Timothy Campbell/).test(output), true); + }); -// dml_structs -test.serial( - `should update a record in an example table using a DML statement along with a struct value`, - async t => { + // dml_structs + it(`should update a record in an example table using a DML statement along with a struct value`, async () => { const results = await tools.runAsyncWithIO( `${dmlCmd} updateUsingDmlWithStruct ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, cwd ); const output = results.stdout + results.stderr; - t.regex(output, /Successfully updated 1 record/); - } -); + assert.strictEqual( + new RegExp(/Successfully updated 1 record/).test(output), + true + ); + }); -// dml_getting_started_insert -test.serial( - `should insert multiple records into an example table using a DML statement`, - async t => { + // dml_getting_started_insert + it(`should insert multiple records into an example table using a DML statement`, async () => { const results = await tools.runAsyncWithIO( `${dmlCmd} writeUsingDml ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, cwd ); const output = results.stdout + results.stderr; - t.regex(output, /4 records inserted/); - } -); + assert.strictEqual(new RegExp(/4 records inserted/).test(output), true); + }); -// dml_getting_started_update -test.serial( - `should transfer value from one record to another using DML statements within a transaction`, - async t => { + // dml_getting_started_update + it(`should transfer value from one record to another using DML statements within a transaction`, async () => { const results = await tools.runAsyncWithIO( `${dmlCmd} writeWithTransactionUsingDml ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, cwd ); const output = results.stdout + results.stderr; - t.regex( - output, - /Successfully executed read-write transaction using DML to transfer 200000 from Album 1 to Album 2/ + assert.strictEqual( + new RegExp( + /Successfully executed read-write transaction using DML to transfer 200000 from Album 1 to Album 2/ + ).test(output), + true ); - } -); + }); -// dml_partitioned_update -test.serial( - `should update multiple records using a partitioned DML statement`, - async t => { + // dml_partitioned_update + it(`should update multiple records using a partitioned DML statement`, async () => { const results = await tools.runAsyncWithIO( `${dmlCmd} updateUsingPartitionedDml ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, cwd ); const output = results.stdout + results.stderr; - t.regex(output, /Successfully updated 3 records/); - } -); + assert.strictEqual( + new RegExp(/Successfully updated 3 records/).test(output), + true + ); + }); -// dml_partitioned_delete -test.serial( - `should delete multiple records using a partitioned DML statement`, - async t => { + // dml_partitioned_delete + it(`should delete multiple records using a partitioned DML statement`, async () => { const results = await tools.runAsyncWithIO( `${dmlCmd} deleteUsingPartitionedDml ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`, cwd ); const output = results.stdout + results.stderr; - t.regex(output, /Successfully deleted 5 records/); - } -); + assert.strictEqual( + new RegExp(/Successfully deleted 5 records/).test(output), + true + ); + }); +}); function apiRequest(reqOpts) { return new Promise((resolve, reject) => { @@ -671,12 +740,7 @@ function apiRequest(reqOpts) { return; } - try { - resolve(JSON.parse(response.body)); - } catch (e) { - reject(e); - return; - } + resolve(JSON.parse(response.body)); }); }) .catch(reject);