From 497b5de6c2cd862ec25d4322342d1b6e8896ca2f Mon Sep 17 00:00:00 2001 From: IKEDA Sho Date: Fri, 22 Jul 2022 13:49:05 +0900 Subject: [PATCH] test(datasource): Avoid snapshots for testing EXTERNAL_HOST_ERROR (#16692) --- .../crate/__snapshots__/index.spec.ts.snap | 2 -- lib/modules/datasource/crate/index.spec.ts | 14 +++++--------- .../dart/__snapshots__/index.spec.ts.snap | 2 -- lib/modules/datasource/dart/index.spec.ts | 14 +++++--------- .../galaxy/__snapshots__/index.spec.ts.snap | 2 -- lib/modules/datasource/galaxy/index.spec.ts | 14 +++++--------- .../helm/__snapshots__/index.spec.ts.snap | 2 -- lib/modules/datasource/helm/index.spec.ts | 14 +++++--------- 8 files changed, 20 insertions(+), 44 deletions(-) diff --git a/lib/modules/datasource/crate/__snapshots__/index.spec.ts.snap b/lib/modules/datasource/crate/__snapshots__/index.spec.ts.snap index 65c7cd35e34464..8a570f97ff6fc2 100644 --- a/lib/modules/datasource/crate/__snapshots__/index.spec.ts.snap +++ b/lib/modules/datasource/crate/__snapshots__/index.spec.ts.snap @@ -305,5 +305,3 @@ Object { "sourceUrl": "https://github.com/rust-lang/libc", } `; - -exports[`modules/datasource/crate/index getReleases throws for 5xx 1`] = `[Error: external-host-error]`; diff --git a/lib/modules/datasource/crate/index.spec.ts b/lib/modules/datasource/crate/index.spec.ts index 9a376abdbbea2b..d115b12c796392 100644 --- a/lib/modules/datasource/crate/index.spec.ts +++ b/lib/modules/datasource/crate/index.spec.ts @@ -8,6 +8,7 @@ import { Fixtures } from '../../../../test/fixtures'; import * as httpMock from '../../../../test/http-mock'; import { GlobalConfig } from '../../../config/global'; import type { RepoGlobalConfig } from '../../../config/types'; +import { EXTERNAL_HOST_ERROR } from '../../../constants/error-messages'; import * as memCache from '../../../util/cache/memory'; import { RegistryFlavor, RegistryInfo } from './types'; import { CrateDatasource } from '.'; @@ -193,18 +194,13 @@ describe('modules/datasource/crate/index', () => { it('throws for 5xx', async () => { httpMock.scope(baseUrl).get('/so/me/some_crate').reply(502); - let e; - try { - await getPkgReleases({ + await expect( + getPkgReleases({ datasource, depName: 'some_crate', registryUrls: ['https://crates.io'], - }); - } catch (err) { - e = err; - } - expect(e).toBeDefined(); - expect(e).toMatchSnapshot(); + }) + ).rejects.toThrow(EXTERNAL_HOST_ERROR); }); it('returns null for unknown error', async () => { diff --git a/lib/modules/datasource/dart/__snapshots__/index.spec.ts.snap b/lib/modules/datasource/dart/__snapshots__/index.spec.ts.snap index 1a7dea7c0d9415..a30b3805972ba5 100644 --- a/lib/modules/datasource/dart/__snapshots__/index.spec.ts.snap +++ b/lib/modules/datasource/dart/__snapshots__/index.spec.ts.snap @@ -184,5 +184,3 @@ Object { "sourceUrl": "http://example.com", } `; - -exports[`modules/datasource/dart/index getReleases throws for 5xx 1`] = `[Error: external-host-error]`; diff --git a/lib/modules/datasource/dart/index.spec.ts b/lib/modules/datasource/dart/index.spec.ts index 7fc817f9c82294..b3472322c6b6a1 100644 --- a/lib/modules/datasource/dart/index.spec.ts +++ b/lib/modules/datasource/dart/index.spec.ts @@ -1,6 +1,7 @@ import { getPkgReleases } from '..'; import { Fixtures } from '../../../../test/fixtures'; import * as httpMock from '../../../../test/http-mock'; +import { EXTERNAL_HOST_ERROR } from '../../../constants/error-messages'; import { DartDatasource } from '.'; const body = Fixtures.getJson('shared_preferences.json'); @@ -63,17 +64,12 @@ describe('modules/datasource/dart/index', () => { it('throws for 5xx', async () => { httpMock.scope(baseUrl).get('/shared_preferences').reply(502); - let e; - try { - await getPkgReleases({ + await expect( + getPkgReleases({ datasource: DartDatasource.id, depName: 'shared_preferences', - }); - } catch (err) { - e = err; - } - expect(e).toBeDefined(); - expect(e).toMatchSnapshot(); + }) + ).rejects.toThrow(EXTERNAL_HOST_ERROR); }); it('returns null for unknown error', async () => { diff --git a/lib/modules/datasource/galaxy/__snapshots__/index.spec.ts.snap b/lib/modules/datasource/galaxy/__snapshots__/index.spec.ts.snap index d9f7deddafb343..e80e16bed5e29f 100644 --- a/lib/modules/datasource/galaxy/__snapshots__/index.spec.ts.snap +++ b/lib/modules/datasource/galaxy/__snapshots__/index.spec.ts.snap @@ -21,5 +21,3 @@ Object { "sourceUrl": "https://github.com/yatesr/ansible-timezone", } `; - -exports[`modules/datasource/galaxy/index getReleases throws for 5xx 1`] = `[Error: external-host-error]`; diff --git a/lib/modules/datasource/galaxy/index.spec.ts b/lib/modules/datasource/galaxy/index.spec.ts index 1216c5716b7419..80ca4b8ca298a4 100644 --- a/lib/modules/datasource/galaxy/index.spec.ts +++ b/lib/modules/datasource/galaxy/index.spec.ts @@ -1,6 +1,7 @@ import { getPkgReleases } from '..'; import { Fixtures } from '../../../../test/fixtures'; import * as httpMock from '../../../../test/http-mock'; +import { EXTERNAL_HOST_ERROR } from '../../../constants/error-messages'; import { GalaxyDatasource } from '.'; const baseUrl = 'https://galaxy.ansible.com/'; @@ -103,17 +104,12 @@ describe('modules/datasource/galaxy/index', () => { .scope(baseUrl) .get('/api/v1/roles/?owner__username=some_crate&name=undefined') .reply(502); - let e; - try { - await getPkgReleases({ + await expect( + getPkgReleases({ datasource: GalaxyDatasource.id, depName: 'some_crate', - }); - } catch (err) { - e = err; - } - expect(e).toBeDefined(); - expect(e).toMatchSnapshot(); + }) + ).rejects.toThrow(EXTERNAL_HOST_ERROR); }); it('throws for 404', async () => { diff --git a/lib/modules/datasource/helm/__snapshots__/index.spec.ts.snap b/lib/modules/datasource/helm/__snapshots__/index.spec.ts.snap index b09bf24ad81d52..f3753a6b5131a8 100644 --- a/lib/modules/datasource/helm/__snapshots__/index.spec.ts.snap +++ b/lib/modules/datasource/helm/__snapshots__/index.spec.ts.snap @@ -116,5 +116,3 @@ Object { "sourceUrl": "https://github.com/datawire/ambassador", } `; - -exports[`modules/datasource/helm/index getReleases throws for 5xx 1`] = `[Error: external-host-error]`; diff --git a/lib/modules/datasource/helm/index.spec.ts b/lib/modules/datasource/helm/index.spec.ts index 54ea10e1198a18..3b75c57e6b82aa 100644 --- a/lib/modules/datasource/helm/index.spec.ts +++ b/lib/modules/datasource/helm/index.spec.ts @@ -1,6 +1,7 @@ import { getPkgReleases } from '..'; import { Fixtures } from '../../../../test/fixtures'; import * as httpMock from '../../../../test/http-mock'; +import { EXTERNAL_HOST_ERROR } from '../../../constants/error-messages'; import { HelmDatasource } from '.'; // Truncated index.yaml file @@ -84,18 +85,13 @@ describe('modules/datasource/helm/index', () => { .scope('https://example-repository.com') .get('/index.yaml') .reply(502); - let e; - try { - await getPkgReleases({ + await expect( + getPkgReleases({ datasource: HelmDatasource.id, depName: 'some_chart', registryUrls: ['https://example-repository.com'], - }); - } catch (err) { - e = err; - } - expect(e).toBeDefined(); - expect(e).toMatchSnapshot(); + }) + ).rejects.toThrow(EXTERNAL_HOST_ERROR); }); it('returns null for unknown error', async () => {