Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: interface and cli tests ported
Browse files Browse the repository at this point in the history
plus #2625
  • Loading branch information
hugomrdias committed Dec 11, 2019
1 parent b1a8620 commit 2e57c35
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 213 deletions.
6 changes: 2 additions & 4 deletions .aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ const IPFSFactory = require('ipfsd-ctl')
const MockPreloadNode = require('./test/utils/mock-preload-node')
const EchoServer = require('interface-ipfs-core/src/utils/echo-http-server')

const promisify = require('promisify-es6')

const ipfsdServer = IPFSFactory.createServer()
const preloadNode = promisify(MockPreloadNode.createNode())
const echoServer = promisify(EchoServer.createServer())
const preloadNode = MockPreloadNode.createNode()
const echoServer = EchoServer.createServer()

module.exports = {
bundlesize: { maxSize: '652kB' },
Expand Down
31 changes: 5 additions & 26 deletions test/cli/dht.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,12 @@
'use strict'

const { expect } = require('interface-ipfs-core/src/utils/mocha')
const path = require('path')
const DaemonFactory = require('ipfsd-ctl')
const df = DaemonFactory.create({
type: 'js',
IpfsClient: require('ipfs-http-client')
})

const factory = require('../utils/factory')
const ipfsExec = require('../utils/ipfs-exec')

const daemonOpts = {
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
config: {
Bootstrap: [],
Discovery: {
MDNS: {
Enabled: false
},
webRTCStar: {
Enabled: false
}
}
},
initOptions: { bits: 512 }
}

// TODO: unskip when DHT is enabled: https://github.com/ipfs/js-ipfs/pull/1994
describe.skip('dht', () => {
const df = factory({ type: 'js' })
const nodes = []
let ipfsA
let ipfsB
Expand All @@ -41,11 +20,11 @@ describe.skip('dht', () => {
before(async function () {
this.timeout(80 * 1000)

const ipfsdA = await df.spawn(daemonOpts)
const ipfsdA = await df.spawn()
ipfsA = ipfsExec(ipfsdA.repoPath)
nodes.push(ipfsdA)

const ipfsdB = await df.spawn(daemonOpts)
const ipfsdB = await df.spawn()
ipfsB = ipfsExec(ipfsdB.repoPath)
nodes.push(ipfsdB)
})
Expand All @@ -71,7 +50,7 @@ describe.skip('dht', () => {
return nodes[0].api.swarm.connect(multiaddrB)
})

after(() => Promise.all(nodes.map((node) => node.stop())))
after(() => df.clean())

it('should be able to put a value to the dht and get it afterwards', async function () {
this.timeout(60 * 1000)
Expand Down
48 changes: 10 additions & 38 deletions test/cli/name-pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,13 @@
'use strict'

const { expect } = require('interface-ipfs-core/src/utils/mocha')
const factory = require('../utils/factory')
const path = require('path')
const ipfsExec = require('../utils/ipfs-exec')

const DaemonFactory = require('ipfsd-ctl')
const df = DaemonFactory.create({
type: 'js',
IpfsClient: require('ipfs-http-client')
})

const spawnDaemon = () => df.spawn({
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
args: ['--enable-namesys-pubsub'],
initOptions: { bits: 512 },
config: {
Bootstrap: [],
Discovery: {
MDNS: {
Enabled: false
},
webRTCStar: {
Enabled: false
}
}
}
})

describe('name-pubsub', () => {
describe('enabled', () => {
const df = factory({ type: 'js', args: ['--enable-namesys-pubsub'] })
let ipfsA
let ipfsB
let nodeAId
Expand All @@ -44,12 +23,12 @@ describe('name-pubsub', () => {
// timeout for the before step
this.timeout(80 * 1000)

const nodeA = await spawnDaemon()
ipfsA = ipfsExec(nodeA.repoPath)
const nodeA = await df.spawn()
ipfsA = ipfsExec(nodeA.path)
nodes.push(nodeA)

const nodeB = await spawnDaemon()
ipfsB = ipfsExec(nodeB.repoPath)
const nodeB = await df.spawn()
ipfsB = ipfsExec(nodeB.path)
nodes.push(nodeB)
})

Expand All @@ -71,7 +50,7 @@ describe('name-pubsub', () => {
expect(out).to.eql(`connect ${bMultiaddr} success\n`)
})

after(() => Promise.all(nodes.map((node) => node.stop())))
after(() => df.clean())

describe('pubsub commands', () => {
it('should get enabled state of pubsub', async function () {
Expand Down Expand Up @@ -114,6 +93,7 @@ describe('name-pubsub', () => {
})

describe('disabled', () => {
const df = factory({ type: 'js' })
let ipfsA
let node

Expand All @@ -123,19 +103,11 @@ describe('name-pubsub', () => {
// timeout for the before step
this.timeout(80 * 1000)

node = await df.spawn({
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
config: {},
initOptions: { bits: 512 }
})
node = await df.spawn()
ipfsA = ipfsExec(node.repoPath)
})

after(() => {
if (node) {
return node.stop()
}
})
after(() => df.clean())

it('should get disabled state of pubsub', async function () {
const res = await ipfsA('name pubsub state')
Expand Down
43 changes: 6 additions & 37 deletions test/cli/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,8 @@
'use strict'

const { expect } = require('interface-ipfs-core/src/utils/mocha')
const DaemonFactory = require('ipfsd-ctl')
const factory = require('../utils/factory')
const ipfsExec = require('../utils/ipfs-exec')
const path = require('path')
const df = DaemonFactory.create({
type: 'js',
IpfsClient: require('ipfs-http-client')
})

const config = {
Bootstrap: [],
Discovery: {
MDNS: {
Enabled:
false
}
}
}

describe('ping', function () {
this.timeout(60 * 1000)
Expand All @@ -28,15 +13,12 @@ describe('ping', function () {
let bMultiaddr
let ipfsdBId
let cli
const df = factory({ type: 'js' })

before(async function () {
this.timeout(60 * 1000)

ipfsdB = await df.spawn({
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
config,
initOptions: { bits: 512 }
})
ipfsdB = await df.spawn()
const peerInfo = await ipfsdB.api.id()
ipfsdBId = peerInfo.id
bMultiaddr = peerInfo.addresses[0]
Expand All @@ -45,30 +27,17 @@ describe('ping', function () {
before(async function () {
this.timeout(60 * 1000)

ipfsdA = await df.spawn({
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
config,
initOptions: { bits: 512 }
})
ipfsdA = await df.spawn()
// Without DHT we need to have an already established connection
await ipfsdA.api.swarm.connect(bMultiaddr)
})

before(() => {
this.timeout(60 * 1000)
cli = ipfsExec(ipfsdA.repoPath)
cli = ipfsExec(ipfsdA.path)
})

after(() => {
if (ipfsdA) {
return ipfsdA.stop()
}
})
after(() => {
if (ipfsdB) {
return ipfsdB.stop()
}
})
after(() => df.clean())

it('ping host', async () => {
this.timeout(60 * 1000)
Expand Down
38 changes: 5 additions & 33 deletions test/cli/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,11 @@ const { expect } = require('interface-ipfs-core/src/utils/mocha')
const delay = require('delay')
const series = require('async/series')
const ipfsExec = require('../utils/ipfs-exec')
const IPFS = require('../../src')
const path = require('path')
const DaemonFactory = require('ipfsd-ctl')

const config = {
Bootstrap: [],
Discovery: {
MDNS: {
Enabled:
false
}
}
}
const factory = require('../utils/factory')

describe('pubsub', function () {
this.timeout(80 * 1000)

const df = factory()
let node
let ipfsdA
let ipfsdB
Expand All @@ -36,15 +24,7 @@ describe('pubsub', function () {
before(async function () {
this.timeout(60 * 1000)

const df = DaemonFactory.create({
type: 'proc',
IpfsClient: require('ipfs-http-client')
})
ipfsdA = await df.spawn({
exec: IPFS,
initOptions: { bits: 512 },
config
})
ipfsdA = await df.spawn({ type: 'proc' })
node = ipfsdA.api
})

Expand All @@ -55,17 +35,9 @@ describe('pubsub', function () {
})

before(async () => {
const df = DaemonFactory.create({
type: 'js',
IpfsClient: require('ipfs-http-client')
})
ipfsdB = await df.spawn({
initOptions: { bits: 512 },
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
config
})
ipfsdB = await df.spawn({ type: 'js' })
httpApi = ipfsdB.api
httpApi.repoPath = ipfsdB.repoPath
httpApi.repoPath = ipfsdB.path
})

after(() => {
Expand Down
42 changes: 8 additions & 34 deletions test/cli/swarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,15 @@

const { expect } = require('interface-ipfs-core/src/utils/mocha')
const sinon = require('sinon')
const ipfsExec = require('../utils/ipfs-exec')
const path = require('path')
const addrsCommand = require('../../src/cli/commands/swarm/addrs')

const multiaddr = require('multiaddr')
const PeerInfo = require('peer-info')
const ipfsExec = require('../utils/ipfs-exec')
const PeerId = require('peer-id')

const DaemonFactory = require('ipfsd-ctl')
const df = DaemonFactory.create({
type: 'js',
IpfsClient: require('ipfs-http-client')
})

const config = {
Bootstrap: [],
Discovery: {
MDNS: {
Enabled:
false
}
}
}
const addrsCommand = require('../../src/cli/commands/swarm/addrs')
const factory = require('../utils/factory')

describe('swarm', () => {
const df = factory({ type: 'js' })
afterEach(() => {
sinon.restore()
})
Expand All @@ -39,31 +23,21 @@ describe('swarm', () => {
let bMultiaddr
let ipfsA

const nodes = []
before(async function () {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(80 * 1000)

const res = await Promise.all([
df.spawn({
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
config,
initOptions: { bits: 512 }
}),
df.spawn({
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
config,
initOptions: { bits: 512 }
})
df.spawn(),
df.spawn()
])
ipfsA = ipfsExec(res[0].repoPath)
ipfsA = ipfsExec(res[0].path)
const id = await res[1].api.id()
bMultiaddr = id.addresses[0]
nodes.push(...res)
})

after(() => Promise.all(nodes.map((node) => node.stop())))
after(() => df.clean())

it('connect', async () => {
const out = await ipfsA(`swarm connect ${bMultiaddr}`)
Expand Down
Loading

0 comments on commit 2e57c35

Please sign in to comment.