Skip to content

Commit

Permalink
fix(deps): upgrade to google-gax 1.x (#651)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus authored and JustinBeckwith committed Jul 8, 2019
1 parent 6705517 commit a32e838
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 28 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@
"events-intercept": "^2.0.0",
"extend": "^3.0.1",
"google-auth-library": "^4.0.0",
"google-gax": "^0.26.0",
"google-gax": "^1.0.0",
"grpc": "^1.21.1",
"grpc-gcp": "^0.1.1",
"is": "^3.2.1",
"lodash.snakecase": "^4.1.1",
"merge-stream": "^2.0.0",
Expand Down
20 changes: 14 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ import {Table} from './table';
import {PartitionedDml, Snapshot, Transaction} from './transaction';
import {GrpcClientOptions} from 'google-gax';
import {ChannelCredentials} from 'grpc';
import {
createGcpApiConfig,
gcpCallInvocationTransformer,
gcpChannelFactoryOverride,
} from 'grpc-gcp';

const grpc = require('grpc');

// Import the clients for each version supported by this package.
const gapic = Object.freeze({
Expand Down Expand Up @@ -212,18 +219,19 @@ class Spanner extends Service {
}
}
}
options = extend(
options = (Object.assign(
{
libName: 'gccl',
libVersion: require('../../package.json').version,
scopes,
// Enable grpc-gcp support
'grpc.callInvocationTransformer': gcpCallInvocationTransformer,
'grpc.channelFactoryOverride': gcpChannelFactoryOverride,
'grpc.gcpApiConfig': createGcpApiConfig(gcpApiConfig),
grpc,
},
options || {}
);

// Enable grpc-gcp support
options = Object.assign({'grpc_gcp.apiConfig': gcpApiConfig}, options);

) as {}) as SpannerOptions;
const config = ({
baseUrl:
options.apiEndpoint ||
Expand Down
50 changes: 29 additions & 21 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import * as pfy from '@google-cloud/promisify';
import * as sinon from 'sinon';
import * as spnr from '../src';

const grpc = require('grpc');

const apiConfig = require('../src/spanner_grpc_config.json');

function getFake(obj: {}) {
Expand All @@ -49,6 +51,16 @@ function fakeReplaceProjectIdToken(...args) {
);
}

const fakeGrpcGcp = {
gcpChannelFactoryOverride: {},
gcpCallInvocationTransformer: {},
createGcpApiConfig: apiConfig => {
return {
calledWith_: apiConfig,
};
},
};

const fakePaginator = {
paginator: {
streamify(methodName) {
Expand Down Expand Up @@ -146,6 +158,7 @@ describe('Spanner', () => {
'google-auth-library': {
GoogleAuth: fakeGoogleAuth,
},
'grpc-gcp': fakeGrpcGcp,
'./codec.js': {codec: fakeCodec},
'./instance.js': {Instance: FakeInstance},
'./v1': fakeV1,
Expand All @@ -170,6 +183,19 @@ describe('Spanner', () => {
afterEach(() => sandbox.restore());

describe('instantiation', () => {
const EXPECTED_OPTIONS = extend({}, OPTIONS, {
libName: 'gccl',
libVersion: require('../../package.json').version,
scopes: [],
grpc,
'grpc.callInvocationTransformer':
fakeGrpcGcp.gcpCallInvocationTransformer,
'grpc.channelFactoryOverride': fakeGrpcGcp.gcpChannelFactoryOverride,
'grpc.gcpApiConfig': {
calledWith_: apiConfig,
},
});

it('should localize a cached gapic client map', () => {
assert(spanner.clients_ instanceof Map);
assert.strictEqual(spanner.clients_.size, 0);
Expand All @@ -189,16 +215,9 @@ describe('Spanner', () => {
});

it('should create an auth instance from google-auth-library', () => {
const expectedOptions = extend({}, OPTIONS, {
libName: 'gccl',
libVersion: require('../../package.json').version,
scopes: [],
'grpc_gcp.apiConfig': apiConfig,
});

assert.deepStrictEqual(
getFake(spanner.auth).calledWith_[0],
expectedOptions
EXPECTED_OPTIONS
);
});

Expand All @@ -210,11 +229,8 @@ describe('Spanner', () => {

const spanner = new Spanner(OPTIONS);

const expectedOptions = extend({}, OPTIONS, {
libName: 'gccl',
libVersion: require('../../package.json').version,
const expectedOptions = extend({}, EXPECTED_OPTIONS, {
scopes: expectedScopes,
'grpc_gcp.apiConfig': apiConfig,
});

assert.deepStrictEqual(
Expand Down Expand Up @@ -242,15 +258,7 @@ describe('Spanner', () => {
packageJson: require('../../package.json'),
});

assert.deepStrictEqual(
options,
extend({}, OPTIONS, {
libName: 'gccl',
libVersion: require('../../package.json').version,
scopes: [],
'grpc_gcp.apiConfig': apiConfig,
})
);
assert.deepStrictEqual(options, EXPECTED_OPTIONS);
});

it('should optionally accept a servicePath', () => {
Expand Down

0 comments on commit a32e838

Please sign in to comment.