Skip to content

Commit

Permalink
test(datasource): Avoid snapshots for testing EXTERNAL_HOST_ERROR (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesyo committed Jul 22, 2022
1 parent 2f93a5e commit 497b5de
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 44 deletions.
2 changes: 0 additions & 2 deletions lib/modules/datasource/crate/__snapshots__/index.spec.ts.snap
Expand Up @@ -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]`;
14 changes: 5 additions & 9 deletions lib/modules/datasource/crate/index.spec.ts
Expand Up @@ -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 '.';
Expand Down Expand Up @@ -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 () => {
Expand Down
2 changes: 0 additions & 2 deletions lib/modules/datasource/dart/__snapshots__/index.spec.ts.snap
Expand Up @@ -184,5 +184,3 @@ Object {
"sourceUrl": "http://example.com",
}
`;

exports[`modules/datasource/dart/index getReleases throws for 5xx 1`] = `[Error: external-host-error]`;
14 changes: 5 additions & 9 deletions 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');
Expand Down Expand Up @@ -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 () => {
Expand Down
Expand Up @@ -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]`;
14 changes: 5 additions & 9 deletions 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/';
Expand Down Expand Up @@ -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 () => {
Expand Down
2 changes: 0 additions & 2 deletions lib/modules/datasource/helm/__snapshots__/index.spec.ts.snap
Expand Up @@ -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]`;
14 changes: 5 additions & 9 deletions 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
Expand Down Expand Up @@ -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 () => {
Expand Down

0 comments on commit 497b5de

Please sign in to comment.