This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathdns.js
97 lines (75 loc) · 2.3 KB
/
dns.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* eslint-env mocha */
import { expect } from 'aegir/chai'
import { getDescribe, getIt } from '../utils/mocha.js'
/**
* @typedef {import('ipfsd-ctl').Factory} Factory
*/
/**
* @param {Factory} factory
* @param {object} options
*/
export function testDns (factory, options) {
const describe = getDescribe(options)
const it = getIt(options)
describe('.dns', function () {
this.timeout(60 * 1000)
this.retries(3)
/** @type {import('ipfs-core-types').IPFS} */
let ipfs
before(async () => {
ipfs = (await factory.spawn()).api
})
after(() => factory.clean())
it('should non-recursively resolve ipfs.io', async function () {
const domain = 'ipfs.io'
try {
const res = await ipfs.dns(domain, { recursive: false })
// matches pattern /ipns/<ipnsaddress>
expect(res).to.match(/\/ipns\/.+$/)
} catch (/** @type {any} */ err) {
if (err.message.includes('could not resolve name')) {
return this.skip()
}
// happens when running tests offline
if (err.message.includes(`ECONNREFUSED ${domain}`)) {
return this.skip()
}
throw err
}
})
it('should recursively resolve ipfs.io', async function () {
const domain = 'ipfs.io'
try {
const res = await ipfs.dns(domain, { recursive: true })
// matches pattern /ipfs/<hash>
expect(res).to.match(/\/ipfs\/.+$/)
} catch (/** @type {any} */ err) {
if (err.message.includes('could not resolve name')) {
return this.skip()
}
// happens when running tests offline
if (err.message.includes(`ECONNREFUSED ${domain}`)) {
return this.skip()
}
throw err
}
})
it('should resolve subdomain docs.ipfs.io', async function () {
const domain = 'docs.ipfs.io'
try {
const res = await ipfs.dns(domain)
// matches pattern /ipfs/<hash>
expect(res).to.match(/\/ipfs\/.+$/)
} catch (/** @type {any} */ err) {
if (err.message.includes('could not resolve name')) {
return this.skip()
}
// happens when running tests offline
if (err.message.includes(`ECONNREFUSED ${domain}`)) {
return this.skip()
}
throw err
}
})
})
}