From e86976ed7684aacee688ba1fb6c855db83c6205f Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Wed, 17 Jun 2020 10:34:13 +0200 Subject: [PATCH 1/2] fix: global cache return undefined instead of null --- lib/util/cache/global/file.spec.ts | 6 ++++-- lib/util/cache/global/file.ts | 2 +- lib/util/cache/global/redis.ts | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/util/cache/global/file.spec.ts b/lib/util/cache/global/file.spec.ts index 7a774e39019ad2..26be177a9c8649 100644 --- a/lib/util/cache/global/file.spec.ts +++ b/lib/util/cache/global/file.spec.ts @@ -7,7 +7,9 @@ describe('lib/util/cache/global/file', () => { }); it('gets null', async () => { - expect(await global.renovateCache.get('test', 'missing-key')).toBeNull(); + expect( + await global.renovateCache.get('test', 'missing-key') + ).toBeUndefined(); }); it('sets and gets', async () => { @@ -17,6 +19,6 @@ describe('lib/util/cache/global/file', () => { it('expires', async () => { await global.renovateCache.set('test', 'key', 1234, -5); - expect(await global.renovateCache.get('test', 'key')).toBeNull(); + expect(await global.renovateCache.get('test', 'key')).toBeUndefined(); }); }); diff --git a/lib/util/cache/global/file.ts b/lib/util/cache/global/file.ts index 589dd84e3a52c8..e13818c5af40be 100644 --- a/lib/util/cache/global/file.ts +++ b/lib/util/cache/global/file.ts @@ -29,7 +29,7 @@ async function get(namespace: string, key: string): Promise { } catch (err) { logger.trace({ namespace, key }, 'Cache miss'); } - return null; + return undefined; } async function set( diff --git a/lib/util/cache/global/redis.ts b/lib/util/cache/global/redis.ts index abb7497b8c45ae..bd3406837fe808 100644 --- a/lib/util/cache/global/redis.ts +++ b/lib/util/cache/global/redis.ts @@ -38,7 +38,7 @@ async function get(namespace: string, key: string): Promise { } catch (err) { logger.trace({ namespace, key }, 'Cache miss'); } - return null; + return undefined; } async function set( From e38536a87670677439f7acb72c13727ce821cd1b Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Wed, 17 Jun 2020 10:39:20 +0200 Subject: [PATCH 2/2] remove unused comment --- lib/util/cache/global/file.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/util/cache/global/file.ts b/lib/util/cache/global/file.ts index e13818c5af40be..0fcbda3010bd78 100644 --- a/lib/util/cache/global/file.ts +++ b/lib/util/cache/global/file.ts @@ -18,7 +18,6 @@ async function get(namespace: string, key: string): Promise { try { const res = await cacache.get(renovateCache, getKey(namespace, key)); const cachedValue = JSON.parse(res.data.toString()); - // istanbul ignore else: only happens when cache is corrupted if (cachedValue) { if (DateTime.local() < DateTime.fromISO(cachedValue.expiry)) { logger.trace({ namespace, key }, 'Returning cached value');