Skip to content

Commit

Permalink
run lint
Browse files Browse the repository at this point in the history
  • Loading branch information
sofisl committed Dec 11, 2024
1 parent 5e9bd38 commit 9224b47
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
20 changes: 10 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function validate(options: Options) {
break;
case 'qs':
throw new Error(
"'qs' is not a valid configuration option. Please use 'params' instead."
"'qs' is not a valid configuration option. Please use 'params' instead.",
);
default:
throw new Error(`'${key}' is not a valid configuration option.`);
Expand All @@ -112,14 +112,14 @@ async function metadataAccessor<T>(
type: string,
options?: string | Options,
noResponseRetries?: number,
fastFail?: boolean
fastFail?: boolean,
): Promise<T>;
async function metadataAccessor<T>(metadata: MetadataAccessor): Promise<T>;
async function metadataAccessor<T>(
type: MetadataAccessor | string,
options: string | Options = {},
noResponseRetries = 3,
fastFail = false
fastFail = false,
): Promise<T> {
let metadataKey = '';
let params: {} = {};
Expand Down Expand Up @@ -162,7 +162,7 @@ async function metadataAccessor<T>(
// NOTE: node.js converts all incoming headers to lower case.
if (res.headers[HEADER_NAME.toLowerCase()] !== HEADER_VALUE) {
throw new Error(
`Invalid response from metadata service: incorrect ${HEADER_NAME} header.`
`Invalid response from metadata service: incorrect ${HEADER_NAME} header.`,
);
}

Expand All @@ -178,7 +178,7 @@ async function metadataAccessor<T>(
}

async function fastFailMetadataRequest<T>(
options: GaxiosOptions
options: GaxiosOptions,
): Promise<GaxiosResponse> {
const secondaryOptions = {
...options,
Expand Down Expand Up @@ -314,7 +314,7 @@ export async function bulk<

r[key] = res;
})();
})
}),
);

return r as R;
Expand Down Expand Up @@ -342,8 +342,8 @@ export async function isAvailable() {
if (!(value in METADATA_SERVER_DETECTION)) {
throw new RangeError(
`Unknown \`METADATA_SERVER_DETECTION\` env variable. Got \`${value}\`, but it should be \`${Object.keys(
METADATA_SERVER_DETECTION
).join('`, `')}\`, or unset`
METADATA_SERVER_DETECTION,
).join('`, `')}\`, or unset`,
);
}

Expand Down Expand Up @@ -372,7 +372,7 @@ export async function isAvailable() {
// If the default HOST_ADDRESS has been overridden, we should not
// make an effort to try SECONDARY_HOST_ADDRESS (as we are likely in
// a non-GCP environment):
!(process.env.GCE_METADATA_IP || process.env.GCE_METADATA_HOST)
!(process.env.GCE_METADATA_IP || process.env.GCE_METADATA_HOST),
);
}
await cachedIsAvailableResponse;
Expand Down Expand Up @@ -409,7 +409,7 @@ export async function isAvailable() {
if (err.code) code = err.code;
process.emitWarning(
`received unexpected error = ${err.message} code = ${code}`,
'MetadataLookupWarning'
'MetadataLookupWarning',
);
}

Expand Down
8 changes: 4 additions & 4 deletions system-test/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ describe('gcp metadata', () => {
const result = await gcbuild.build({
sourcePath: path.join(
__dirname,
'../../system-test/fixtures/cloudbuild'
'../../system-test/fixtures/cloudbuild',
),
});
console.log(result.log);
assert.ok(/isAvailable: true/.test(result.log));
assert.ok(
result.log.includes('"default":{"aliases":["default"],"email"')
result.log.includes('"default":{"aliases":["default"],"email"'),
);
} catch (e) {
console.error((e as gcbuild.BuildError).log);
Expand Down Expand Up @@ -127,7 +127,7 @@ async function pruneFunctions(sessionOnly: boolean) {
console.error(`There was a problem deleting function ${fn.name}.`);
console.error(e);
});
})
}),
);
}

Expand Down Expand Up @@ -158,6 +158,6 @@ async function packModule() {
targets.map(target => {
const to = `system-test/fixtures/${target}/${pkg.name}.tgz`;
return copy(from, to);
})
}),
);
}
16 changes: 8 additions & 8 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ describe('unit test', () => {
.reply(200, {}, {[gcp.HEADER_NAME.toLowerCase()]: 'Hazelnut'});
await assert.rejects(
gcp.instance(),
/Invalid response from metadata service: incorrect Metadata-Flavor header./
/Invalid response from metadata service: incorrect Metadata-Flavor header./,
);
scope.done();
});
Expand Down Expand Up @@ -226,15 +226,15 @@ describe('unit test', () => {
await assert.rejects(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
gcp.instance({qs: {one: 'two'}} as any),
/'qs' is not a valid configuration option. Please use 'params' instead\./
/'qs' is not a valid configuration option. Please use 'params' instead\./,
);
});

it('should throw if invalid options are passed', async () => {
await assert.rejects(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
gcp.instance({fake: 'news'} as any),
/'fake' is not a valid/
/'fake' is not a valid/,
);
});

Expand All @@ -251,7 +251,7 @@ describe('unit test', () => {

async function secondaryHostRequest(
delay: number,
responseType = 'success'
responseType = 'success',
): Promise<void> {
let secondary: nock.Scope;
if (responseType === 'success') {
Expand Down Expand Up @@ -467,7 +467,7 @@ describe('unit test', () => {
});

it('should fail on isAvailable if request times out', async () => {
secondaryHostRequest(5000);
void secondaryHostRequest(5000);
const primary = nock(HOST)
.get(`${PATH}/${TYPE}`)
.delayConnection(3500)
Expand All @@ -482,7 +482,7 @@ describe('unit test', () => {

it('should fail on isAvailable if GCE_METADATA_HOST times out', async () => {
process.env.GCE_METADATA_HOST = '127.0.0.1:8080';
secondaryHostRequest(5000);
void secondaryHostRequest(5000);
const primary = nock(`http://${process.env.GCE_METADATA_HOST}`)
.get(`${PATH}/${TYPE}`)
.delayConnection(3500)
Expand Down Expand Up @@ -540,7 +540,7 @@ describe('unit test', () => {
process.on('warning', warning => {
assert.strictEqual(
warning.toString().includes('unexpected error'),
true
true,
);
return resolve();
});
Expand Down Expand Up @@ -596,7 +596,7 @@ describe('unit test', () => {
it('should only make one outbound request, if isAvailable() called in rapid succession', async () => {
const secondary = secondaryHostRequest(500);
const primary = nock(HOST).get(`${PATH}/${TYPE}`).reply(200, {}, HEADERS);
gcp.isAvailable();
void gcp.isAvailable();
// because we haven't created additional mocks, we expect this to fail
// if we were not caching the first isAvailable() call:
const isGCE = await gcp.isAvailable();
Expand Down
2 changes: 1 addition & 1 deletion test/utils/gcp-residency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class GCPResidencyUtil {

this.stubs.osNetworkInterfaces ??= this.sandbox.stub(
os,
'networkInterfaces'
'networkInterfaces',
);
this.stubs.osNetworkInterfaces.returns({
'test-interface': [{mac} as os.NetworkInterfaceInfo],
Expand Down

0 comments on commit 9224b47

Please sign in to comment.