diff --git a/lib/datasource/go/__fixtures__/go-get-github-ee.html b/lib/datasource/go/__fixtures__/go-get-github-ee.html new file mode 100644 index 0000000000000000000000000000000000000000..aca6bf30562ad2c51f9b2815491170cf5803e8f0 --- /dev/null +++ b/lib/datasource/go/__fixtures__/go-get-github-ee.html @@ -0,0 +1,13 @@ +<!DOCTYPE html> +<html lang="en"> +<head> +<meta charset="utf-8"> + +<title>Go remote import path metadata</title> +<meta name="go-import" content="git.enterprise.com/example/module git https://git.enterprise.com/example/module.git"> +</head> + +<body> +<!-- Metadata for Go remote import path --> +</body> +</html> diff --git a/lib/datasource/go/__fixtures__/go-get-github.html b/lib/datasource/go/__fixtures__/go-get-github.html new file mode 100644 index 0000000000000000000000000000000000000000..963087d8d8e4f286a16c5af75c766593c75c3d32 --- /dev/null +++ b/lib/datasource/go/__fixtures__/go-get-github.html @@ -0,0 +1,12 @@ +<!DOCTYPE html> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> +<meta name="go-import" content="golang.org/x/text git https://go.googlesource.com/text"> +<meta name="go-source" content="golang.org/x/text https://github.com/golang/text/ https://github.com/golang/text/tree/master{/dir} https://github.com/golang/text/blob/master{/dir}/{file}#L{line}"> +<meta http-equiv="refresh" content="0; url=https://godoc.org/golang.org/x/text"> +</head> +<body> +Nothing to see here; <a href="https://godoc.org/golang.org/x/text">move along</a>. +</body> +</html> diff --git a/lib/datasource/go/__fixtures__/go-get-gitlab-ee.html b/lib/datasource/go/__fixtures__/go-get-gitlab-ee.html new file mode 100644 index 0000000000000000000000000000000000000000..067d7d16758d8f7ccf6e7259143b1ef61b6d1dfe --- /dev/null +++ b/lib/datasource/go/__fixtures__/go-get-gitlab-ee.html @@ -0,0 +1,10 @@ +<html> +<head> + <meta name="go-import" content="my.custom.domain/golang/myrepo git https://my.custom.domain/golang/myrepo.git" /> + <meta name="go-source" + content="my.custom.domain/golang/myrepo https://my.custom.domain/golang/myrepo https://my.custom.domain/golang/myrepo/-/tree/master{/dir} https://my.custom.domain/golang/myrepo/-/blob/master{/dir}/{file}#L{line}" /> +</head> + +<body>go get https://my.custom.domain/golang/myrepo</body> + +</html> diff --git a/lib/datasource/go/__fixtures__/go-get-gitlab.html b/lib/datasource/go/__fixtures__/go-get-gitlab.html new file mode 100644 index 0000000000000000000000000000000000000000..ab6fb5c8cd6143781a2239b94879b26ce8acb897 --- /dev/null +++ b/lib/datasource/go/__fixtures__/go-get-gitlab.html @@ -0,0 +1,11 @@ +<!DOCTYPE html> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> +<meta name="go-import" content="gitlab.com/group/subgroup git https://gitlab.com/group/subgroup/repo"> +<meta name="go-source" content="gitlab.com/group/subgroup https://gitlab.com/group/subgroup https://gitlab.com/group/subgroup/-/tree/master{/dir} https://gitlab.com/group/subgroup/-/blob/master{/dir}/{file}#L{line}"> +</head> +<body> +go get https://gitlab.com/group/subgroup +</body> +</html> diff --git a/lib/datasource/go/__snapshots__/releases-direct.spec.ts.snap b/lib/datasource/go/__snapshots__/releases-direct.spec.ts.snap index ccd663b4ea7ee5e790a442eb7b4a803e4468c393..838734d3c6444be9f3ce91e528b53048a98644d2 100644 --- a/lib/datasource/go/__snapshots__/releases-direct.spec.ts.snap +++ b/lib/datasource/go/__snapshots__/releases-direct.spec.ts.snap @@ -1,55 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`datasource/go/releases-direct getReleases handles fyne.io 1`] = ` -Object { - "releases": Array [ - Object { - "gitRef": "v1.0.0", - "version": "v1.0.0", - }, - Object { - "gitRef": "v2.0.0", - "version": "v2.0.0", - }, - ], - "sourceUrl": "https://github.com/fyne-io/fyne", -} -`; - -exports[`datasource/go/releases-direct getReleases handles fyne.io 2`] = ` -Array [ - Object { - "headers": Object { - "accept-encoding": "gzip, deflate, br", - "host": "fyne.io", - "user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)", - }, - "method": "GET", - "url": "https://fyne.io/fyne?go-get=1", - }, - Object { - "headers": Object { - "accept": "application/vnd.github.v3+json", - "accept-encoding": "gzip, deflate, br", - "host": "api.github.com", - "user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)", - }, - "method": "GET", - "url": "https://api.github.com/repos/fyne-io/fyne/tags?per_page=100", - }, - Object { - "headers": Object { - "accept": "application/vnd.github.v3+json", - "accept-encoding": "gzip, deflate, br", - "host": "api.github.com", - "user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)", - }, - "method": "GET", - "url": "https://api.github.com/repos/fyne-io/fyne/releases?per_page=100", - }, -] -`; - exports[`datasource/go/releases-direct getReleases processes real data 1`] = ` Object { "releases": Array [ @@ -68,15 +18,6 @@ Object { exports[`datasource/go/releases-direct getReleases processes real data 2`] = ` Array [ - Object { - "headers": Object { - "accept-encoding": "gzip, deflate, br", - "host": "golang.org", - "user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)", - }, - "method": "GET", - "url": "https://golang.org/x/text?go-get=1", - }, Object { "headers": Object { "accept": "application/vnd.github.v3+json", @@ -150,62 +91,6 @@ Array [ ] `; -exports[`datasource/go/releases-direct getReleases returns null for empty result 1`] = ` -Array [ - Object { - "headers": Object { - "accept-encoding": "gzip, deflate, br", - "host": "golang.org", - "user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)", - }, - "method": "GET", - "url": "https://golang.org/foo/something?go-get=1", - }, -] -`; - -exports[`datasource/go/releases-direct getReleases returns null for go-import prefix mismatch 1`] = ` -Array [ - Object { - "headers": Object { - "accept-encoding": "gzip, deflate, br", - "host": "git.enterprise.com", - "user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)", - }, - "method": "GET", - "url": "https://git.enterprise.com/example/module?go-get=1", - }, -] -`; - -exports[`datasource/go/releases-direct getReleases skips unsupported platform 1`] = ` -Array [ - Object { - "headers": Object { - "accept-encoding": "gzip, deflate, br", - "host": "golang.org", - "user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)", - }, - "method": "GET", - "url": "https://golang.org/x/text?go-get=1", - }, -] -`; - -exports[`datasource/go/releases-direct getReleases skips wrong package 1`] = ` -Array [ - Object { - "headers": Object { - "accept-encoding": "gzip, deflate, br", - "host": "golang.org", - "user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)", - }, - "method": "GET", - "url": "https://golang.org/x/sys?go-get=1", - }, -] -`; - exports[`datasource/go/releases-direct getReleases support bitbucket tags 1`] = ` Object { "registryUrl": "https://bitbucket.org", @@ -258,15 +143,6 @@ Object { exports[`datasource/go/releases-direct getReleases support ghe 2`] = ` Array [ - Object { - "headers": Object { - "accept-encoding": "gzip, deflate, br", - "host": "git.enterprise.com", - "user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)", - }, - "method": "GET", - "url": "https://git.enterprise.com/example/module?go-get=1", - }, Object { "headers": Object { "accept": "application/vnd.github.v3+json", @@ -310,15 +186,6 @@ Object { exports[`datasource/go/releases-direct getReleases support gitlab 2`] = ` Array [ - Object { - "headers": Object { - "accept-encoding": "gzip, deflate, br", - "host": "golang.org", - "user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)", - }, - "method": "GET", - "url": "https://golang.org/x/text?go-get=1", - }, Object { "headers": Object { "accept": "application/json", @@ -352,15 +219,6 @@ Object { exports[`datasource/go/releases-direct getReleases support gitlab subgroups 2`] = ` Array [ - Object { - "headers": Object { - "accept-encoding": "gzip, deflate, br", - "host": "gitlab.com", - "user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)", - }, - "method": "GET", - "url": "https://gitlab.com/group/subgroup/repo?go-get=1", - }, Object { "headers": Object { "accept": "application/json", @@ -394,16 +252,6 @@ Object { exports[`datasource/go/releases-direct getReleases support self hosted gitlab private repositories 2`] = ` Array [ - Object { - "headers": Object { - "accept-encoding": "gzip, deflate, br", - "authorization": "Bearer some-token", - "host": "my.custom.domain", - "user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)", - }, - "method": "GET", - "url": "https://my.custom.domain/golang/myrepo?go-get=1", - }, Object { "headers": Object { "accept": "application/json", @@ -418,50 +266,6 @@ Array [ ] `; -exports[`datasource/go/releases-direct getReleases throws for 404 1`] = ` -Array [ - Object { - "headers": Object { - "accept-encoding": "gzip, deflate, br", - "host": "golang.org", - "user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)", - }, - "method": "GET", - "url": "https://golang.org/foo/something?go-get=1", - }, -] -`; - -exports[`datasource/go/releases-direct getReleases throws for unknown error 1`] = ` -Array [ - Object { - "headers": Object { - "accept-encoding": "gzip, deflate, br", - "host": "golang.org", - "user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)", - }, - "method": "GET", - "url": "https://golang.org/foo/something?go-get=1", - }, -] -`; - -exports[`datasource/go/releases-direct getReleases unknown datasource returns null 1`] = `null`; - -exports[`datasource/go/releases-direct getReleases unknown datasource returns null 2`] = ` -Array [ - Object { - "headers": Object { - "accept-encoding": "gzip, deflate, br", - "host": "some.unknown.website", - "user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)", - }, - "method": "GET", - "url": "https://some.unknown.website/example/module?go-get=1", - }, -] -`; - exports[`datasource/go/releases-direct getReleases works for known servers 1`] = ` Array [ Object { diff --git a/lib/datasource/go/get-datasource.spec.ts b/lib/datasource/go/get-datasource.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..b90e65180ff52c534080df21468781b6a17a0518 --- /dev/null +++ b/lib/datasource/go/get-datasource.spec.ts @@ -0,0 +1,177 @@ +import * as httpMock from '../../../test/http-mock'; +import { loadFixture, mocked } from '../../../test/util'; +import * as _hostRules from '../../util/host-rules'; +import { id as githubDatasource } from '../github-tags'; +import { id as gitlabDatasource } from '../gitlab-tags'; +import { getDatasource } from './get-datasource'; + +jest.mock('../../util/host-rules'); + +const hostRules = mocked(_hostRules); + +describe('datasource/go/get-datasource', () => { + describe('simple cases', () => { + test.each` + module | datasource | lookupName + ${'gopkg.in/foo'} | ${'github-tags'} | ${'go-foo/foo'} + ${'gopkg.in/foo/bar'} | ${'github-tags'} | ${'foo/bar'} + ${'github.com/foo/bar'} | ${'github-tags'} | ${'foo/bar'} + ${'bitbucket.org/foo/bar'} | ${'bitbucket-tags'} | ${'foo/bar'} + `( + '$module -> $datasource: $lookupName', + async ({ module, datasource, lookupName }) => { + const res = await getDatasource(module); + expect(res).toMatchObject({ datasource, lookupName }); + } + ); + }); + + describe('go-get requests', () => { + beforeEach(() => { + jest.resetAllMocks(); + hostRules.find.mockReturnValue({}); + hostRules.hosts.mockReturnValue([]); + }); + + afterEach(() => { + jest.resetAllMocks(); + }); + + describe('meta name=go-source', () => { + it('returns null for unknown prefix', async () => { + const meta = + '<meta name="go-source" content="golang.org/x/text https://github.com/golang/text/ foobar">'; + httpMock + .scope('https://example.com') + .get('/x/text?go-get=1') + .reply(200, meta); + + const res = await getDatasource('example.com/x/text'); + + expect(res).toBeNull(); + }); + + it('returns null for unknown datasource', async () => { + httpMock + .scope('https://example.com') + .get('/example/module?go-get=1') + .reply(200); + + const res = await getDatasource('example.com/example/module'); + + expect(res).toBeNull(); + }); + + it('returns null for go-import prefix mismatch', async () => { + const mismatchResponse = loadFixture('go-get-github-ee.html').replace( + 'git.enterprise.com/example/module', + 'git.enterprise.com/badexample/badmodule' + ); + httpMock + .scope('https://example.com') + .get('/example/module?go-get=1') + .reply(200, mismatchResponse); + + const res = await getDatasource('example.com/example/module'); + + expect(res).toBeNull(); + }); + + it('supports GitHub deps', async () => { + httpMock + .scope('https://golang.org') + .get('/x/text?go-get=1') + .reply(200, loadFixture('go-get-github.html')); + + const res = await getDatasource('golang.org/x/text'); + + expect(res).toEqual({ + datasource: githubDatasource, + lookupName: 'golang/text', + }); + }); + + it('supports GitHub EE deps', async () => { + httpMock + .scope('https://git.enterprise.com') + .get('/example/module?go-get=1') + .reply(200, loadFixture('go-get-github-ee.html')); + + const res = await getDatasource('git.enterprise.com/example/module'); + + expect(res).toEqual({ + datasource: githubDatasource, + lookupName: 'example/module', + registryUrl: 'https://git.enterprise.com', + }); + }); + + it('supports GitLab deps', async () => { + httpMock + .scope('https://gitlab.com') + .get('/group/subgroup?go-get=1') + .reply(200, loadFixture('go-get-gitlab.html')); + + const res = await getDatasource('gitlab.com/group/subgroup'); + + expect(res).toEqual({ + datasource: gitlabDatasource, + lookupName: 'group/subgroup', + registryUrl: 'https://gitlab.com', + }); + }); + + it('supports GitLab with URL mismatch', async () => { + const mismatchingResponse = loadFixture('go-get-github.html').replace( + 'https://github.com/golang/text/', + 'https://gitlab.com/golang/text/' + ); + httpMock + .scope('https://golang.org') + .get('/x/text?go-get=1') + .reply(200, mismatchingResponse); + + const res = await getDatasource('golang.org/x/text'); + + expect(res).toEqual({ + datasource: gitlabDatasource, + lookupName: 'golang/text', + registryUrl: 'https://gitlab.com', + }); + }); + + it('supports GitLab EE deps', async () => { + hostRules.find.mockReturnValue({ token: 'some-token' }); + httpMock + .scope('https://my.custom.domain') + .get('/golang/myrepo?go-get=1') + .reply(200, loadFixture('go-get-gitlab-ee.html')); + + const res = await getDatasource('my.custom.domain/golang/myrepo'); + + expect(res).toEqual({ + datasource: gitlabDatasource, + lookupName: 'golang/myrepo', + registryUrl: 'https://my.custom.domain', + }); + }); + + it('handles fyne.io', async () => { + const meta = + '<meta name="go-import" content="fyne.io/fyne git https://github.com/fyne-io/fyne">'; + httpMock + .scope('https://fyne.io') + .get('/fyne?go-get=1') + .reply(200, meta); + + const res = await getDatasource('fyne.io/fyne'); + + expect(res).toEqual({ + datasource: 'github-tags', + registryUrl: 'https://github.com', + lookupName: 'fyne-io/fyne', + }); + }); + }); + }); +}); diff --git a/lib/datasource/go/releases-direct.spec.ts b/lib/datasource/go/releases-direct.spec.ts index 5a4b6c2a0e38f460ecf73b84d3b4213a4c002127..ff1c6676f6d109d8bff380ebf624a267527ae25f 100644 --- a/lib/datasource/go/releases-direct.spec.ts +++ b/lib/datasource/go/releases-direct.spec.ts @@ -1,64 +1,19 @@ import * as httpMock from '../../../test/http-mock'; -import { logger, mocked } from '../../../test/util'; +import { mocked } from '../../../test/util'; import * as _hostRules from '../../util/host-rules'; +import * as _ds from './get-datasource'; import { getReleases } from './releases-direct'; jest.mock('../../util/host-rules'); -const hostRules = mocked(_hostRules); - -const res1 = `<!DOCTYPE html> -<html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> -<meta name="go-import" content="golang.org/x/text git https://go.googlesource.com/text"> -<meta name="go-source" content="golang.org/x/text https://github.com/golang/text/ https://github.com/golang/text/tree/master{/dir} https://github.com/golang/text/blob/master{/dir}/{file}#L{line}"> -<meta http-equiv="refresh" content="0; url=https://godoc.org/golang.org/x/text"> -</head> -<body> -Nothing to see here; <a href="https://godoc.org/golang.org/x/text">move along</a>. -</body> -</html>`; - -const res2 = `<!DOCTYPE html> -<html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> -<meta name="go-import" content="gitlab.com/group/subgroup git https://gitlab.com/group/subgroup/repo"> -<meta name="go-source" content="gitlab.com/group/subgroup https://gitlab.com/group/subgroup https://gitlab.com/group/subgroup/-/tree/master{/dir} https://gitlab.com/group/subgroup/-/blob/master{/dir}/{file}#L{line}"> -</head> -<body> -go get https://gitlab.com/group/subgroup -</body> -</html>`; - -const resGitLabEE = `<html> -<head> - <meta name="go-import" content="my.custom.domain/golang/myrepo git https://my.custom.domain/golang/myrepo.git" /> - <meta name="go-source" - content="my.custom.domain/golang/myrepo https://my.custom.domain/golang/myrepo https://my.custom.domain/golang/myrepo/-/tree/master{/dir} https://my.custom.domain/golang/myrepo/-/blob/master{/dir}/{file}#L{line}" /> -</head> - -<body>go get https://my.custom.domain/golang/myrepo</body> - -</html>`; +jest.mock('./get-datasource'); +const ds = mocked(_ds); -const resGitHubEnterprise = `<!DOCTYPE html> -<html lang="en"> -<head> -<meta charset="utf-8"> - -<title>Go remote import path metadata</title> -<meta name="go-import" content="git.enterprise.com/example/module git https://git.enterprise.com/example/module.git"> -</head> - -<body> -<!-- Metadata for Go remote import path --> -</body> -</html>`; +const hostRules = mocked(_hostRules); describe('datasource/go/releases-direct', () => { beforeEach(() => { + jest.resetAllMocks(); hostRules.find.mockReturnValue({}); hostRules.hosts.mockReturnValue([]); }); @@ -68,46 +23,26 @@ describe('datasource/go/releases-direct', () => { }); describe('getReleases', () => { - it('returns null for empty result', async () => { - httpMock - .scope('https://golang.org/') - .get('/foo/something?go-get=1') - .reply(200, res1); + it('returns null for null getDatasource result', async () => { + ds.getDatasource.mockResolvedValueOnce(null); const res = await getReleases({ lookupName: 'golang.org/foo/something', }); expect(res).toBeNull(); - expect(httpMock.getTrace()).toMatchSnapshot(); }); - it('throws for 404', async () => { - httpMock - .scope('https://golang.org/') - .get('/foo/something?go-get=1') - .reply(404); + it('throws for getDatasource error', async () => { + ds.getDatasource.mockRejectedValueOnce(new Error('unknown')); await expect( getReleases({ lookupName: 'golang.org/foo/something', }) ).rejects.toThrow(); - expect(httpMock.getTrace()).toMatchSnapshot(); - }); - it('throws for unknown error', async () => { - httpMock - .scope('https://golang.org/') - .get('/foo/something?go-get=1') - .replyWithError('error'); - await expect( - getReleases({ - lookupName: 'golang.org/foo/something', - }) - ).rejects.toThrow(); - expect(httpMock.getTrace()).toMatchSnapshot(); }); it('processes real data', async () => { - httpMock - .scope('https://golang.org/') - .get('/x/text?go-get=1') - .reply(200, res1); + ds.getDatasource.mockResolvedValueOnce({ + datasource: 'github-tags', + lookupName: 'golang/text', + }); httpMock .scope('https://api.github.com/') .get('/repos/golang/text/tags?per_page=100') @@ -123,16 +58,11 @@ describe('datasource/go/releases-direct', () => { expect(httpMock.getTrace()).toMatchSnapshot(); }); it('support gitlab', async () => { - httpMock - .scope('https://golang.org/') - .get('/x/text?go-get=1') - .reply( - 200, - res1.replace( - 'https://github.com/golang/text/', - 'https://gitlab.com/golang/text/' - ) - ); + ds.getDatasource.mockResolvedValueOnce({ + datasource: 'gitlab-tags', + registryUrl: 'https://gitlab.com', + lookupName: 'golang/text', + }); httpMock .scope('https://gitlab.com/') .get('/api/v4/projects/golang%2Ftext/repository/tags?per_page=100') @@ -146,11 +76,12 @@ describe('datasource/go/releases-direct', () => { expect(httpMock.getTrace()).toMatchSnapshot(); }); it('support self hosted gitlab private repositories', async () => { + ds.getDatasource.mockResolvedValueOnce({ + datasource: 'gitlab-tags', + registryUrl: 'https://my.custom.domain', + lookupName: 'golang/myrepo', + }); hostRules.find.mockReturnValue({ token: 'some-token' }); - httpMock - .scope('https://my.custom.domain/') - .get('/golang/myrepo?go-get=1') - .reply(200, resGitLabEE); httpMock .scope('https://my.custom.domain/') .get('/api/v4/projects/golang%2Fmyrepo/repository/tags?per_page=100') @@ -164,6 +95,10 @@ describe('datasource/go/releases-direct', () => { expect(httpMock.getTrace()).toMatchSnapshot(); }); it('support bitbucket tags', async () => { + ds.getDatasource.mockResolvedValueOnce({ + datasource: 'bitbucket-tags', + lookupName: 'golang/text', + }); httpMock .scope('https://api.bitbucket.org/') .get('/2.0/repositories/golang/text/refs/tags') @@ -180,29 +115,12 @@ describe('datasource/go/releases-direct', () => { expect(res).toBeDefined(); expect(httpMock.getTrace()).toMatchSnapshot(); }); - it('unknown datasource returns null', async () => { - httpMock - .scope('https://some.unknown.website/') - .get('/example/module?go-get=1') - .reply(200); - const res = await getReleases({ - lookupName: 'some.unknown.website/example/module', - }); - expect(res).toMatchSnapshot(); - expect(res).toBeNull(); - expect(httpMock.getTrace()).toMatchSnapshot(); - expect(logger.logger.info).toHaveBeenCalledWith( - { lookupName: 'some.unknown.website/example/module' }, - 'Unsupported go host - cannot look up versions' - ); - expect(logger.logger.error).not.toHaveBeenCalled(); - expect(logger.logger.fatal).not.toHaveBeenCalled(); - }); it('support ghe', async () => { - httpMock - .scope('https://git.enterprise.com/') - .get('/example/module?go-get=1') - .reply(200, resGitHubEnterprise); + ds.getDatasource.mockResolvedValueOnce({ + datasource: 'github-tags', + registryUrl: 'https://git.enterprise.com', + lookupName: 'example/module', + }); httpMock .scope('https://git.enterprise.com/') .get('/api/v3/repos/example/module/tags?per_page=100') @@ -217,52 +135,19 @@ describe('datasource/go/releases-direct', () => { expect(res).toBeDefined(); expect(httpMock.getTrace()).toMatchSnapshot(); }); - it('returns null for go-import prefix mismatch', async () => { - httpMock - .scope('https://git.enterprise.com/') - .get('/example/module?go-get=1') - .reply( - 200, - resGitHubEnterprise.replace( - 'git.enterprise.com/example/module', - 'git.enterprise.com/badexample/badmodule' - ) - ); - const res = await getReleases({ - lookupName: 'git.enterprise.com/example/module', + it('works for known servers', async () => { + ds.getDatasource.mockResolvedValueOnce({ + datasource: 'github-tags', + lookupName: 'x/text', }); - expect(res).toBeNull(); - expect(httpMock.getTrace()).toMatchSnapshot(); - }); - it('skips wrong package', async () => { - httpMock - .scope('https://golang.org/') - .get('/x/sys?go-get=1') - .reply(200, res1); - const res = await getReleases({ - lookupName: 'golang.org/x/sys', + ds.getDatasource.mockResolvedValueOnce({ + datasource: 'github-tags', + lookupName: 'x/text', }); - expect(res).toBeNull(); - expect(httpMock.getTrace()).toMatchSnapshot(); - }); - it('skips unsupported platform', async () => { - httpMock - .scope('https://golang.org/') - .get('/x/text?go-get=1') - .reply( - 200, - res1.replace( - 'https://github.com/golang/text/', - 'https://google.com/golang/text/' - ) - ); - const res = await getReleases({ - lookupName: 'golang.org/x/text', + ds.getDatasource.mockResolvedValueOnce({ + datasource: 'github-tags', + lookupName: 'go-x/x', }); - expect(res).toBeNull(); - expect(httpMock.getTrace()).toMatchSnapshot(); - }); - it('works for known servers', async () => { httpMock .scope('https://api.github.com/') .get('/repos/x/text/tags?per_page=100') @@ -291,10 +176,11 @@ describe('datasource/go/releases-direct', () => { expect(httpCalls).toMatchSnapshot(); }); it('support gitlab subgroups', async () => { - httpMock - .scope('https://gitlab.com/') - .get('/group/subgroup/repo?go-get=1') - .reply(200, res2); + ds.getDatasource.mockResolvedValueOnce({ + datasource: 'gitlab-tags', + registryUrl: 'https://gitlab.com', + lookupName: 'group/subgroup/repo', + }); httpMock .scope('https://gitlab.com/') .get( @@ -310,6 +196,18 @@ describe('datasource/go/releases-direct', () => { expect(httpMock.getTrace()).toMatchSnapshot(); }); it('works for nested modules on github', async () => { + ds.getDatasource.mockResolvedValueOnce({ + datasource: 'github-tags', + lookupName: 'x/text', + }); + ds.getDatasource.mockResolvedValueOnce({ + datasource: 'github-tags', + lookupName: 'x/text', + }); + ds.getDatasource.mockResolvedValueOnce({ + datasource: 'github-tags', + lookupName: 'x/text', + }); const packages = [ { lookupName: 'github.com/x/text/a' }, { lookupName: 'github.com/x/text/b' }, @@ -335,6 +233,14 @@ describe('datasource/go/releases-direct', () => { } }); it('returns none if no tags match submodules', async () => { + ds.getDatasource.mockResolvedValueOnce({ + datasource: 'github-tags', + lookupName: 'x/text', + }); + ds.getDatasource.mockResolvedValueOnce({ + datasource: 'github-tags', + lookupName: 'x/text', + }); const packages = [ { lookupName: 'github.com/x/text/a' }, { lookupName: 'github.com/x/text/b' }, @@ -358,6 +264,10 @@ describe('datasource/go/releases-direct', () => { } }); it('works for nested modules on github v2+ major upgrades', async () => { + ds.getDatasource.mockResolvedValueOnce({ + datasource: 'github-tags', + lookupName: 'x/text', + }); const pkg = { lookupName: 'github.com/x/text/b/v2' }; const tags = [ { name: 'a/v1.0.0' }, @@ -382,27 +292,5 @@ describe('datasource/go/releases-direct', () => { const httpCalls = httpMock.getTrace(); expect(httpCalls).toMatchSnapshot(); }); - it('handles fyne.io', async () => { - httpMock - .scope('https://fyne.io/') - .get('/fyne?go-get=1') - .reply( - 200, - '<meta name="go-import" content="fyne.io/fyne git https://github.com/fyne-io/fyne">' - ); - httpMock - .scope('https://api.github.com/') - .get('/repos/fyne-io/fyne/tags?per_page=100') - .reply(200, [{ name: 'v1.0.0' }, { name: 'v2.0.0' }]) - .get('/repos/fyne-io/fyne/releases?per_page=100') - .reply(200, []); - const res = await getReleases({ - lookupName: 'fyne.io/fyne', - }); - expect(res).toMatchSnapshot(); - expect(res).not.toBeNull(); - expect(res).toBeDefined(); - expect(httpMock.getTrace()).toMatchSnapshot(); - }); }); });