11/* eslint-env mocha */
22import { access , constants } from 'node:fs/promises'
3- import { homedir } from 'node:os'
4- import { join } from 'node:path'
53import { prefixLogger } from '@libp2p/logger'
64import { expect } from 'aegir/chai'
7- import { execa } from 'execa'
8- import { Agent , setGlobalDispatcher } from 'undici'
9- import { GWC_IMAGE } from './constants.js'
105import expectedFailingTests from './expected-failing-tests.json' with { type : 'json' }
116import expectedPassingTests from './expected-passing-tests.json' with { type : 'json' }
127import { getReportDetails } from './get-report-details.js'
13- import { getTestsToRun } from './get-tests-to-run.js'
14- import { getTestsToSkip } from './get-tests-to-skip.js'
158
169const logger = prefixLogger ( 'gateway-conformance' )
1710
18- function getGatewayConformanceBinaryPath ( ) : string {
19- if ( process . env . GATEWAY_CONFORMANCE_BINARY != null ) {
20- return process . env . GATEWAY_CONFORMANCE_BINARY
21- }
22- const goPath = process . env . GOPATH ?? join ( homedir ( ) , 'go' )
23- return join ( goPath , 'bin' , 'gateway-conformance' )
24- }
25-
26- function getConformanceTestArgs ( name : string , gwcArgs : string [ ] = [ ] , goTestArgs : string [ ] = [ ] ) : string [ ] {
27- return [
28- 'test' ,
29- `--gateway-url=http://127.0.0.1:${ process . env . SERVER_PORT } ` ,
30- `--subdomain-url=http://${ process . env . CONFORMANCE_HOST } :${ process . env . SERVER_PORT } ` ,
31- '--verbose' ,
32- '--json' , `gwc-report-${ name } .json` ,
33- ...gwcArgs ,
34- '--' ,
35- '-timeout' , '5m' ,
36- ...goTestArgs
37- ]
38- }
39-
4011describe ( '@helia/verified-fetch - gateway conformance' , function ( ) {
41- before ( async ( ) => {
42- if ( process . env . KUBO_GATEWAY == null ) {
43- throw new Error ( 'KUBO_GATEWAY env var is required' )
44- }
45- if ( process . env . SERVER_PORT == null ) {
46- throw new Error ( 'SERVER_PORT env var is required' )
47- }
48- if ( process . env . CONFORMANCE_HOST == null ) {
49- throw new Error ( 'CONFORMANCE_HOST env var is required' )
50- }
51- // see https://stackoverflow.com/questions/71074255/use-custom-dns-resolver-for-any-request-in-nodejs
52- // EVERY undici/fetch request host resolves to local IP. Without this, Node.js does not resolve subdomain requests properly
53- const staticDnsAgent = new Agent ( {
54- connect : {
55- lookup : ( _hostname , _options , callback ) => { callback ( null , [ { address : '0.0.0.0' , family : 4 } ] ) }
56- }
57- } )
58- setGlobalDispatcher ( staticDnsAgent )
59- } )
60-
61- describe ( 'smokeTests' , ( ) => {
62- [
63- [ 'basic server path request works' , `http://localhost:${ process . env . SERVER_PORT } /ipfs/bafkqabtimvwgy3yk` ] ,
64- [ 'basic server subdomain request works' , `http://bafkqabtimvwgy3yk.ipfs.localhost:${ process . env . SERVER_PORT } ` ]
65- ] . forEach ( ( [ name , url ] ) => {
66- it ( name , async ( ) => {
67- const resp = await fetch ( url )
68- expect ( resp ) . to . be . ok ( )
69- expect ( resp . status ) . to . equal ( 200 )
70- const text = await resp . text ( )
71- expect ( text . trim ( ) ) . to . equal ( 'hello' )
72- } )
73- } )
74- } )
75-
7612 describe ( 'conformance testing' , ( ) => {
77- const binaryPath = getGatewayConformanceBinaryPath ( )
78- before ( async ( ) => {
79- const log = logger . forComponent ( 'before' )
80- if ( process . env . GATEWAY_CONFORMANCE_BINARY != null ) {
81- log ( 'Using custom gateway-conformance binary at %s' , binaryPath )
82- return
83- }
84- const gwcVersion = GWC_IMAGE . split ( ':' ) . pop ( )
85- const { stdout, stderr } = await execa ( 'go' , [ 'install' , `github.com/ipfs/gateway-conformance/cmd/gateway-conformance@${ gwcVersion } ` ] , { reject : true } )
86- log ( stdout )
87- log . error ( stderr )
88- } )
89-
90- after ( async ( ) => {
91- const log = logger . forComponent ( 'after' )
92-
93- if ( process . env . GATEWAY_CONFORMANCE_BINARY == null ) {
94- try {
95- await execa ( 'rm' , [ binaryPath ] )
96- log ( 'gateway-conformance binary successfully uninstalled.' )
97- } catch ( error ) {
98- log . error ( `Error removing "${ binaryPath } "` , error )
99- }
100- } else {
101- log ( 'Not removing custom gateway-conformance binary at %s' , binaryPath )
102- }
103- } )
104-
10513 /**
10614 * You can see what the latest success rate, passing tests, and failing tests are by running the following command:
10715 *
@@ -110,34 +18,26 @@ describe('@helia/verified-fetch - gateway conformance', function () {
11018 * ```
11119 */
11220 describe ( 'gateway conformance' , function ( ) {
113- this . timeout ( 200000 )
11421 let successRate : number
11522 let failingTests : string [ ]
11623 let passingTests : string [ ]
11724 const log = logger . forComponent ( 'output:all' )
11825
11926 before ( async function ( ) {
120- const testsToSkip : string [ ] = getTestsToSkip ( )
121- const testsToRun : string [ ] = getTestsToRun ( )
122- const cancelSignal = AbortSignal . timeout ( 200000 )
123- const { stderr, stdout } = await execa ( binaryPath , getConformanceTestArgs ( 'all' , [ ] , [
124- ...( testsToRun . length > 0 ? [ '-run' , `${ testsToRun . join ( '|' ) } ` ] : [ ] ) ,
125- ...( testsToSkip . length > 0 ? [ '-skip' , `${ testsToSkip . join ( '|' ) } ` ] : [ ] )
126- ] ) , { reject : false , cancelSignal } )
127-
128- expect ( cancelSignal . aborted ) . to . be . false ( )
129-
130- log ( stdout )
131- log . error ( stderr )
13227 await expect ( access ( 'gwc-report-all.json' , constants . R_OK ) ) . to . eventually . be . fulfilled ( )
13328 const results = await getReportDetails ( 'gwc-report-all.json' )
13429 successRate = results . successRate
13530 failingTests = results . failingTests
13631 passingTests = results . passingTests
32+
13733 log . trace ( 'Passing tests:' )
138- passingTests . forEach ( ( test ) => { log . trace ( `PASS: ${ test } ` ) } )
34+ for ( const test of passingTests ) {
35+ log . trace ( `PASS: ${ test } ` )
36+ }
13937 log . trace ( 'Failing tests:' )
140- failingTests . forEach ( ( test ) => { log . trace ( `FAIL: ${ test } ` ) } )
38+ for ( const test of failingTests ) {
39+ log . trace ( `FAIL: ${ test } ` )
40+ }
14141 } )
14242
14343 for ( const test of expectedPassingTests ) {
0 commit comments