Skip to content

Commit

Permalink
fix: update @google-cloud/common dependency to 0.25.3 (#871)
Browse files Browse the repository at this point in the history
  • Loading branch information
kjin authored Sep 27, 2018
1 parent f722200 commit 23a0616
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 141 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"typescript": "~3.0.0"
},
"dependencies": {
"@google-cloud/common": "^0.23.0",
"@google-cloud/common": "^0.25.3",
"builtin-modules": "^3.0.0",
"console-log-level": "^1.4.0",
"continuation-local-storage": "^3.2.1",
Expand Down
139 changes: 0 additions & 139 deletions test/test-config-credentials.ts

This file was deleted.

73 changes: 73 additions & 0 deletions test/test-trace-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@

import {Service} from '@google-cloud/common';
import * as assert from 'assert';
import {GoogleAuth} from 'google-auth-library';
import {JWTInput} from 'google-auth-library/build/src/auth/credentials';
import {RefreshOptions} from 'google-auth-library/build/src/auth/oauth2client';
import {OutgoingHttpHeaders} from 'http';
import * as nock from 'nock';
import * as os from 'os';
import * as path from 'path';
import {Response} from 'request'; // Only for type declarations.
import * as shimmer from 'shimmer';

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

interface TestCredentials {
client_id?: string;
client_secret?: string;
refresh_token?: string;
private_key?: string;
type?: string;
}

interface DecorateRequestOptions {
method: string;
uri: string;
Expand Down Expand Up @@ -116,6 +128,67 @@ describe('Trace Writer', () => {
nock.cleanAll();
});

describe('constructor', () => {
// Utility method which, for a given config, constructs a new TraceWriter
// instance, and gets the credentials that would be used upon initiating
// a trace batch publish.
const captureCredentialsForConfig =
async (config: Partial<TraceWriterConfig>) => {
const writer =
new TraceWriter(Object.assign({}, DEFAULT_CONFIG, config), logger);
let capturedJson;
shimmer.wrap(writer.authClient, 'fromJSON', (fromJSON) => {
return function(
this: GoogleAuth, json: JWTInput, options?: RefreshOptions) {
capturedJson = json;
return fromJSON.call(this, json, options);
};
});
await writer.authClient.getClient();
shimmer.unwrap(writer.authClient, 'fromJSON');
return capturedJson;
};

beforeEach(() => {
// Just for this scenario, use real metadata endpoints
metadataScopes.cancel();
nock.cleanAll();
});

it('should use the keyFilename field of the config object', async () => {
const expectedCredentials: TestCredentials =
require('./fixtures/gcloud-credentials.json');
const actualCredentials = await captureCredentialsForConfig({
projectId: 'my-project',
keyFilename: path.join('test', 'fixtures', 'gcloud-credentials.json')
});
assert.deepStrictEqual(actualCredentials, expectedCredentials);
});

it('should use the credentials field of the config object', async () => {
const expectedCredentials: TestCredentials =
require('./fixtures/gcloud-credentials.json');
const actualCredentials = await captureCredentialsForConfig(
{projectId: 'my-project', credentials: expectedCredentials});
assert.deepStrictEqual(actualCredentials, expectedCredentials);
});

it('should ignore keyFilename if credentials is provided', async () => {
const expectedCredentials: TestCredentials = {
client_id: 'a',
client_secret: 'b',
refresh_token: 'c',
type: 'authorized_user'
};
const actualCredentials = await captureCredentialsForConfig({
projectId: 'my-project',
keyFilename: path.join('test', 'fixtures', 'gcloud-credentials.json'),
credentials: expectedCredentials
});
assert.deepStrictEqual(actualCredentials, expectedCredentials);
});
});

describe('initialization process', () => {
it('gets the project ID when none is passed in', (done) => {
const writer = new TraceWriter(DEFAULT_CONFIG, logger);
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"test/test-cls.ts",
"test/test-cls-ah.ts",
"test/test-config-cls.ts",
"test/test-config-credentials.ts",
"test/test-config-plugins.ts",
"test/test-default-ignore-ah-health.ts",
"test/test-env-log-level.ts",
Expand Down

0 comments on commit 23a0616

Please sign in to comment.