Skip to content

Commit b754e81

Browse files
committed
resolve lint errors, fix header, remove todos
1 parent 93e7861 commit b754e81

File tree

1 file changed

+92
-98
lines changed

1 file changed

+92
-98
lines changed

system-test/datasets.ts

Lines changed: 92 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017 Google LLC
1+
// Copyright 2025 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -14,123 +14,117 @@
1414

1515
'use strict';
1616

17-
import * as protos from '../protos/protos'
17+
import * as protos from '../protos/protos';
1818
import {BigQueryClient} from '../src';
19-
import assert = require('assert')
20-
const cp = require('child_process');
19+
import assert = require('assert');
2120
const {randomUUID} = require('crypto');
21+
import {GoogleError} from 'google-gax';
2222

2323
const GCLOUD_TESTS_PREFIX = 'nodejs_samples_tests';
2424
const datasetId = `${GCLOUD_TESTS_PREFIX}_datasets_${randomUUID()}`.replace(
2525
/-/gi,
2626
'_',
2727
);
2828

29-
//TODO(coleleah): remove fallback: false if needed
30-
const bigquery = new BigQueryClient({}, {opts:{fallback: false}});
3129
// the GCLOUD_PROJECT environment variable is set as part of test harness setup
3230
const projectId = process.env.GCLOUD_PROJECT;
3331

3432
describe('Datasets', () => {
35-
//TODO(coleleah): update
3633
before(async () => {
37-
// // Delete any stale datasets from samples tests
38-
// await deleteDatasets();
39-
if (projectId===undefined){
40-
throw Error("GCLOUD_PROJECT must be defined as an environment variable before tests can be run")
41-
34+
if (projectId === undefined) {
35+
throw Error(
36+
'GCLOUD_PROJECT must be defined as an environment variable before tests can be run',
37+
);
4238
}
4339
});
4440

45-
// beforeEach(async function () {
46-
// this.currentTest.retries(2);
47-
// });
41+
beforeEach(async function () {
42+
this.currentTest.retries(2);
43+
});
44+
4845

49-
// after(async () => {
50-
// await bigquery.dataset(datasetId).delete({force: true}).catch(console.warn);
51-
// });
5246
describe('dataset creation', () => {
53-
const usCentral1Bigquery = new BigQueryClient({}, {opts: {
54-
apiEndpoint: 'bigquery.us-central1.rep.googleapis.com',
55-
}});
56-
const usCentral1DatasetId = datasetId + '_uscentral1';
57-
58-
after('clean up dataset creation tests', async () => {
59-
const usCentral1Request = {
60-
projectId: projectId,
61-
datasetId: usCentral1DatasetId,
62-
};
63-
await usCentral1Bigquery.deleteDataset(usCentral1Request)
64-
65-
})
66-
67-
it('should create a dataset using a regional endpoint', async () => {
68-
// Construct the dataset resource.
69-
const dataset = {
70-
datasetReference: {
71-
datasetId: usCentral1DatasetId,
47+
const usCentral1Bigquery = new BigQueryClient(
48+
{},
49+
{
50+
opts: {
51+
apiEndpoint: 'bigquery.us-central1.rep.googleapis.com',
52+
},
7253
},
73-
location: 'us-central1'
74-
};
75-
76-
// Construct the request object.
77-
const request = {
78-
projectId: projectId,
79-
dataset: dataset,
80-
};
81-
await usCentral1Bigquery.insertDataset(request);
82-
const getRequest = {
83-
projectId: projectId,
84-
datasetId: usCentral1DatasetId
85-
}
54+
);
55+
const usCentral1DatasetId = datasetId + '_uscentral1';
8656

87-
// we have to typecast this because response can be void when getDataset is called synchronously
88-
// it is safe to typecast here because we are calling asynchronously
89-
const response = await usCentral1Bigquery.getDataset(getRequest) as [
90-
protos.google.cloud.bigquery.v2.IDataset,
91-
protos.google.cloud.bigquery.v2.IGetDatasetRequest | undefined,
92-
{} | undefined,
93-
]
94-
assert.strictEqual(response[0].id, `${projectId}:${usCentral1DatasetId}`);
95-
});
96-
97-
//TODO(coleleah): fix
98-
//captured in b/429419330
99-
it.skip('should fail to create a dataset using a different region from the client endpoint', async () => {
100-
const usEast4DatasetId = datasetId + '_us-east4';
101-
102-
// Construct the dataset resource
103-
// with a location that does not match the client
104-
// which uses us-central1
105-
const dataset = {
106-
datasetReference: {
107-
datasetId: usEast4DatasetId,
108-
},
109-
location: 'us-east4'
110-
};
111-
112-
// Construct the request object.
113-
const request = {
114-
projectId: projectId,
115-
dataset: dataset,
116-
};
117-
let error;
118-
try {
57+
after('clean up dataset creation tests', async () => {
58+
const usCentral1Request = {
59+
projectId: projectId,
60+
datasetId: usCentral1DatasetId,
61+
};
62+
await usCentral1Bigquery.deleteDataset(usCentral1Request);
63+
});
64+
65+
it('should create a dataset using a regional endpoint', async () => {
66+
// Construct the dataset resource.
67+
const dataset = {
68+
datasetReference: {
69+
datasetId: usCentral1DatasetId,
70+
},
71+
location: 'us-central1',
72+
};
73+
74+
// Construct the request object.
75+
const request = {
76+
projectId: projectId,
77+
dataset: dataset,
78+
};
11979
await usCentral1Bigquery.insertDataset(request);
120-
} catch (err: unknown) {
121-
console.log(err)
122-
error = err;
123-
}
124-
assert.notStrictEqual(error, null);
125-
//TODO(coleleah) fix typing
126-
//@ts-ignore
127-
assert.strictEqual(error.message, 'Invalid storage region');
80+
const getRequest = {
81+
projectId: projectId,
82+
datasetId: usCentral1DatasetId,
83+
};
84+
85+
// we have to typecast this because response can be void when getDataset is called synchronously
86+
// it is safe to typecast here because we are calling asynchronously
87+
const response = (await usCentral1Bigquery.getDataset(getRequest)) as [
88+
protos.google.cloud.bigquery.v2.IDataset,
89+
protos.google.cloud.bigquery.v2.IGetDatasetRequest | undefined,
90+
{} | undefined,
91+
];
92+
assert.strictEqual(response[0].id, `${projectId}:${usCentral1DatasetId}`);
93+
});
94+
95+
//TODO(coleleah): fix
96+
//captured in b/429419330
97+
it.skip('should fail to create a dataset using a different region from the client endpoint', async () => {
98+
const usEast4DatasetId = datasetId + '_us-east4';
99+
100+
// Construct the dataset resource
101+
// with a location that does not match the client
102+
// which uses us-central1
103+
const dataset = {
104+
datasetReference: {
105+
datasetId: usEast4DatasetId,
106+
},
107+
location: 'us-east4',
108+
};
109+
110+
// Construct the request object.
111+
const request = {
112+
projectId: projectId,
113+
dataset: dataset,
114+
};
115+
let error;
116+
try {
117+
await usCentral1Bigquery.insertDataset(request);
118+
} catch (err: unknown) {
119+
console.log(err);
120+
error = err;
121+
}
122+
assert.notStrictEqual(error, null);
123+
124+
assert.strictEqual(
125+
(error as GoogleError).message,
126+
'Invalid storage region',
127+
);
128+
});
128129
});
129-
130-
})
131-
132-
133-
134-
135-
136-
});
130+
});

0 commit comments

Comments
 (0)