Skip to content

Commit

Permalink
run lint
Browse files Browse the repository at this point in the history
  • Loading branch information
sofisl committed Feb 15, 2025
1 parent d3aa828 commit b6f2d83
Show file tree
Hide file tree
Showing 11 changed files with 235 additions and 196 deletions.
39 changes: 19 additions & 20 deletions gax/test/unit/apiCallable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ describe('createApiCall', () => {
assert(Number(resp) - start <= 30100);
});
});
it('override just custom retry.retryCodes with retry codes', async () => {
it('override just custom retry.retryCodes with retry codes', () => {
const initialRetryCodes = [1];
const overrideRetryCodes = [1, 2, 3];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
sinon.stub(retries, 'retryable').callsFake((func, retry): any => {
assert.strictEqual(retry.retryCodes, overrideRetryCodes);
return func;
assert.strictEqual(retry.retryCodes, overrideRetryCodes);
return func;
});

function func() {
Expand All @@ -161,14 +161,14 @@ describe('createApiCall', () => {
},
});

await apiCall(
apiCall(
{},
{
retry: {
retryCodes: overrideRetryCodes,
},
},
);
).catch(console.error);
});
it('errors when you override custom retry.shouldRetryFn with a function on a non streaming call', async () => {
function neverRetry() {
Expand Down Expand Up @@ -211,7 +211,7 @@ describe('createApiCall', () => {
}
});

it('override just custom retry.backoffSettings', async () => {
it('override just custom retry.backoffSettings', () => {
const initialBackoffSettings = gax.createDefaultBackoffSettings();
const overriBackoffSettings = gax.createBackoffSettings(
100,
Expand All @@ -238,14 +238,14 @@ describe('createApiCall', () => {
},
});

await apiCall(
apiCall(
{},
{
retry: {
backoffSettings: overriBackoffSettings,
},
},
);
).catch(console.error);
});

it('errors when a resumption strategy is passed for a non streaming call', async () => {
Expand All @@ -265,7 +265,7 @@ describe('createApiCall', () => {
};

function func() {
Promise.resolve();
Promise.resolve().catch(console.error);
}
const apiCall = createApiCall(func, {
settings: {
Expand Down Expand Up @@ -443,7 +443,7 @@ describe('retryable', () => {
assert.strictEqual(toAttempt, 0);
assert(deadlineArg);
done();
});
}).catch(console.error);
});

it('retries the API call with promise', async () => {
Expand All @@ -464,13 +464,12 @@ describe('retryable', () => {
callback(null, 1729);
}
const apiCall = createApiCall(func, settings);
await apiCall({}, undefined)
.then(resp => {
assert.ok(Array.isArray(resp));
assert.strictEqual(resp[0], 1729);
assert.strictEqual(toAttempt, 0);
assert.ok(deadlineArg);
});
await apiCall({}, undefined).then(resp => {
assert.ok(Array.isArray(resp));
assert.strictEqual(resp[0], 1729);
assert.strictEqual(toAttempt, 0);
assert.ok(deadlineArg);
});
});

it('cancels in the middle of retries', done => {
Expand Down Expand Up @@ -515,7 +514,7 @@ describe('retryable', () => {
assert.strictEqual(err!.note, undefined);
assert.strictEqual(spy.callCount, 1);
done();
});
}).catch(console.error);
});

it('aborts retries', async () => {
Expand All @@ -536,7 +535,7 @@ describe('retryable', () => {
assert(err!.note);
assert.strictEqual(spy.callCount, toAttempt);
done();
});
}).catch(console.error);
});

it('errors on maxRetries and surfaces original error', async () => {
Expand Down Expand Up @@ -661,7 +660,7 @@ describe('retryable', () => {
assert(spy.callCount > callsLowerBound);
assert(spy.callCount < callsUpperBound);
done();
});
}).catch(console.error);
});

it.skip('reports A/B testing', () => {
Expand Down
13 changes: 6 additions & 7 deletions gax/test/unit/bundling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -881,13 +881,12 @@ describe('bundleable', () => {
const apiCall = createApiCall(spy, settings);
await apiCall({field1: [1, 2, 3], field2: 'id'}, undefined, (err, obj) => {
if (err) {
return err;
throw err;
} else {
callback([obj]);
}
});
await apiCall({field1: [1, 2, 3], field2: 'id'}, undefined)
.then(callback)
await apiCall({field1: [1, 2, 3], field2: 'id'}, undefined).then(callback);
});

it('does not fail if bundle field is not set', done => {
Expand Down Expand Up @@ -1001,27 +1000,27 @@ describe('bundleable', () => {
} else {
callback();
}
});
}).catch(console.error);
apiCall({data: ['data1'], logName: 'log2'}, undefined, err => {
if (err) {
done(err);
} else {
callback();
}
});
}).catch(console.error);
apiCall({data: ['data2'], logName: 'log1'}, undefined, err => {
if (err) {
done(err);
} else {
callback();
}
});
}).catch(console.error);
apiCall({data: ['data2'], logName: 'log2'}, undefined, err => {
if (err) {
done(err);
} else {
callback();
}
});
}).catch(console.error);
});
});
20 changes: 12 additions & 8 deletions gax/test/unit/grpc-fallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,22 @@ describe('createStub', () => {

it('validates universe domain if set', async () => {
const opts = {...stubOptions, universeDomain: 'example.com'};
assert.rejects(
gaxGrpc.createStub(echoService, opts),
/configured universe domain/,
);
assert
.rejects(
gaxGrpc.createStub(echoService, opts),
/configured universe domain/,
)
.catch(console.error);
});

it('validates universe domain if unset', async () => {
authClient.universeDomain = 'example.com';
assert.rejects(
gaxGrpc.createStub(echoService, stubOptions),
/configured universe domain/,
);
assert
.rejects(
gaxGrpc.createStub(echoService, stubOptions),
/configured universe domain/,
)
.catch(console.error);
// reset to default value
authClient.universeDomain = 'googleapis.com';
});
Expand Down
34 changes: 20 additions & 14 deletions gax/test/unit/grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,22 +184,26 @@ describe('grpc', () => {
port: 443,
universeDomain: 'example.com',
};
assert.rejects(
// @ts-ignore
grpcClient.createStub(DummyStub, opts),
/configured universe domain/,
);
assert
.rejects(
// @ts-ignore
grpcClient.createStub(DummyStub, opts),
/configured universe domain/,
)
.catch(console.error);
});

it('validates universe domain if unset', async () => {
const opts = {servicePath: 'foo.example.com', port: 443};
stubAuth.getUniverseDomain.reset();
stubAuth.getUniverseDomain.resolves('example.com');
assert.rejects(
// @ts-ignore
grpcClient.createStub(DummyStub, opts),
/configured universe domain/,
);
assert
.rejects(
// @ts-ignore
grpcClient.createStub(DummyStub, opts),
/configured universe domain/,
)
.catch(console.error);
});

it('supports optional parameters', () => {
Expand Down Expand Up @@ -711,10 +715,12 @@ dvorak
// Create a client and test the certificate detection flow:
process.env.GOOGLE_API_USE_CLIENT_CERTIFICATE = 'true';
const clientMock = new GrpcClient();
assert.rejects(
clientMock.createStub(DummyStub, {universeDomain: 'example.com'}),
/configured universe domain/,
);
assert
.rejects(
clientMock.createStub(DummyStub, {universeDomain: 'example.com'}),
/configured universe domain/,
)
.catch(console.error);
await fsp.rm(tmpFolder, {recursive: true, force: true}); // Cleanup.
});
});
Expand Down
Loading

0 comments on commit b6f2d83

Please sign in to comment.