Skip to content

Commit

Permalink
test: add gateway conformance tests (#67)
Browse files Browse the repository at this point in the history
* feat: initial gateway-conformance setup

* feat: basic subdomain and path requests work

* docs: add debug instructions

* feat: multiple changes and fixes to lint/dep-check

* chore: trying to get passing tests to run is a PITA

* fix: split up conformance tests so its not one big long run

* fix: longer spec test timeout and more accurate fail/pass count

* chore: ensure test:node script exists

* feat: making progress on conformance test running

* feat: gateway-conformance tests are running and passing locally

NOTE: we are failing actual conformance tests, but the tests here ensure no regressions

* tmp: fix for #68

* feat: use gateway-conformance cmd instead of docker

* feat: create github action for running gateway conformance

* fix: gateway conformance action working dir

* fix: remove test:node script so tests aren't run with others because additional setup is required

* fix: json formatting

* fix: tighten up expectations with minSuccesses

* fix: gateway conformance action syntax is correct

* fix: gwc can npm install deps

* chore: gwc gh action caches node modules

* fix: remove mkdir

* chore: update actions/upload-artifact

* test: explicit counts for default gwc specs

* chore: apply suggestions from code review

* test: support IPFS_NS_MAP fixtures

* chore: various fixes

* test: disable ipfs_ns_map in CI
  • Loading branch information
SgtPooki committed May 9, 2024
1 parent 754e219 commit 30958fb
Show file tree
Hide file tree
Showing 21 changed files with 1,257 additions and 0 deletions.
82 changes: 82 additions & 0 deletions .github/workflows/gateway-conformance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Gateway Conformance

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
gateway-conformance:
runs-on: ubuntu-latest
steps:
# 1, Setup Node, install npm dependencies, and build all packages/*
# see https://github.com/ipdxco/unified-github-workflows/blob/3a1a7870ce5967163d8f5c8210b8ad50b2e659aa/.github/workflows/js-test-and-release.yml#L28-L34
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- uses: ipfs/aegir/actions/cache-node-modules@master

# 2. Set up 'go' so we can install the gateway-conformance binary
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: 1.21.x

# 3. Download the gateway-conformance fixtures using ipfs/gateway-conformance action
# This will prevent us from needing to install `docker` on the github runner
- name: Download gateway-conformance fixtures
uses: ipfs/gateway-conformance/.github/actions/extract-fixtures@v0.5.1
# working-directory: ./packages/gateway-conformance
with:
output: ./packages/gateway-conformance/dist/src/fixtures/data/gateway-conformance-fixtures


# 4. Run the tests
- name: Run gateway-conformance tests
run: |
npm run test
working-directory: ./packages/gateway-conformance

# 5. Convert json output to reports similar to how it's done at https://github.com/ipfs/gateway-conformance/blob/main/.github/actions/test/action.yml
# the 'gwc-report-all.json' file is created by the 'has expected total failures and successes' test
# TODO: remove this when we're passing enough tests to use the 'ipfs/gateway-conformance/.github/actions/test' action
- name: Create the XML
if: failure() || success()
uses: pl-strflt/gotest-json-to-junit-xml@v1
with:
input: ./packages/gateway-conformance/gwc-report-all.json
output: ./packages/gateway-conformance/gwc-report-all.xml
- name: Create the HTML
if: failure() || success()
uses: pl-strflt/junit-xml-to-html@v1
with:
mode: no-frames
input: ./packages/gateway-conformance/gwc-report-all.xml
output: ./packages/gateway-conformance/gwc-report-all.html
- name: Create the Markdown
if: failure() || success()
uses: pl-strflt/junit-xml-to-html@v1
with:
mode: summary
input: ./packages/gateway-conformance/gwc-report-all.xml
output: ./packages/gateway-conformance/gwc-report-all.md

# 6. Upload the reports
- name: Upload MD summary
if: failure() || success()
run: cat ./packages/gateway-conformance/gwc-report-all.md >> $GITHUB_STEP_SUMMARY
- name: Upload HTML report
if: failure() || success()
uses: actions/upload-artifact@v4
with:
name: gateway-conformance.html
path: ./packages/gateway-conformance/gwc-report-all.html
- name: Upload JSON report
if: failure() || success()
uses: actions/upload-artifact@v4
with:
name: gateway-conformance.json
path: ./packages/gateway-conformance/gwc-report-all.json
65 changes: 65 additions & 0 deletions packages/gateway-conformance/.aegir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// @ts-check
import getPort from 'aegir/get-port'

/** @type {import('aegir').PartialOptions} */
export default {
test: {
files: ['./dist/src/*.spec.js'],
before: async (options) => {
if (options.runner !== 'node') {
throw new Error('Only node runner is supported')
}

const { GWC_IMAGE } = await import('./dist/src/constants.js')
const { loadKuboFixtures, kuboRepoDir } = await import('./dist/src/fixtures/kubo-mgmt.js')
const IPFS_NS_MAP = await loadKuboFixtures()

const { createKuboNode } = await import('./dist/src/fixtures/create-kubo.js')
const controller = await createKuboNode(await getPort(3440))
await controller.start()
const kuboGateway = `http://${controller.api.gatewayHost}:${controller.api.gatewayPort}`

const { startBasicServer } = await import('./dist/src/fixtures/basic-server.js')
const SERVER_PORT = await getPort(3441)
const stopBasicServer = await startBasicServer({
serverPort: SERVER_PORT,
kuboGateway
})

const { startReverseProxy } = await import('./dist/src/fixtures/reverse-proxy.js')
const PROXY_PORT = await getPort(3442)
const KUBO_PORT = controller.api.gatewayPort
const stopReverseProxy = await startReverseProxy({
backendPort: SERVER_PORT,
targetHost: 'localhost',
proxyPort: PROXY_PORT
})

const CONFORMANCE_HOST = 'localhost'

return {
controller,
stopReverseProxy,
stopBasicServer,
env: {
IPFS_NS_MAP,
GWC_IMAGE,
CONFORMANCE_HOST,
KUBO_PORT: `${KUBO_PORT}`,
PROXY_PORT: `${PROXY_PORT}`,
SERVER_PORT: `${SERVER_PORT}`,
KUBO_GATEWAY: kuboGateway,
KUBO_REPO: process.env.KUBO_REPO || kuboRepoDir
}
}
},
after: async (options, beforeResult) => {
// @ts-expect-error - broken aegir types
await beforeResult.stopReverseProxy()
// @ts-expect-error - broken aegir types
await beforeResult.stopBasicServer()
// @ts-expect-error - broken aegir types
await beforeResult.controller.stop()
}
}
}
1 change: 1 addition & 0 deletions packages/gateway-conformance/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gwc-report*.json
Empty file.
4 changes: 4 additions & 0 deletions packages/gateway-conformance/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This project is dual licensed under MIT and Apache-2.0.

MIT: https://www.opensource.org/licenses/mit
Apache-2.0: https://www.apache.org/licenses/license-2.0
5 changes: 5 additions & 0 deletions packages/gateway-conformance/LICENSE-APACHE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
19 changes: 19 additions & 0 deletions packages/gateway-conformance/LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
58 changes: 58 additions & 0 deletions packages/gateway-conformance/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<p align="center">
<a href="https://github.com/ipfs/helia" title="Helia">
<img src="https://raw.githubusercontent.com/ipfs/helia/main/assets/helia.png" alt="Helia logo" width="300" />
</a>
</p>

# @helia/verified-fetch-gateway-conformance

[![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech)
[![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech)
[![codecov](https://img.shields.io/codecov/c/github/ipfs/helia-verified-fetch.svg?style=flat-square)](https://codecov.io/gh/ipfs/helia-verified-fetch)
[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/helia-verified-fetch/js-test-and-release.yml?branch=main\&style=flat-square)](https://github.com/ipfs/helia-verified-fetch/actions/workflows/js-test-and-release.yml?query=branch%3Amain)

> [Gateway Conformance](https://github.com/ipfs/gateway-conformance) tests for @helia/verified-fetch
# About

Runs Gateway Conformance tests against @helia/verified-fetch using Kubo as a backing trustless-gateway.

## Example - Testing a new Kubo release

```console
$ npm i @helia/verified-fetch-gateway-conformance
$ KUBO_BINARY=/path/to/kubo verified-fetch-gateway-conformance
```

# Install

```console
$ npm i @helia/verified-fetch-gateway-conformance
```

## Browser `<script>` tag

Loading this module through a script tag will make it's exports available as `HeliaInterop` in the global namespace.

```html
<script src="https://unpkg.com/@helia/verified-fetch-gateway-conformance/dist/index.min.js"></script>
```

# License

Licensed under either of

- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)

# Contribute

Contributions welcome! Please check out [the issues](https://github.com/ipfs/helia-verified-fetch/issues).

Also see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.

Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)
70 changes: 70 additions & 0 deletions packages/gateway-conformance/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"name": "@helia/verified-fetch-gateway-conformance",
"version": "1.20.0",
"description": "Gateway conformance tests for @helia/verified-fetch",
"license": "Apache-2.0 OR MIT",
"homepage": "https://github.com/ipfs/helia-verified-fetch/tree/main/packages/gateway-conformance#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/ipfs/helia-verified-fetch.git"
},
"bugs": {
"url": "https://github.com/ipfs/helia-verified-fetch/issues"
},
"publishConfig": {
"access": "public",
"provenance": true
},
"keywords": [
"IPFS"
],
"bin": {
"demo-server": "./dist/src/demo-server.js",
"verified-fetch-gateway-conformance": "./dist/src/bin.js"
},
"type": "module",
"types": "./dist/src/index.d.ts",
"files": [
"src",
"dist",
"!dist/test",
"!**/*.tsbuildinfo"
],
"exports": {
".": {
"types": "./dist/src/index.d.ts",
"import": "./dist/src/index.js"
}
},
"eslintConfig": {
"extends": "ipfs",
"parserOptions": {
"project": true,
"sourceType": "module"
}
},
"scripts": {
"clean": "aegir clean dist gwc-report-*.json",
"lint": "aegir lint",
"dep-check": "aegir dep-check",
"doc-check": "aegir doc-check",
"build": "aegir build",
"test": "aegir test -t node"
},
"dependencies": {
"@helia/verified-fetch": "1.3.13",
"@libp2p/logger": "^4.0.11",
"@sgtpooki/file-type": "^1.0.1",
"aegir": "^42.2.5",
"execa": "^8.0.1",
"glob": "^10.3.12",
"ipfsd-ctl": "^13.0.0",
"kubo": "^0.27.0",
"kubo-rpc-client": "^3.0.4",
"undici": "^6.15.0"
},
"browser": {
"./dist/src/fixtures/create-kubo.js": "./dist/src/fixtures/create-kubo.browser.js",
"kubo": false
}
}
25 changes: 25 additions & 0 deletions packages/gateway-conformance/src/bin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#! /usr/bin/env node
/* eslint-disable no-console */

import { spawn } from 'node:child_process'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'

// aegir should be run from `node_modules/@helia/verified-fetch-gateway-conformance`
const cwd = resolve(dirname(fileURLToPath(import.meta.url)), '../../')

const test = spawn('npx', ['aegir', 'test'], {
cwd
})

test.stdout.on('data', (data) => {
process.stdout.write(data)
})

test.stderr.on('data', (data) => {
process.stderr.write(data)
})

test.on('close', (code) => {
process.exit(code ?? 0)
})
Loading

0 comments on commit 30958fb

Please sign in to comment.