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

Commit 23a0616

Browse files
authored
fix: update @google-cloud/common dependency to 0.25.3 (#871)
1 parent f722200 commit 23a0616

4 files changed

Lines changed: 74 additions & 141 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
"typescript": "~3.0.0"
9595
},
9696
"dependencies": {
97-
"@google-cloud/common": "^0.23.0",
97+
"@google-cloud/common": "^0.25.3",
9898
"builtin-modules": "^3.0.0",
9999
"console-log-level": "^1.4.0",
100100
"continuation-local-storage": "^3.2.1",

test/test-config-credentials.ts

Lines changed: 0 additions & 139 deletions
This file was deleted.

test/test-trace-writer.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616

1717
import {Service} from '@google-cloud/common';
1818
import * as assert from 'assert';
19+
import {GoogleAuth} from 'google-auth-library';
20+
import {JWTInput} from 'google-auth-library/build/src/auth/credentials';
21+
import {RefreshOptions} from 'google-auth-library/build/src/auth/oauth2client';
1922
import {OutgoingHttpHeaders} from 'http';
2023
import * as nock from 'nock';
2124
import * as os from 'os';
25+
import * as path from 'path';
2226
import {Response} from 'request'; // Only for type declarations.
2327
import * as shimmer from 'shimmer';
2428

@@ -30,6 +34,14 @@ import {TestLogger} from './logger';
3034
import {hostname, instanceId, oauth2} from './nocks';
3135
import {wait} from './utils';
3236

37+
interface TestCredentials {
38+
client_id?: string;
39+
client_secret?: string;
40+
refresh_token?: string;
41+
private_key?: string;
42+
type?: string;
43+
}
44+
3345
interface DecorateRequestOptions {
3446
method: string;
3547
uri: string;
@@ -116,6 +128,67 @@ describe('Trace Writer', () => {
116128
nock.cleanAll();
117129
});
118130

131+
describe('constructor', () => {
132+
// Utility method which, for a given config, constructs a new TraceWriter
133+
// instance, and gets the credentials that would be used upon initiating
134+
// a trace batch publish.
135+
const captureCredentialsForConfig =
136+
async (config: Partial<TraceWriterConfig>) => {
137+
const writer =
138+
new TraceWriter(Object.assign({}, DEFAULT_CONFIG, config), logger);
139+
let capturedJson;
140+
shimmer.wrap(writer.authClient, 'fromJSON', (fromJSON) => {
141+
return function(
142+
this: GoogleAuth, json: JWTInput, options?: RefreshOptions) {
143+
capturedJson = json;
144+
return fromJSON.call(this, json, options);
145+
};
146+
});
147+
await writer.authClient.getClient();
148+
shimmer.unwrap(writer.authClient, 'fromJSON');
149+
return capturedJson;
150+
};
151+
152+
beforeEach(() => {
153+
// Just for this scenario, use real metadata endpoints
154+
metadataScopes.cancel();
155+
nock.cleanAll();
156+
});
157+
158+
it('should use the keyFilename field of the config object', async () => {
159+
const expectedCredentials: TestCredentials =
160+
require('./fixtures/gcloud-credentials.json');
161+
const actualCredentials = await captureCredentialsForConfig({
162+
projectId: 'my-project',
163+
keyFilename: path.join('test', 'fixtures', 'gcloud-credentials.json')
164+
});
165+
assert.deepStrictEqual(actualCredentials, expectedCredentials);
166+
});
167+
168+
it('should use the credentials field of the config object', async () => {
169+
const expectedCredentials: TestCredentials =
170+
require('./fixtures/gcloud-credentials.json');
171+
const actualCredentials = await captureCredentialsForConfig(
172+
{projectId: 'my-project', credentials: expectedCredentials});
173+
assert.deepStrictEqual(actualCredentials, expectedCredentials);
174+
});
175+
176+
it('should ignore keyFilename if credentials is provided', async () => {
177+
const expectedCredentials: TestCredentials = {
178+
client_id: 'a',
179+
client_secret: 'b',
180+
refresh_token: 'c',
181+
type: 'authorized_user'
182+
};
183+
const actualCredentials = await captureCredentialsForConfig({
184+
projectId: 'my-project',
185+
keyFilename: path.join('test', 'fixtures', 'gcloud-credentials.json'),
186+
credentials: expectedCredentials
187+
});
188+
assert.deepStrictEqual(actualCredentials, expectedCredentials);
189+
});
190+
});
191+
119192
describe('initialization process', () => {
120193
it('gets the project ID when none is passed in', (done) => {
121194
const writer = new TraceWriter(DEFAULT_CONFIG, logger);

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"test/test-cls.ts",
2828
"test/test-cls-ah.ts",
2929
"test/test-config-cls.ts",
30-
"test/test-config-credentials.ts",
3130
"test/test-config-plugins.ts",
3231
"test/test-default-ignore-ah-health.ts",
3332
"test/test-env-log-level.ts",

0 commit comments

Comments
 (0)