Skip to content

Commit

Permalink
feat: add collation feature tests (#1188)
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarowolfx committed Mar 9, 2023
1 parent c20d12d commit 80d86ba
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
17 changes: 17 additions & 0 deletions samples/test/datasets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,23 @@ describe('Datasets', () => {
assert.equal(error.message, 'Invalid storage region');
});

it('should create/update a dataset with a different default collation', async () => {
const bigquery = new BigQuery({});
const collationDatasetId = datasetId + '_collation_test';
await bigquery.createDataset(collationDatasetId, {
defaultCollation: 'und:ci',
});
const dataset = await bigquery.dataset(collationDatasetId);
const [exists] = await dataset.exists();
assert.ok(exists);
let [md] = await dataset.getMetadata();
assert.equal(md.defaultCollation, 'und:ci');
md.defaultCollation = '';
await dataset.setMetadata(md);
[md] = await dataset.getMetadata();
assert.equal(md.defaultCollation, '');
});

it('should list datasets', async () => {
const output = execSync('node listDatasets.js');
assert.match(output, /Datasets:/);
Expand Down
42 changes: 42 additions & 0 deletions samples/test/tables.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const exportJSONFileName = 'data.json';
const importFileName = 'data.avro';
const partialDataFileName = 'partialdata.csv';
const localFilePath = path.join(__dirname, `../resources/${importFileName}`);
const testExpirationTime = Date.now() + 2 * 60 * 60 * 1000; // Add two hours
let projectId;
let policyTag0;
let policyTag1;
Expand Down Expand Up @@ -266,6 +267,47 @@ describe('Tables', () => {
assert.include(output, nonexistentTableId);
});

it('should create/update a table with default collation', async () => {
const collationTableId = tableId + '_collation_test';
const [table] = await bigquery
.dataset(datasetId)
.createTable(collationTableId, {
schema: [
{name: 'name', type: 'STRING'},
{name: 'nums', type: 'INTEGER'},
],
defaultCollation: 'und:ci',
expirationTime: testExpirationTime,
});
let [md] = await table.getMetadata();
assert.equal(md.defaultCollation, 'und:ci');
for (const field of md.schema.fields) {
if (field.type === 'STRING') {
assert.equal(field.collation, 'und:ci');
}
}
// update table collation to case sensitive
md.defaultCollation = '';
await table.setMetadata(md);
[md] = await table.getMetadata();
assert.equal(md.defaultCollation, '');

// add field with different collation
md.schema.fields.push({
name: 'another_name',
type: 'STRING',
collation: 'und:ci',
});
await table.setMetadata(md);

[md] = await table.getMetadata();
for (const field of md.schema.fields) {
if (field.type === 'STRING') {
assert.equal(field.collation, 'und:ci');
}
}
});

it('should list tables', async () => {
const output = execSync(`node listTables.js ${datasetId}`);
assert.match(output, /Tables:/);
Expand Down

0 comments on commit 80d86ba

Please sign in to comment.