Skip to content

Commit

Permalink
fix: support go with abortOnError
Browse files Browse the repository at this point in the history
  • Loading branch information
ahippler committed Jun 24, 2024
1 parent b6d2c4b commit ce617ad
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
40 changes: 40 additions & 0 deletions lib/modules/datasource/go/releases-goproxy.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { codeBlock } from 'common-tags';
import { mockDeep } from 'jest-mock-extended';
import { Fixtures } from '../../../../test/fixtures';
import * as httpMock from '../../../../test/http-mock';
import { mocked } from '../../../../test/util';
import * as _hostRules from '../../../util/host-rules';
import { GithubReleasesDatasource } from '../github-releases';
import { GithubTagsDatasource } from '../github-tags';
import { GoProxyDatasource } from './releases-goproxy';

const hostRules = mocked(_hostRules);
jest.mock('../../../util/host-rules', () => mockDeep());

const datasource = new GoProxyDatasource();

describe('modules/datasource/go/releases-goproxy', () => {
Expand All @@ -18,6 +24,10 @@ describe('modules/datasource/go/releases-goproxy', () => {
'getReleases',
);

beforeEach(() => {
hostRules.find.mockReturnValue({});
});

it('encodeCase', () => {
expect(datasource.encodeCase('foo')).toBe('foo');
expect(datasource.encodeCase('Foo')).toBe('!foo');
Expand Down Expand Up @@ -454,6 +464,36 @@ describe('modules/datasource/go/releases-goproxy', () => {
});
});

it('handles major releases with abortOnError=true', async () => {
process.env.GOPROXY = baseUrl;
hostRules.find.mockReturnValue({
abortOnError: true,
});

httpMock
.scope(`${baseUrl}/github.com/google/btree`)
.get('/@v/list')
.reply(200, 'v1.0.0')
.get('/@v/v1.0.0.info')
.reply(200, { Version: 'v1.0.0', Time: '2018-08-13T15:31:12Z' })
.get('/@latest')
.reply(200, { Version: 'v1.0.0' })
.get('/v2/@v/list')
.reply(404);

const res = await datasource.getReleases({
packageName: 'github.com/google/btree',
});

expect(res).toEqual({
releases: [
{ releaseTimestamp: '2018-08-13T15:31:12Z', version: 'v1.0.0' },
],
sourceUrl: 'https://github.com/google/btree',
tags: { latest: 'v1.0.0' },
});
});

it('handles gopkg.in major releases', async () => {
process.env.GOPROXY = baseUrl;

Expand Down
11 changes: 8 additions & 3 deletions lib/modules/datasource/go/releases-goproxy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import is from '@sindresorhus/is';
import { DateTime } from 'luxon';
import { logger } from '../../../logger';
import { ExternalHostError } from '../../../types/errors/external-host-error';
import { cache } from '../../../util/cache/package/decorator';
import { filterMap } from '../../../util/filter-map';
import { HttpError } from '../../../util/http';
Expand Down Expand Up @@ -88,7 +89,9 @@ export class GoProxyDatasource extends Datasource {
break;
}
} catch (err) {
const statusCode = err?.response?.statusCode;
const potentialHttpError =
err instanceof ExternalHostError ? err.err : err;
const statusCode = potentialHttpError?.response?.statusCode;
const canFallback =
fallback === '|' ? true : statusCode === 404 || statusCode === 410;
const msg = canFallback
Expand Down Expand Up @@ -213,9 +216,11 @@ export class GoProxyDatasource extends Datasource {
});
result.releases.push(...releases);
} catch (err) {
const potentialHttpError =
err instanceof ExternalHostError ? err.err : err;
if (
err instanceof HttpError &&
err.response?.statusCode === 404 &&
potentialHttpError instanceof HttpError &&
potentialHttpError.response?.statusCode === 404 &&
major !== packageMajor
) {
break;
Expand Down

0 comments on commit ce617ad

Please sign in to comment.