11import { codeBlock } from 'common-tags' ;
2+ import { mockDeep } from 'jest-mock-extended' ;
23import { Fixtures } from '../../../../test/fixtures' ;
34import * as httpMock from '../../../../test/http-mock' ;
5+ import { mocked } from '../../../../test/util' ;
6+ import * as _hostRules from '../../../util/host-rules' ;
47import { GithubReleasesDatasource } from '../github-releases' ;
58import { GithubTagsDatasource } from '../github-tags' ;
69import { GoProxyDatasource } from './releases-goproxy' ;
710
11+ const hostRules = mocked ( _hostRules ) ;
12+ jest . mock ( '../../../util/host-rules' , ( ) => mockDeep ( ) ) ;
13+
814const datasource = new GoProxyDatasource ( ) ;
915
1016describe ( 'modules/datasource/go/releases-goproxy' , ( ) => {
@@ -18,6 +24,10 @@ describe('modules/datasource/go/releases-goproxy', () => {
1824 'getReleases' ,
1925 ) ;
2026
27+ beforeEach ( ( ) => {
28+ hostRules . find . mockReturnValue ( { } ) ;
29+ } ) ;
30+
2131 it ( 'encodeCase' , ( ) => {
2232 expect ( datasource . encodeCase ( 'foo' ) ) . toBe ( 'foo' ) ;
2333 expect ( datasource . encodeCase ( 'Foo' ) ) . toBe ( '!foo' ) ;
@@ -195,46 +205,54 @@ describe('modules/datasource/go/releases-goproxy', () => {
195205 } ) ;
196206 } ) ;
197207
198- it ( 'handles pipe fallback' , async ( ) => {
199- process . env . GOPROXY = `https://example.com|${ baseUrl } ` ;
200-
201- httpMock
202- . scope ( 'https://example.com/github.com/google/btree' )
203- . get ( '/@v/list' )
204- . replyWithError ( 'unknown' ) ;
205-
206- httpMock
207- . scope ( `${ baseUrl } /github.com/google/btree` )
208- . get ( '/@v/list' )
209- . reply (
210- 200 ,
211- codeBlock `
208+ it . each < { abortOnError : boolean } > `
209+ abortOnError
210+ ${ true }
211+ ${ false }
212+ ` (
213+ 'handles pipe fallback when abortOnError is $abortOnError' ,
214+ async ( { abortOnError } ) => {
215+ process . env . GOPROXY = `https://example.com|${ baseUrl } ` ;
216+ hostRules . find . mockReturnValue ( { abortOnError } ) ;
217+
218+ httpMock
219+ . scope ( 'https://example.com/github.com/google/btree' )
220+ . get ( '/@v/list' )
221+ . replyWithError ( 'unknown' ) ;
222+
223+ httpMock
224+ . scope ( `${ baseUrl } /github.com/google/btree` )
225+ . get ( '/@v/list' )
226+ . reply (
227+ 200 ,
228+ codeBlock `
212229 v1.0.0
213230 v1.0.1
214231 ` ,
215- )
216- . get ( '/@v/v1.0.0.info' )
217- . reply ( 200 , { Version : 'v1.0.0' , Time : '2018-08-13T15:31:12Z' } )
218- . get ( '/@v/v1.0.1.info' )
219- . reply ( 200 , { Version : 'v1.0.1' , Time : '2019-10-16T16:15:28Z' } )
220- . get ( '/@latest' )
221- . reply ( 200 , { Version : 'v1.0.1' } )
222- . get ( '/v2/@v/list' )
223- . reply ( 404 ) ;
224-
225- const res = await datasource . getReleases ( {
226- packageName : 'github.com/google/btree' ,
227- } ) ;
228-
229- expect ( res ) . toEqual ( {
230- releases : [
231- { releaseTimestamp : '2018-08-13T15:31:12Z' , version : 'v1.0.0' } ,
232- { releaseTimestamp : '2019-10-16T16:15:28Z' , version : 'v1.0.1' } ,
233- ] ,
234- sourceUrl : 'https://github.com/google/btree' ,
235- tags : { latest : 'v1.0.1' } ,
236- } ) ;
237- } ) ;
232+ )
233+ . get ( '/@v/v1.0.0.info' )
234+ . reply ( 200 , { Version : 'v1.0.0' , Time : '2018-08-13T15:31:12Z' } )
235+ . get ( '/@v/v1.0.1.info' )
236+ . reply ( 200 , { Version : 'v1.0.1' , Time : '2019-10-16T16:15:28Z' } )
237+ . get ( '/@latest' )
238+ . reply ( 200 , { Version : 'v1.0.1' } )
239+ . get ( '/v2/@v/list' )
240+ . reply ( 404 ) ;
241+
242+ const res = await datasource . getReleases ( {
243+ packageName : 'github.com/google/btree' ,
244+ } ) ;
245+
246+ expect ( res ) . toEqual ( {
247+ releases : [
248+ { releaseTimestamp : '2018-08-13T15:31:12Z' , version : 'v1.0.0' } ,
249+ { releaseTimestamp : '2019-10-16T16:15:28Z' , version : 'v1.0.1' } ,
250+ ] ,
251+ sourceUrl : 'https://github.com/google/btree' ,
252+ tags : { latest : 'v1.0.1' } ,
253+ } ) ;
254+ } ,
255+ ) ;
238256
239257 it ( 'handles comma fallback' , async ( ) => {
240258 process . env . GOPROXY = [
@@ -406,53 +424,61 @@ describe('modules/datasource/go/releases-goproxy', () => {
406424 } ) ;
407425 } ) ;
408426
409- it ( 'handles major releases' , async ( ) => {
410- process . env . GOPROXY = baseUrl ;
411-
412- httpMock
413- . scope ( `${ baseUrl } /github.com/google/btree` )
414- . get ( '/@v/list' )
415- . reply (
416- 200 ,
417- codeBlock `
427+ it . each < { abortOnError : boolean } > `
428+ abortOnError
429+ ${ true }
430+ ${ false }
431+ ` (
432+ 'handles major releases with abortOnError is $abortOnError' ,
433+ async ( { abortOnError } ) => {
434+ process . env . GOPROXY = baseUrl ;
435+ hostRules . find . mockReturnValue ( { abortOnError } ) ;
436+
437+ httpMock
438+ . scope ( `${ baseUrl } /github.com/google/btree` )
439+ . get ( '/@v/list' )
440+ . reply (
441+ 200 ,
442+ codeBlock `
418443 v1.0.0
419444 v1.0.1
420445 ` ,
421- )
422- . get ( '/@v/v1.0.0.info' )
423- . reply ( 200 , { Version : 'v1.0.0' , Time : '2018-08-13T15:31:12Z' } )
424- . get ( '/@v/v1.0.1.info' )
425- . reply ( 200 , { Version : 'v1.0.1' , Time : '2019-10-16T16:15:28Z' } )
426- . get ( '/@latest' )
427- . reply ( 200 , { Version : 'v1.0.1' } )
428- . get ( '/v2/@v/list' )
429- . reply (
430- 200 ,
431- codeBlock `
446+ )
447+ . get ( '/@v/v1.0.0.info' )
448+ . reply ( 200 , { Version : 'v1.0.0' , Time : '2018-08-13T15:31:12Z' } )
449+ . get ( '/@v/v1.0.1.info' )
450+ . reply ( 200 , { Version : 'v1.0.1' , Time : '2019-10-16T16:15:28Z' } )
451+ . get ( '/@latest' )
452+ . reply ( 200 , { Version : 'v1.0.1' } )
453+ . get ( '/v2/@v/list' )
454+ . reply (
455+ 200 ,
456+ codeBlock `
432457 v2.0.0
433458 ` ,
434- )
435- . get ( '/v2/@v/v2.0.0.info' )
436- . reply ( 200 , { Version : 'v2.0.0' , Time : '2020-10-16T16:15:28Z' } )
437- . get ( '/v2/@latest' )
438- . reply ( 200 , { Version : 'v2.0.0' } )
439- . get ( '/v3/@v/list' )
440- . reply ( 404 ) ;
441-
442- const res = await datasource . getReleases ( {
443- packageName : 'github.com/google/btree' ,
444- } ) ;
445-
446- expect ( res ) . toEqual ( {
447- releases : [
448- { releaseTimestamp : '2018-08-13T15:31:12Z' , version : 'v1.0.0' } ,
449- { releaseTimestamp : '2019-10-16T16:15:28Z' , version : 'v1.0.1' } ,
450- { releaseTimestamp : '2020-10-16T16:15:28Z' , version : 'v2.0.0' } ,
451- ] ,
452- sourceUrl : 'https://github.com/google/btree' ,
453- tags : { latest : 'v2.0.0' } ,
454- } ) ;
455- } ) ;
459+ )
460+ . get ( '/v2/@v/v2.0.0.info' )
461+ . reply ( 200 , { Version : 'v2.0.0' , Time : '2020-10-16T16:15:28Z' } )
462+ . get ( '/v2/@latest' )
463+ . reply ( 200 , { Version : 'v2.0.0' } )
464+ . get ( '/v3/@v/list' )
465+ . reply ( 404 ) ;
466+
467+ const res = await datasource . getReleases ( {
468+ packageName : 'github.com/google/btree' ,
469+ } ) ;
470+
471+ expect ( res ) . toEqual ( {
472+ releases : [
473+ { releaseTimestamp : '2018-08-13T15:31:12Z' , version : 'v1.0.0' } ,
474+ { releaseTimestamp : '2019-10-16T16:15:28Z' , version : 'v1.0.1' } ,
475+ { releaseTimestamp : '2020-10-16T16:15:28Z' , version : 'v2.0.0' } ,
476+ ] ,
477+ sourceUrl : 'https://github.com/google/btree' ,
478+ tags : { latest : 'v2.0.0' } ,
479+ } ) ;
480+ } ,
481+ ) ;
456482
457483 it ( 'handles gopkg.in major releases' , async ( ) => {
458484 process . env . GOPROXY = baseUrl ;
0 commit comments