diff --git a/src/index.ts b/src/index.ts index 82e13a0..cf81421 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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.`); @@ -112,14 +112,14 @@ async function metadataAccessor( type: string, options?: string | Options, noResponseRetries?: number, - fastFail?: boolean + fastFail?: boolean, ): Promise; async function metadataAccessor(metadata: MetadataAccessor): Promise; async function metadataAccessor( type: MetadataAccessor | string, options: string | Options = {}, noResponseRetries = 3, - fastFail = false + fastFail = false, ): Promise { let metadataKey = ''; let params: {} = {}; @@ -162,7 +162,7 @@ async function metadataAccessor( // 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.`, ); } @@ -178,7 +178,7 @@ async function metadataAccessor( } async function fastFailMetadataRequest( - options: GaxiosOptions + options: GaxiosOptions, ): Promise { const secondaryOptions = { ...options, @@ -314,7 +314,7 @@ export async function bulk< r[key] = res; })(); - }) + }), ); return r as R; @@ -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`, ); } @@ -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; @@ -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', ); } diff --git a/system-test/system.ts b/system-test/system.ts index 94c9abb..8144ea0 100644 --- a/system-test/system.ts +++ b/system-test/system.ts @@ -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); @@ -127,7 +127,7 @@ async function pruneFunctions(sessionOnly: boolean) { console.error(`There was a problem deleting function ${fn.name}.`); console.error(e); }); - }) + }), ); } @@ -158,6 +158,6 @@ async function packModule() { targets.map(target => { const to = `system-test/fixtures/${target}/${pkg.name}.tgz`; return copy(from, to); - }) + }), ); } diff --git a/test/index.test.ts b/test/index.test.ts index d23eeb5..abf43b6 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -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(); }); @@ -226,7 +226,7 @@ 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\./, ); }); @@ -234,7 +234,7 @@ describe('unit test', () => { 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/, ); }); @@ -251,7 +251,7 @@ describe('unit test', () => { async function secondaryHostRequest( delay: number, - responseType = 'success' + responseType = 'success', ): Promise { let secondary: nock.Scope; if (responseType === 'success') { @@ -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) @@ -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) @@ -540,7 +540,7 @@ describe('unit test', () => { process.on('warning', warning => { assert.strictEqual( warning.toString().includes('unexpected error'), - true + true, ); return resolve(); }); @@ -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(); diff --git a/test/utils/gcp-residency.ts b/test/utils/gcp-residency.ts index 144fa78..51640f3 100644 --- a/test/utils/gcp-residency.ts +++ b/test/utils/gcp-residency.ts @@ -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],