Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
feat(swarm): tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Aug 17, 2016
1 parent f62f648 commit 5c145c6
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 22 deletions.
45 changes: 25 additions & 20 deletions API/swarm/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
swarm API
Swarm API
=========

#### `addrs`

> List of known addresses (from the peer).
> List of known addresses of each peer connected.
##### `Go` **WIP**

Expand Down Expand Up @@ -61,9 +61,31 @@ Example:
ipfs.swarm.disconnect(addr, function (err) {})
```

#### `peers`

> List out the peers that we have connections with.
##### `Go` **WIP**

##### `JavaScript` - ipfs.swarm.peers([callback])

`callback` must follow `function (err, peerInfos) {}` signature, where `err` is an error if the operation was not successful. `peerInfos` will be an array of [PeerInfo]().

If no `callback` is passed, a promise is returned.

Example:

```JavaScript
ipfs.swarm.peers(function (err, peerInfos) {})
```

------------------------------

> NOT IMPLEMENTED YET
#### `filters`

> Display current multiaddr filters
> Display current multiaddr filters. Filters are a way to set up rules for the network connections established.
##### `Go` **WIP**

Expand Down Expand Up @@ -119,21 +141,4 @@ Example:
ipfs.swarm.filters.rm(filter, function (err) {})
```

#### `peers`

> List out the peers that we have connections with.
##### `Go` **WIP**

##### `JavaScript` - ipfs.swarm.peers([callback])

`callback` must follow `function (err, peerInfos) {}` signature, where `err` is an error if the operation was not successful. `peerInfos` will be an array of [PeerInfo]().

If no `callback` is passed, a promise is returned.

Example:

```JavaScript
ipfs.swarm.peers(function (err, peerInfos) {})
```

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"concat-stream": "^1.5.1",
"detect-node": "^2.0.3",
"ipfs-merkle-dag": "^0.6.2",
"readable-stream": "1.1.13"
"readable-stream": "1.1.13",
"run-series": "^1.1.4"
},
"devDependencies": {
"aegir": "^6.0.0"
Expand All @@ -47,4 +48,4 @@
"greenkeeperio-bot <support@greenkeeper.io>",
"nginnever <ginneversource@gmail.com>"
]
}
}
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ exports.files = require('./files')
exports.config = require('./config')
exports.pin = require('./pin')
exports.generic = require('./generic')
exports.swarm = require('./swarm')
123 changes: 123 additions & 0 deletions src/swarm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 8] */

'use strict'

const expect = require('chai').expect
const series = require('run-series')

module.exports = (common) => {
describe('.swarm', () => {
let ipfsA
let ipfsB

before(function (done) {
// CI takes longer to instantiate the daemon,
// so we need to increase the timeout for the
// before step
this.timeout(20 * 1000)

common.setup((err, factory) => {
expect(err).to.not.exist
series([
(cb) => {
factory.spawnNode((err, node) => {
expect(err).to.not.exist
ipfsA = node
cb()
})
},
(cb) => {
factory.spawnNode((err, node) => {
expect(err).to.not.exist
ipfsB = node
cb()
})
}
], done)
})
})

after((done) => {
common.teardown(done)
})

describe('callback API', () => {
it('.connect', (done) => {
ipfsB.id((err, id) => {
expect(err).to.not.exist
const ipfsBAddr = id.addresses[0]
ipfsA.swarm.connect(ipfsBAddr, done)
})
})

it('.peers', (done) => {
ipfsA.swarm.peers((err, multiaddrs) => {
expect(err).to.not.exist
expect(multiaddrs).to.have.length.above(0)
done()
})
})

it('.addrs', (done) => {
ipfsA.swarm.addrs((err, multiaddrs) => {
expect(err).to.not.exist
expect(multiaddrs).to.have.length.above(0)
done()
})
})

it('.localAddrs', (done) => {
ipfsA.swarm.localAddrs((err, multiaddrs) => {
expect(err).to.not.exist
expect(multiaddrs).to.have.length.above(0)
done()
})
})

it('.disconnect', (done) => {
ipfsB.id((err, id) => {
expect(err).to.not.exist
const ipfsBAddr = id.addresses[0]
ipfsA.swarm.disconnect(ipfsBAddr, done)
})
})
})

describe('promise API', () => {
it('.connect', () => {
return ipfsB.id()
.then((id) => {
const ipfsBAddr = id.addresses[0]
return ipfsA.swarm.connect(ipfsBAddr)
})
})

it('.peers', () => {
return ipfsA.swarm.peers().then((multiaddrs) => {
expect(multiaddrs).to.have.length.above(0)
})
})

it('.addrs', () => {
return ipfsA.swarm.addrs().then((multiaddrs) => {
expect(multiaddrs).to.have.length.above(0)
})
})

it('.localAddrs', () => {
return ipfsA.swarm.localAddrs().then((multiaddrs) => {
expect(multiaddrs).to.have.length.above(0)
})
})

it('.disconnect', () => {
return ipfsB.id()
.then((id) => {
const ipfsBAddr = id.addresses[0]
return ipfsA.swarm.disconnect(ipfsBAddr)
})
})
})
})
}

0 comments on commit 5c145c6

Please sign in to comment.