Skip to content

Commit

Permalink
feat: use stub for warn method in test (#921)
Browse files Browse the repository at this point in the history
  • Loading branch information
alicejli committed Jul 12, 2021
1 parent bbc4330 commit 0c8479e
Show file tree
Hide file tree
Showing 60 changed files with 1,241 additions and 13 deletions.
4 changes: 4 additions & 0 deletions baselines/asset/src/v1/asset_service_client.ts.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class AssetServiceClient {
longrunning: {},
batching: {},
};
warn: (code: string, message: string, warnType?: string) => void;
innerApiCalls: {[name: string]: Function};
pathTemplates: {[name: string]: gax.PathTemplate};
operationsClient: gax.OperationsClient;
Expand Down Expand Up @@ -187,6 +188,9 @@ export class AssetServiceClient {
// of calling the API is handled in `google-gax`, with this code
// merely providing the destination and request information.
this.innerApiCalls = {};

// Add a warn function to the client constructor so it can be easily tested.
this.warn = gax.warn;
}

/**
Expand Down
24 changes: 24 additions & 0 deletions baselines/asset/test/gapic_asset_service_v1.ts.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ describe('v1.AssetServiceClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.asset.v1.BatchGetAssetsHistoryRequest());
request.parent = '';
Expand All @@ -164,6 +165,7 @@ describe('v1.AssetServiceClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.asset.v1.BatchGetAssetsHistoryRequest());
request.parent = '';
Expand Down Expand Up @@ -199,6 +201,7 @@ describe('v1.AssetServiceClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.asset.v1.BatchGetAssetsHistoryRequest());
request.parent = '';
Expand All @@ -224,6 +227,7 @@ describe('v1.AssetServiceClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.asset.v1.CreateFeedRequest());
request.parent = '';
Expand All @@ -248,6 +252,7 @@ describe('v1.AssetServiceClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.asset.v1.CreateFeedRequest());
request.parent = '';
Expand Down Expand Up @@ -283,6 +288,7 @@ describe('v1.AssetServiceClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.asset.v1.CreateFeedRequest());
request.parent = '';
Expand All @@ -308,6 +314,7 @@ describe('v1.AssetServiceClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.asset.v1.GetFeedRequest());
request.name = '';
Expand All @@ -332,6 +339,7 @@ describe('v1.AssetServiceClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.asset.v1.GetFeedRequest());
request.name = '';
Expand Down Expand Up @@ -367,6 +375,7 @@ describe('v1.AssetServiceClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.asset.v1.GetFeedRequest());
request.name = '';
Expand All @@ -392,6 +401,7 @@ describe('v1.AssetServiceClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.asset.v1.ListFeedsRequest());
request.parent = '';
Expand All @@ -416,6 +426,7 @@ describe('v1.AssetServiceClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.asset.v1.ListFeedsRequest());
request.parent = '';
Expand Down Expand Up @@ -451,6 +462,7 @@ describe('v1.AssetServiceClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.asset.v1.ListFeedsRequest());
request.parent = '';
Expand All @@ -476,6 +488,7 @@ describe('v1.AssetServiceClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.asset.v1.UpdateFeedRequest());
request.feed = {};
Expand All @@ -501,6 +514,7 @@ describe('v1.AssetServiceClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.asset.v1.UpdateFeedRequest());
request.feed = {};
Expand Down Expand Up @@ -537,6 +551,7 @@ describe('v1.AssetServiceClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.asset.v1.UpdateFeedRequest());
request.feed = {};
Expand All @@ -563,6 +578,7 @@ describe('v1.AssetServiceClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.asset.v1.DeleteFeedRequest());
request.name = '';
Expand All @@ -587,6 +603,7 @@ describe('v1.AssetServiceClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.asset.v1.DeleteFeedRequest());
request.name = '';
Expand Down Expand Up @@ -622,6 +639,7 @@ describe('v1.AssetServiceClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.asset.v1.DeleteFeedRequest());
request.name = '';
Expand All @@ -647,6 +665,7 @@ describe('v1.AssetServiceClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.asset.v1.ExportAssetsRequest());
request.parent = '';
Expand All @@ -672,6 +691,7 @@ describe('v1.AssetServiceClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.asset.v1.ExportAssetsRequest());
request.parent = '';
Expand Down Expand Up @@ -710,6 +730,7 @@ describe('v1.AssetServiceClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.asset.v1.ExportAssetsRequest());
request.parent = '';
Expand All @@ -733,6 +754,7 @@ describe('v1.AssetServiceClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.asset.v1.ExportAssetsRequest());
request.parent = '';
Expand All @@ -757,6 +779,7 @@ describe('v1.AssetServiceClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const expectedResponse = generateSampleMessage(new operationsProtos.google.longrunning.Operation());
expectedResponse.name = 'test';
Expand All @@ -775,6 +798,7 @@ describe('v1.AssetServiceClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const expectedError = new Error('expected');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class BigQueryStorageClient {
longrunning: {},
batching: {},
};
warn: (code: string, message: string, warnType?: string) => void;
innerApiCalls: {[name: string]: Function};
pathTemplates: {[name: string]: gax.PathTemplate};
bigQueryStorageStub?: Promise<{[name: string]: Function}>;
Expand Down Expand Up @@ -169,6 +170,9 @@ export class BigQueryStorageClient {
// of calling the API is handled in `google-gax`, with this code
// merely providing the destination and request information.
this.innerApiCalls = {};

// Add a warn function to the client constructor so it can be easily tested.
this.warn = gax.warn;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ describe('v1beta1.BigQueryStorageClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest());
request.tableReference = {};
Expand Down Expand Up @@ -165,6 +166,7 @@ describe('v1beta1.BigQueryStorageClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest());
request.tableReference = {};
Expand Down Expand Up @@ -203,6 +205,7 @@ describe('v1beta1.BigQueryStorageClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest());
request.tableReference = {};
Expand Down Expand Up @@ -231,6 +234,7 @@ describe('v1beta1.BigQueryStorageClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.bigquery.storage.v1beta1.BatchCreateReadSessionStreamsRequest());
request.session = {};
Expand All @@ -256,6 +260,7 @@ describe('v1beta1.BigQueryStorageClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.bigquery.storage.v1beta1.BatchCreateReadSessionStreamsRequest());
request.session = {};
Expand Down Expand Up @@ -292,6 +297,7 @@ describe('v1beta1.BigQueryStorageClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.bigquery.storage.v1beta1.BatchCreateReadSessionStreamsRequest());
request.session = {};
Expand All @@ -318,6 +324,7 @@ describe('v1beta1.BigQueryStorageClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.bigquery.storage.v1beta1.FinalizeStreamRequest());
request.stream = {};
Expand All @@ -343,6 +350,7 @@ describe('v1beta1.BigQueryStorageClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.bigquery.storage.v1beta1.FinalizeStreamRequest());
request.stream = {};
Expand Down Expand Up @@ -379,6 +387,7 @@ describe('v1beta1.BigQueryStorageClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.bigquery.storage.v1beta1.FinalizeStreamRequest());
request.stream = {};
Expand All @@ -405,6 +414,7 @@ describe('v1beta1.BigQueryStorageClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.bigquery.storage.v1beta1.SplitReadStreamRequest());
request.originalStream = {};
Expand All @@ -430,6 +440,7 @@ describe('v1beta1.BigQueryStorageClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.bigquery.storage.v1beta1.SplitReadStreamRequest());
request.originalStream = {};
Expand Down Expand Up @@ -466,6 +477,7 @@ describe('v1beta1.BigQueryStorageClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.bigquery.storage.v1beta1.SplitReadStreamRequest());
request.originalStream = {};
Expand All @@ -492,6 +504,7 @@ describe('v1beta1.BigQueryStorageClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest());
request.readPosition = {};
Expand Down Expand Up @@ -527,6 +540,7 @@ describe('v1beta1.BigQueryStorageClient', () => {
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
const stub = sinon.stub(client, 'warn');
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest());
request.readPosition = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class DeprecatedServiceClient {
longrunning: {},
batching: {},
};
warn: (code: string, message: string, warnType?: string) => void;
innerApiCalls: {[name: string]: Function};
deprecatedServiceStub?: Promise<{[name: string]: Function}>;

Expand Down Expand Up @@ -150,6 +151,9 @@ export class DeprecatedServiceClient {
// of calling the API is handled in `google-gax`, with this code
// merely providing the destination and request information.
this.innerApiCalls = {};

// Add a warn function to the client constructor so it can be easily tested.
this.warn = gax.warn;
}

/**
Expand All @@ -166,7 +170,7 @@ export class DeprecatedServiceClient {
initialize() {
// If the client stub promise is already initialized, return immediately.
if (this.deprecatedServiceStub) {
gax.warn('DEP$DeprecatedService', 'DeprecatedService is deprecated and may be removed in a future version.', 'DeprecationWarning');
this.warn('DEP$DeprecatedService', 'DeprecatedService is deprecated and may be removed in a future version.', 'DeprecationWarning');
return this.deprecatedServiceStub;
}

Expand Down Expand Up @@ -206,7 +210,7 @@ export class DeprecatedServiceClient {

this.innerApiCalls[methodName] = apiCall;
}
gax.warn('DEP$DeprecatedService', 'DeprecatedService is deprecated and may be removed in a future version.', 'DeprecationWarning');
this.warn('DEP$DeprecatedService', 'DeprecatedService is deprecated and may be removed in a future version.', 'DeprecationWarning');

return this.deprecatedServiceStub;
}
Expand Down Expand Up @@ -392,7 +396,7 @@ export class DeprecatedServiceClient {
}
options = options || {};
this.initialize();
gax.warn('DEP$DeprecatedService-$SlowFibonacci','SlowFibonacci is deprecated and may be removed in a future version.', 'DeprecationWarning');
this.warn('DEP$DeprecatedService-$SlowFibonacci','SlowFibonacci is deprecated and may be removed in a future version.', 'DeprecationWarning');
return this.innerApiCalls.slowFibonacci(request, options, callback);
}

Expand Down
Loading

0 comments on commit 0c8479e

Please sign in to comment.