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

Commit

Permalink
no gateway tests using harcoded ports
Browse files Browse the repository at this point in the history
  • Loading branch information
victorb committed Feb 20, 2018
1 parent 8ed04bb commit 51ef64b
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 16 deletions.
5 changes: 5 additions & 0 deletions test/gateway/index.js
Expand Up @@ -33,6 +33,11 @@ describe('HTTP Gateway', function () {
const repoPath = path.join(os.tmpdir(), '/ipfs-' + hat())

http.api = new API(repoPath, {
Addresses: {
Swarm: ['/ip4/127.0.0.1/tcp/0'],
API: '/ip4/127.0.0.1/tcp/0',
Gateway: '/ip4/127.0.0.1/tcp/0'
},
Bootstrap: [],
Discovery: {
MDNS: {
Expand Down
7 changes: 6 additions & 1 deletion test/http-api/extra/block.js
Expand Up @@ -8,8 +8,13 @@ chai.use(dirtyChai)

const multihash = require('multihashes')
const waterfall = require('async/waterfall')
const getCtl = require('./utils/get-ctl.js')

module.exports = (ctl) => {
module.exports = (http) => {
let ctl = null
before(() => {
ctl = getCtl(http)
})
describe('.block', () => {
describe('.put', () => {
it('updates value', (done) => {
Expand Down
7 changes: 6 additions & 1 deletion test/http-api/extra/bootstrap.js
Expand Up @@ -5,8 +5,13 @@ const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const getCtl = require('./utils/get-ctl.js')

module.exports = (ctl) => {
module.exports = (http) => {
let ctl = null
before(() => {
ctl = getCtl(http)
})
describe('.bootstrap', () => {
const invalidArg = 'this/Is/So/Invalid/'
const validIp4 = '/ip4/101.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z'
Expand Down
7 changes: 6 additions & 1 deletion test/http-api/extra/config.js
Expand Up @@ -8,8 +8,13 @@ chai.use(dirtyChai)

const fs = require('fs')
const path = require('path')
const getCtl = require('./utils/get-ctl.js')

module.exports = (ctl) => {
module.exports = (http) => {
let ctl = null
before(() => {
ctl = getCtl(http)
})
describe('.config', () => {
const configPath = path.join(__dirname, '../../repo-tests-run/config')

Expand Down
7 changes: 6 additions & 1 deletion test/http-api/extra/dns.js
Expand Up @@ -5,8 +5,13 @@ const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const getCtl = require('./utils/get-ctl.js')

module.exports = (ctl) => {
module.exports = (http) => {
let ctl = null
before(() => {
ctl = getCtl(http)
})
describe('.dns', () => {
it('resolve ipfs.io dns', (done) => {
ctl.dns('ipfs.io', (err, result) => {
Expand Down
7 changes: 6 additions & 1 deletion test/http-api/extra/id.js
Expand Up @@ -5,8 +5,13 @@ const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const getCtl = require('./utils/get-ctl.js')

module.exports = (ctl) => {
module.exports = (http) => {
let ctl = null
before(() => {
ctl = getCtl(http)
})
describe('.id', () => {
it('get the identity', (done) => {
ctl.id((err, result) => {
Expand Down
7 changes: 6 additions & 1 deletion test/http-api/extra/object.js
Expand Up @@ -10,6 +10,7 @@ chai.use(dirtyChai)
const fs = require('fs')
const dagPB = require('ipld-dag-pb')
const DAGLink = dagPB.DAGLink
const getCtl = require('./utils/get-ctl.js')

function asJson (cb) {
return (err, result) => {
Expand All @@ -19,7 +20,11 @@ function asJson (cb) {
}
}

module.exports = (ctl) => {
module.exports = (http) => {
let ctl = null
before(() => {
ctl = getCtl(http)
})
describe('.object', () => {
it('.new', (done) => {
ctl.object.new(asJson((err, res) => {
Expand Down
5 changes: 5 additions & 0 deletions test/http-api/extra/utils/get-ctl.js
@@ -0,0 +1,5 @@
'use strict'
const APIctl = require('ipfs-api')
module.exports = (http) => {
return APIctl(http.api.apiMultiaddr)
}
7 changes: 6 additions & 1 deletion test/http-api/extra/version.js
Expand Up @@ -5,8 +5,13 @@ const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const getCtl = require('./utils/get-ctl.js')

module.exports = (ctl) => {
module.exports = (http) => {
let ctl = null
before(() => {
ctl = getCtl(http)
})
describe('.version', () => {
it('get the version', (done) => {
ctl.version((err, result) => {
Expand Down
37 changes: 28 additions & 9 deletions test/http-api/index.js
Expand Up @@ -8,7 +8,6 @@ const expect = chai.expect
chai.use(dirtyChai)
const hat = require('hat')
const API = require('../../src/http')
const APIctl = require('ipfs-api')
const ncp = require('ncp').ncp
const path = require('path')
const clean = require('../utils/clean')
Expand All @@ -19,19 +18,35 @@ describe('HTTP API', () => {

let http = {}

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

const startHttpAPI = (cb) => {
const options = {
pass: hat(),
enablePubsubExperiment: true
}
http.api = new API(repoTests, null, options)

ncp(repoExample, repoTests, (err) => {
expect(err).to.not.exist()
if (err) {
return cb(err)
}

http.api.start(false, (err) => {
if (err) {
return cb(err)
}
cb(null, http)
})
})
}

http.api.start(false, done)
before(function (done) {
this.timeout(60 * 1000)
startHttpAPI((err, _http) => {
if (err) {
throw err
}
http = _http
done()
})
})

Expand All @@ -52,9 +67,13 @@ describe('HTTP API', () => {
})

describe('## extra tests with ipfs-api', () => {
const ctl = APIctl('/ip4/127.0.0.1/tcp/6001')

fs.readdirSync(path.join(__dirname, '/extra'))
.forEach((file) => require('./extra/' + file)(ctl))
.forEach((file) => {
// todo(victor) want to make all this loading of tests proper, but for now
if (file.includes('utils')) {
return
}
require('./extra/' + file)(http)
})
})
})

0 comments on commit 51ef64b

Please sign in to comment.