Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit cd45aa0

Browse files
authored
test: Add a test that confirms errors are properly passed through for getInstance calls (#1606)
## Description This test confirms that errors will bubble up to the user for getInstances calls which allows us to close b/388499540 as not reproducible. ## Impact Just adding a test to confirm correct client library behaviour ## Additional Information Two files were edited: - One is the test file where we added the new test - The other is the file that defines mock services where we needed to add a mock service for the admin client
1 parent 75d1a6f commit cd45aa0

2 files changed

Lines changed: 60 additions & 1 deletion

File tree

src/util/mock-servers/service-implementations/bigtable-client-mock-service.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,10 @@ export class BigtableClientMockService extends MockService {
3636
// @ts-ignore
3737
proto.google.bigtable.v2.Bigtable.service;
3838
}
39+
40+
export class BigtableAdminClientMockService extends MockService {
41+
service =
42+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
43+
// @ts-ignore
44+
proto.google.bigtable.admin.v2.BigtableInstanceAdmin.service;
45+
}

test/errors.ts

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ import * as assert from 'assert';
2222

2323
import {GoogleError, grpc, ServiceError} from 'google-gax';
2424
import {MockServer} from '../src/util/mock-servers/mock-server';
25-
import {BigtableClientMockService} from '../src/util/mock-servers/service-implementations/bigtable-client-mock-service';
25+
import {
26+
BigtableAdminClientMockService,
27+
BigtableClientMockService,
28+
} from '../src/util/mock-servers/service-implementations/bigtable-client-mock-service';
2629
import {MockService} from '../src/util/mock-servers/mock-service';
2730

2831
function isServiceError(error: any): error is ServiceError {
@@ -147,3 +150,52 @@ describe('Bigtable/Errors', () => {
147150
server.shutdown(() => {});
148151
});
149152
});
153+
154+
describe('BigtableAdminClient/Errors', () => {
155+
let server: MockServer;
156+
let bigtable: Bigtable;
157+
let service: MockService;
158+
159+
before(async () => {
160+
// make sure we have everything initialized before starting tests
161+
const port = await new Promise<string>(resolve => {
162+
server = new MockServer(resolve);
163+
});
164+
bigtable = new Bigtable({
165+
apiEndpoint: `localhost:${port}`,
166+
});
167+
service = new BigtableAdminClientMockService(server);
168+
});
169+
170+
describe('with getInstances', () => {
171+
const emitGetInstancesError = (stream: any) => {
172+
const metadata = new grpc.Metadata();
173+
stream.emit('error', {
174+
code: 5,
175+
details: 'getInstances error details',
176+
metadata,
177+
});
178+
};
179+
before(async () => {
180+
service.setService({
181+
listInstances: emitGetInstancesError,
182+
});
183+
});
184+
it('should produce human readable error when passing through gax', async () => {
185+
try {
186+
await bigtable.getInstances();
187+
assert.fail(
188+
'An error should have been thrown by the getInstances call',
189+
);
190+
} catch (err) {
191+
assert.strictEqual(
192+
(err as ServiceError).message,
193+
'5 NOT_FOUND: getInstances error details',
194+
);
195+
}
196+
});
197+
});
198+
after(async () => {
199+
server.shutdown(() => {});
200+
});
201+
});

0 commit comments

Comments
 (0)