Skip to content

Commit fc54595

Browse files
fix: better support for fallback mode (#402)
- [ ] Regenerate this pull request now. PiperOrigin-RevId: 468790263 Source-Link: googleapis/googleapis@873ab45 Source-Link: googleapis/googleapis-gen@cb6f37a Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiY2I2ZjM3YWVmZjJhMzQ3MmU0MGE3YmJhY2U4YzY3ZDc1ZTI0YmVlNSJ9
1 parent 8e8a2e8 commit fc54595

File tree

4 files changed

+117
-105
lines changed

4 files changed

+117
-105
lines changed

packages/google-cloud-phishingprotection/samples/generated/v1beta1/phishing_protection_service_v1_beta1.report_phishing.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
function main(parent, uri) {
2424
// [START phishingprotection_v1beta1_generated_PhishingProtectionServiceV1Beta1_ReportPhishing_async]
2525
/**
26+
* This snippet has been automatically generated and should be regarded as a code template only.
27+
* It will require modifications to work.
28+
* It may require correct/in-range values for request initialization.
2629
* TODO(developer): Uncomment these variables before running the sample.
2730
*/
2831
/**

packages/google-cloud-phishingprotection/samples/generated/v1beta1/snippet_metadata.google.cloud.phishingprotection.v1beta1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"segments": [
2323
{
2424
"start": 25,
25-
"end": 56,
25+
"end": 59,
2626
"type": "FULL"
2727
}
2828
],

packages/google-cloud-phishingprotection/src/v1beta1/phishing_protection_service_v1_beta1_client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ export class PhishingProtectionServiceV1Beta1Client {
230230
const apiCall = this._gaxModule.createApiCall(
231231
callPromise,
232232
this._defaults[methodName],
233-
descriptor
233+
descriptor,
234+
this._opts.fallback
234235
);
235236

236237
this.innerApiCalls[methodName] = apiCall;

packages/google-cloud-phishingprotection/test/gapic_phishing_protection_service_v1_beta1_v1beta1.ts

Lines changed: 111 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -50,124 +50,132 @@ function stubSimpleCallWithCallback<ResponseType>(
5050
}
5151

5252
describe('v1beta1.PhishingProtectionServiceV1Beta1Client', () => {
53-
it('has servicePath', () => {
54-
const servicePath =
55-
phishingprotectionservicev1beta1Module.v1beta1
56-
.PhishingProtectionServiceV1Beta1Client.servicePath;
57-
assert(servicePath);
58-
});
53+
describe('Common methods', () => {
54+
it('has servicePath', () => {
55+
const servicePath =
56+
phishingprotectionservicev1beta1Module.v1beta1
57+
.PhishingProtectionServiceV1Beta1Client.servicePath;
58+
assert(servicePath);
59+
});
5960

60-
it('has apiEndpoint', () => {
61-
const apiEndpoint =
62-
phishingprotectionservicev1beta1Module.v1beta1
63-
.PhishingProtectionServiceV1Beta1Client.apiEndpoint;
64-
assert(apiEndpoint);
65-
});
61+
it('has apiEndpoint', () => {
62+
const apiEndpoint =
63+
phishingprotectionservicev1beta1Module.v1beta1
64+
.PhishingProtectionServiceV1Beta1Client.apiEndpoint;
65+
assert(apiEndpoint);
66+
});
6667

67-
it('has port', () => {
68-
const port =
69-
phishingprotectionservicev1beta1Module.v1beta1
70-
.PhishingProtectionServiceV1Beta1Client.port;
71-
assert(port);
72-
assert(typeof port === 'number');
73-
});
68+
it('has port', () => {
69+
const port =
70+
phishingprotectionservicev1beta1Module.v1beta1
71+
.PhishingProtectionServiceV1Beta1Client.port;
72+
assert(port);
73+
assert(typeof port === 'number');
74+
});
7475

75-
it('should create a client with no option', () => {
76-
const client =
77-
new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client();
78-
assert(client);
79-
});
76+
it('should create a client with no option', () => {
77+
const client =
78+
new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client();
79+
assert(client);
80+
});
8081

81-
it('should create a client with gRPC fallback', () => {
82-
const client =
83-
new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client(
84-
{
85-
fallback: true,
86-
}
87-
);
88-
assert(client);
89-
});
82+
it('should create a client with gRPC fallback', () => {
83+
const client =
84+
new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client(
85+
{
86+
fallback: true,
87+
}
88+
);
89+
assert(client);
90+
});
9091

91-
it('has initialize method and supports deferred initialization', async () => {
92-
const client =
93-
new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client(
94-
{
95-
credentials: {client_email: 'bogus', private_key: 'bogus'},
96-
projectId: 'bogus',
97-
}
92+
it('has initialize method and supports deferred initialization', async () => {
93+
const client =
94+
new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client(
95+
{
96+
credentials: {client_email: 'bogus', private_key: 'bogus'},
97+
projectId: 'bogus',
98+
}
99+
);
100+
assert.strictEqual(
101+
client.phishingProtectionServiceV1Beta1Stub,
102+
undefined
98103
);
99-
assert.strictEqual(client.phishingProtectionServiceV1Beta1Stub, undefined);
100-
await client.initialize();
101-
assert(client.phishingProtectionServiceV1Beta1Stub);
102-
});
104+
await client.initialize();
105+
assert(client.phishingProtectionServiceV1Beta1Stub);
106+
});
103107

104-
it('has close method for the initialized client', done => {
105-
const client =
106-
new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client(
107-
{
108-
credentials: {client_email: 'bogus', private_key: 'bogus'},
109-
projectId: 'bogus',
110-
}
111-
);
112-
client.initialize();
113-
assert(client.phishingProtectionServiceV1Beta1Stub);
114-
client.close().then(() => {
115-
done();
108+
it('has close method for the initialized client', done => {
109+
const client =
110+
new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client(
111+
{
112+
credentials: {client_email: 'bogus', private_key: 'bogus'},
113+
projectId: 'bogus',
114+
}
115+
);
116+
client.initialize();
117+
assert(client.phishingProtectionServiceV1Beta1Stub);
118+
client.close().then(() => {
119+
done();
120+
});
116121
});
117-
});
118122

119-
it('has close method for the non-initialized client', done => {
120-
const client =
121-
new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client(
122-
{
123-
credentials: {client_email: 'bogus', private_key: 'bogus'},
124-
projectId: 'bogus',
125-
}
123+
it('has close method for the non-initialized client', done => {
124+
const client =
125+
new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client(
126+
{
127+
credentials: {client_email: 'bogus', private_key: 'bogus'},
128+
projectId: 'bogus',
129+
}
130+
);
131+
assert.strictEqual(
132+
client.phishingProtectionServiceV1Beta1Stub,
133+
undefined
126134
);
127-
assert.strictEqual(client.phishingProtectionServiceV1Beta1Stub, undefined);
128-
client.close().then(() => {
129-
done();
135+
client.close().then(() => {
136+
done();
137+
});
130138
});
131-
});
132139

133-
it('has getProjectId method', async () => {
134-
const fakeProjectId = 'fake-project-id';
135-
const client =
136-
new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client(
137-
{
138-
credentials: {client_email: 'bogus', private_key: 'bogus'},
139-
projectId: 'bogus',
140-
}
141-
);
142-
client.auth.getProjectId = sinon.stub().resolves(fakeProjectId);
143-
const result = await client.getProjectId();
144-
assert.strictEqual(result, fakeProjectId);
145-
assert((client.auth.getProjectId as SinonStub).calledWithExactly());
146-
});
140+
it('has getProjectId method', async () => {
141+
const fakeProjectId = 'fake-project-id';
142+
const client =
143+
new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client(
144+
{
145+
credentials: {client_email: 'bogus', private_key: 'bogus'},
146+
projectId: 'bogus',
147+
}
148+
);
149+
client.auth.getProjectId = sinon.stub().resolves(fakeProjectId);
150+
const result = await client.getProjectId();
151+
assert.strictEqual(result, fakeProjectId);
152+
assert((client.auth.getProjectId as SinonStub).calledWithExactly());
153+
});
147154

148-
it('has getProjectId method with callback', async () => {
149-
const fakeProjectId = 'fake-project-id';
150-
const client =
151-
new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client(
152-
{
153-
credentials: {client_email: 'bogus', private_key: 'bogus'},
154-
projectId: 'bogus',
155-
}
156-
);
157-
client.auth.getProjectId = sinon
158-
.stub()
159-
.callsArgWith(0, null, fakeProjectId);
160-
const promise = new Promise((resolve, reject) => {
161-
client.getProjectId((err?: Error | null, projectId?: string | null) => {
162-
if (err) {
163-
reject(err);
164-
} else {
165-
resolve(projectId);
166-
}
155+
it('has getProjectId method with callback', async () => {
156+
const fakeProjectId = 'fake-project-id';
157+
const client =
158+
new phishingprotectionservicev1beta1Module.v1beta1.PhishingProtectionServiceV1Beta1Client(
159+
{
160+
credentials: {client_email: 'bogus', private_key: 'bogus'},
161+
projectId: 'bogus',
162+
}
163+
);
164+
client.auth.getProjectId = sinon
165+
.stub()
166+
.callsArgWith(0, null, fakeProjectId);
167+
const promise = new Promise((resolve, reject) => {
168+
client.getProjectId((err?: Error | null, projectId?: string | null) => {
169+
if (err) {
170+
reject(err);
171+
} else {
172+
resolve(projectId);
173+
}
174+
});
167175
});
176+
const result = await promise;
177+
assert.strictEqual(result, fakeProjectId);
168178
});
169-
const result = await promise;
170-
assert.strictEqual(result, fakeProjectId);
171179
});
172180

173181
describe('reportPhishing', () => {

0 commit comments

Comments
 (0)