Skip to content

Commit

Permalink
feat: updated dataset (2023-11-17) (#112)
Browse files Browse the repository at this point in the history
Co-authored-by: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com>
Co-authored-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 28, 2023
1 parent 32e9ac3 commit 83c1b09
Show file tree
Hide file tree
Showing 21 changed files with 4,303 additions and 2,544 deletions.
41 changes: 35 additions & 6 deletions .aegir.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import http from 'node:http'
import fs from 'node:fs'

export default {
tsRepo: false,
dependencyCheck: {
Expand All @@ -20,14 +23,40 @@ export default {
}
},
test: {
before: (...args) => {
if (args[0].runner === 'node') {
return {
env: {
NODE_OPTIONS: '--loader=esmock'
}
before: async (...args) => {
// set up a server to serve the fixtures
const server = http.createServer((req, res) => {
const cidString = req.url.replace('/ipfs/', '').split('?')[0]
const mockBlock = fs.readFileSync(`./test/fixtures/${cidString}.raw.bin`, null)

res.writeHead(200, {
'access-control-allow-origin': '*', // allow CORS requests
'Content-Type': 'application/vnd.ipld.raw',
'Content-Length': mockBlock.length
})
res.end(mockBlock)
})
let gwUrl = process.env.IPFS_GATEWAY
if (!gwUrl) {
// no gateway specified, start the server
await new Promise((resolve, _reject) => {
server.listen(0, () => {
gwUrl = `http://localhost:${server.address().port}`
console.log(`server listening at ${gwUrl}`)
resolve()
})
})
}

return {
server,
env: {
IPFS_GATEWAY: gwUrl,
}
}
},
after: (_, before) => {
before.server.close()
}
}
}
8 changes: 7 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@
"parserOptions": {
"sourceType": "module",
"allowImportExportEverywhere": true
}
},
"ignorePatterns": [
"**/bin/load-fixtures.sh",
"**/dist/**",
"**/node_modules/**",
"**/test/fixtures/**"
],
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ build
node_modules

dist
ipfs-geoip.car
9 changes: 9 additions & 0 deletions DEVELOPER-NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Load fixtures

We need to load a fixture with the following command:

```bash
./bin/load-fixtures.sh bafyreif3tfdpr5n4jdrbielmcapwvbpcthepfkwq2vwonmlhirbjmotedi
```

then, we can do `npm run test:node -- -g 'lookup via HTTP Gateway'` to run a test that will tell us of any subsequent fixtures we need to load, and replace the CID in the above command with the CID that the test hangs on, and repeat.
2 changes: 1 addition & 1 deletion bin/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint no-console: "off", no-unreachable: "off" */
import Gauge from 'gauge'
import gen from '../src/generate/index.js'
import { create } from 'ipfs-http-client'
import { create } from 'kubo-rpc-client'
import { CarWriter } from '@ipld/car'
import fs from 'fs'
import { Readable } from 'stream'
Expand Down
8 changes: 8 additions & 0 deletions bin/load-fixtures.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

function main() {
local CID="$1"
curl -H "Accept: application/vnd.ipld.raw" "https://ipfs.io/ipfs/$CID?format=raw" > test/fixtures/$CID.raw.bin
}

main "$@"
Loading

0 comments on commit 83c1b09

Please sign in to comment.