Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test cases #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@
"once": "^1.4.0",
"pump": "^1.0.2",
"qs": "^6.5.1"
}
},
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^6.1.4"
},
"contributors": [
"Tom O'Donnell <[email protected]>",
"Vaibhav Saini <[email protected]>"
]
}
6 changes: 6 additions & 0 deletions test/helpers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const ipfsCluster = require('../../')

// IPFS Cluster node (ipfs-cluster-service) must be running at port 9094 on the same machine
const cluster = ipfsCluster('127.0.0.1', '9094', {protocol: 'http'})

module.exports = cluster
11 changes: 11 additions & 0 deletions test/test.id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const cluster = require('./helpers')
const assert = require('chai').assert

describe('id', () => {
it('shows cluster peer and ipfs daemon information', (done) => {
cluster.id({ protocol: 'http' }, (err, details) => {
assert.notExists(err, 'throws error while fetching cluster peer and ipfs daemon information')
done()
})
})
})
19 changes: 19 additions & 0 deletions test/test.peers.add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const cluster = require('./helpers')
const assert = require('chai').assert

describe('peers.add', () => {

it('throws error while adding a peer with invalid address', (done) => {
cluster.peers.add("invalid address", {}, (err) => {
assert.notDeepEqual(err, null, "adds a peer with invlaid address")
done()
})
})

/* it('adds a cluster peer', (done) => {
cluster.peers.add("/ip4/1.2.3.4/tcp/1234/<peerid>", {}, (err) => {
assert.notExists(err, 'throws error while fetching the list of cluster peers')
done()
})
}) */
})
11 changes: 11 additions & 0 deletions test/test.peers.ls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const cluster = require('./helpers')
const assert = require('chai').assert

describe('peers.ls', () => {
it('lists cluster peers', (done) => {
cluster.peers.ls({ protocol: 'http' }, (err, peers) => {
assert.notExists(err, 'throws error while fetching the list of cluster peers')
done()
})
})
})
24 changes: 24 additions & 0 deletions test/test.peers.rm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const cluster = require('./helpers')
const assert = require('chai').assert

describe('peers.rm', () => {

it('throws error while removing peer with invalid id', (done) => {
cluster.peers.rm("invalidID", {}, (err) => {
assert.notDeepEqual(err, null, "removes peer with invalid id")
done()
})
})

cluster.peers.ls({protocol: 'http'}, (err, peers) => {
assert.equal(err, null, 'throws error while fetching the list of cluster peers')
if (peers.length>=2){
it('removes a cluster peer by id', (done) => {
cluster.peers.rm(peers[1].id, {}, (err) => {
assert.equal(err, null, 'throws error while removing a cluster peer by id')
done()
})
})
}
})
})
13 changes: 13 additions & 0 deletions test/test.pin.add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const cluster = require('./helpers')
const assert = require('chai').assert

const CID = "QmRAQB6YaCyidP37UdDnjFY5vQuiBrcqdyoW1CuDgwxkD4"

describe('pin.add', () => {
it('pins a CID in the cluster', (done) => {
cluster.pin.add(CID, {}, (err) => {
assert.notExists(err, 'throws error while pinning a CID in the cluster')
done()
})
})
})
14 changes: 14 additions & 0 deletions test/test.pin.ls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const cluster = require('./helpers')
const assert = require('chai').assert

const CID = "QmRAQB6YaCyidP37UdDnjFY5vQuiBrcqdyoW1CuDgwxkD4"

describe('pin.ls', () => {

it('list details for a pinned CID', (done) => {
cluster.pin.ls(CID, (err, details) => {
assert.notExists(err, 'throws error while listing details for a pinned CID')
done()
})
})
})
13 changes: 13 additions & 0 deletions test/test.pin.rm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const cluster = require('./helpers')
const assert = require('chai').assert

const CID = "QmRAQB6YaCyidP37UdDnjFY5vQuiBrcqdyoW1CuDgwxkD4"

describe('pin.rm', () => {
it('unpins a CID from the cluster', (done) => {
cluster.pin.rm(CID, {}, (err) => {
assert.notExists(err, 'throws error while unpinning a CID from the cluster')
done()
})
})
})
13 changes: 13 additions & 0 deletions test/test.recover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const cluster = require('./helpers')
const assert = require('chai').assert

const CID = "QmRAQB6YaCyidP37UdDnjFY5vQuiBrcqdyoW1CuDgwxkD4"

describe('recover', () => {
it('attempts to re-pin/unpin CIDs in error state', (done) => {
cluster.recover(CID, {}, (err) => {
assert.notExists(err, 'throws error while attempting to re-pin/unpin CIDs in error state')
done()
})
})
})
13 changes: 13 additions & 0 deletions test/test.status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const cluster = require('./helpers')
const assert = require('chai').assert

const CID = "QmRAQB6YaCyidP37UdDnjFY5vQuiBrcqdyoW1CuDgwxkD4"

describe('status', () => {
it('lists current status of tracked CIDs (local state)', (done) => {
cluster.status(CID, (err, status) => {
assert.notExists(err, 'throws error while listing current status of tracked CIDs')
done()
})
})
})
13 changes: 13 additions & 0 deletions test/test.sync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const cluster = require('./helpers')
const assert = require('chai').assert

const CID = "QmRAQB6YaCyidP37UdDnjFY5vQuiBrcqdyoW1CuDgwxkD4"

describe('sync', () => {
it('re-syncs seen status against status reported by the IPFS daemon', (done) => {
cluster.id(CID, (err) => {
assert.notExists(err, 'throws error while re-syncing seen status against status reported by the IPFS daemon')
done()
})
})
})
12 changes: 12 additions & 0 deletions test/test.version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const cluster = require('./helpers')
const assert = require('chai').assert

describe('version', () => {
it('shows version', (done) => {
cluster.version({}, (err, version) => {
assert.equal(JSON.stringify(version), JSON.stringify({ version: '0.10.1' }), "outputs invalid version")
assert.notExists(err, 'throws error while fetching cluster peer and ipfs daemon information')
done()
})
})
})