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

Commit

Permalink
Merge pull request #100 from ipfs/tests/refactor
Browse files Browse the repository at this point in the history
just a bit of cleanup
  • Loading branch information
daviddias committed Mar 29, 2016
2 parents cd6797d + 4b9e954 commit 2289ac9
Show file tree
Hide file tree
Showing 85 changed files with 66 additions and 58 deletions.
4 changes: 2 additions & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ module.exports = function (config) {

files: [
nodeForgePath,
'tests/test-core/browser.js'
'test/core-tests/browser.js'
],

preprocessors: {
'tests/test-core/*': ['webpack']
'test/core-tests/*': ['webpack']
},

webpack: {
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
"main": "src/core/index.js",
"scripts": {
"lint": "standard --verbose | snazzy",
"coverage": "istanbul cover --print both -- _mocha tests/test-core/index.js",
"coverage:http-api": "istanbul cover --print both -- _mocha tests/test-http-api/index.js",
"coverage": "istanbul cover --print both -- _mocha test/core-tests/index.js",
"coverage:http-api": "istanbul cover --print both -- _mocha test/http-api-tests/index.js",
"test": "npm run test:node && npm run test:browser",
"test:node": "npm run test:node:core && npm run test:node:http-api && npm run test:node:cli",
"test:node:teamcity": "npm run test:node:core:teamcity && npm run test:node:http-api:teamcity && npm run test:node:cli:teamcity",
"test:node:cli:teamcity": "mocha --reporter mocha-teamcity-reporter tests/test-cli/index.js",
"test:node:core:teamcity": "mocha --reporter mocha-teamcity-reporter tests/test-core/index.js",
"test:node:http-api:teamcity": "mocha --reporter mocha-teamcity-reporter tests/test-http-api/index.js",
"test:node:cli": "mocha tests/test-cli/index.js",
"test:node:core": "mocha tests/test-core/index.js",
"test:node:http-api": "mocha tests/test-http-api/index.js",
"test:node:cli:teamcity": "mocha --reporter mocha-teamcity-reporter test/cli-tests/index.js",
"test:node:core:teamcity": "mocha --reporter mocha-teamcity-reporter test/core-tests/index.js",
"test:node:http-api:teamcity": "mocha --reporter mocha-teamcity-reporter test/http-api-tests/index.js",
"test:node:cli": "mocha test/cli-tests/index.js",
"test:node:core": "mocha test/core-tests/index.js",
"test:node:http-api": "mocha test/http-api-tests/index.js",
"test:browser": "karma start karma.conf.js",
"test:browser:teamcity": "karma start --reporters teamcity --colors false karma.conf.js",
"test:core": "mocha tests/test-core/index.js",
"test:cli": "mocha tests/test-cli/index.js"
"test:core": "mocha test/core-tests/index.js",
"test:cli": "mocha test/cli-tests/index.js"
},
"pre-commit": [
"lint",
Expand Down
4 changes: 2 additions & 2 deletions src/core/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = (repo, opts, callback) => {
opts.bits = opts.bits || 2048

// Pre-set config values.
var config = require('../../default-config.json')
var config = require('../init-files/default-config.json')

// Verify repo does not yet exist (or that 'force' is provided).
repo.exists((err, res) => {
Expand Down Expand Up @@ -65,7 +65,7 @@ module.exports = (repo, opts, callback) => {
const blocks = new IpfsBlocks(repo)
const dag = new IpfsDagService(blocks)

const initDocsPath = path.join(__dirname, '../../init-doc')
const initDocsPath = path.join(__dirname, '../init-files/init-docs')

importer.import(initDocsPath, dag, {
recursive: true
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions tests/test-cli/index.js → test/cli-tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const rimraf = require('rimraf')
const expect = require('chai').expect

describe('cli', () => {
const repoExample = process.cwd() + '/tests/repo-example'
const repoTests = exports.repoTests = process.cwd() + '/tests/repo-tests-run'
const repoExample = process.cwd() + '/test/go-ipfs-repo'
const repoTests = exports.repoTests = process.cwd() + '/test/repo-tests-run'

before((done) => {
ncp(repoExample, repoTests, (err) => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions tests/test-cli/test-object.js → test/cli-tests/test-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('object', () => {
})

it('put', (done) => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'object', 'put', process.cwd() + '/tests/node.json'])
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'object', 'put', process.cwd() + '/test/test-data/node.json'])
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
expect(exitcode).to.equal(0)
Expand Down Expand Up @@ -81,7 +81,7 @@ describe('object', () => {

describe('patch', () => {
it('append-data', (done) => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'object', 'patch', 'append-data', 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n', process.cwd() + '/tests/badconfig'])
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'object', 'patch', 'append-data', 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n', process.cwd() + '/test/test-data/badconfig'])
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
expect(exitcode).to.equal(0)
Expand All @@ -92,7 +92,7 @@ describe('object', () => {
})

it('set-data', (done) => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'object', 'patch', 'set-data', 'QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6', process.cwd() + '/tests/badconfig'])
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'object', 'patch', 'set-data', 'QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6', process.cwd() + '/test/test-data/badconfig'])
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
expect(exitcode).to.equal(0)
Expand Down Expand Up @@ -167,7 +167,7 @@ describe('object', () => {
})

it('put', (done) => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'object', 'put', process.cwd() + '/tests/node.json'])
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'object', 'put', process.cwd() + '/test/test-data/node.json'])
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
expect(exitcode).to.equal(0)
Expand Down Expand Up @@ -216,7 +216,7 @@ describe('object', () => {

describe('patch', () => {
it('append-data', (done) => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'object', 'patch', 'append-data', 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n', process.cwd() + '/tests/badconfig'])
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'object', 'patch', 'append-data', 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n', process.cwd() + '/test/test-data/badconfig'])
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
expect(exitcode).to.equal(0)
Expand All @@ -227,7 +227,7 @@ describe('object', () => {
})

it('set-data', (done) => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'object', 'patch', 'set-data', 'QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6', process.cwd() + '/tests/badconfig'])
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'object', 'patch', 'set-data', 'QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6', process.cwd() + '/test/test-data/badconfig'])
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
expect(exitcode).to.equal(0)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/test-core/browser.js → test/core-tests/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const async = require('async')
const store = require('idb-plus-blob-store')
const _ = require('lodash')

const repoContext = require.context('buffer!./../repo-example', true)
const repoContext = require.context('buffer!./../go-ipfs-repo', true)

const idb = window.indexedDB ||
window.mozIndexedDB ||
Expand Down
4 changes: 2 additions & 2 deletions tests/test-core/index.js → test/core-tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const rimraf = require('rimraf')
const expect = require('chai').expect

describe('core', () => {
const repoExample = process.cwd() + '/tests/repo-example'
const repoTests = process.cwd() + '/tests/repo-tests-run'
const repoExample = process.cwd() + '/test/go-ipfs-repo'
const repoTests = process.cwd() + '/test/repo-tests-run'

before((done) => {
ncp(repoExample, repoTests, (err) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const Block = require('ipfs-blocks').Block
const isNode = !global.window

const fileA = isNode
? fs.readFileSync(process.cwd() + '/tests/repo-example/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data')
: require('buffer!./../repo-example/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data')
? fs.readFileSync(process.cwd() + '/test/go-ipfs-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data')
: require('buffer!./../go-ipfs-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data')

// TODO use arrow funtions again when https://github.com/webpack/webpack/issues/1944 is fixed
describe('block', function () {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,25 @@

const expect = require('chai').expect
const IPFS = require('../../src/core')
const createTempRepo = require('../temp-repo')
const createTempRepo = require('../utils/temp-repo')

describe('node: init', function () {
describe('init (Node.js specific)', function () {
this.timeout(10000)

it('init docs written', (done) => {
var repo = createTempRepo()
const ipfs = new IPFS(repo)
var ipfs
var repo

beforeEach((done) => {
repo = createTempRepo()
ipfs = new IPFS(repo)
done()
})

afterEach((done) => {
repo.teardown(done)
})

it('init docs are written', (done) => {
ipfs.init({ bits: 64 }, (err) => {
expect(err).to.not.exist

Expand All @@ -18,23 +29,20 @@ describe('node: init', function () {
ipfs.object.get(multihash, {}, (err, node) => {
expect(err).to.not.exist
expect(node.links).to.exist

repo.teardown(done)
done()
})
})
})

it('empty repo', (done) => {
var repo = createTempRepo()
const ipfs = new IPFS(repo)
ipfs.init({ bits: 64, emptyRepo: true }, (err) => {
expect(err).to.not.exist

// Check for default assets
var multihash = new Buffer('12205e7c3ce237f936c76faf625e90f7751a9f5eeb048f59873303c215e9cce87599', 'hex')
ipfs.object.get(multihash, {}, (err, node) => {
expect(err).to.exist
repo.teardown(done)
done()
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const expect = require('chai').expect
const IPFS = require('../../src/core')
const createTempRepo = require('../temp-repo')
const createTempRepo = require('../utils/temp-repo')

describe('init', function () {
this.timeout(10000)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions tests/test-http-api/index.js → test/http-api-tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const ncp = require('ncp').ncp
const rimraf = require('rimraf')

describe('http api', () => {
const repoExample = process.cwd() + '/tests/repo-example'
const repoTests = process.cwd() + '/tests/repo-tests-run'
const repoExample = process.cwd() + '/test/go-ipfs-repo'
const repoTests = process.cwd() + '/test/repo-tests-run'
process.env.IPFS_PATH = repoTests

before((done) => {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const FormData = require('form-data')
const streamToPromise = require('stream-to-promise')

describe('config', () => {
const configPath = process.cwd() + '/tests/repo-tests-run/config'
const originalConfigPath = process.cwd() + '/tests/repo-example/config'
const configPath = process.cwd() + '/test/repo-tests-run/config'
const originalConfigPath = process.cwd() + '/test/go-ipfs-repo/config'
const updatedConfig = () => JSON.parse(fs.readFileSync(configPath, 'utf8'))
const restoreConfig = () => fs.writeFileSync(configPath, fs.readFileSync(originalConfigPath, 'utf8'), 'utf8')

Expand Down Expand Up @@ -169,7 +169,7 @@ describe('config', () => {

it('returns 500 if the config is invalid', (done) => {
const form = new FormData()
const filePath = 'tests/badconfig'
const filePath = 'test/test-data/badconfig'
form.append('file', fs.createReadStream(filePath))
const headers = form.getHeaders()

Expand All @@ -188,7 +188,7 @@ describe('config', () => {

it('updates value', (done) => {
const form = new FormData()
const filePath = 'tests/otherconfig'
const filePath = 'test/test-data/otherconfig'
form.append('file', fs.createReadStream(filePath))
const headers = form.getHeaders()
const expectedConfig = JSON.parse(fs.readFileSync(filePath, 'utf8'))
Expand Down Expand Up @@ -311,7 +311,7 @@ describe('config', () => {

describe('ipfs.config.replace', () => {
it('returns error if the config is invalid', (done) => {
const filePath = 'tests/badconfig'
const filePath = 'test/test-data/badconfig'

ctl.config.replace(filePath, (err) => {
expect(err).to.exist
Expand All @@ -320,7 +320,7 @@ describe('config', () => {
})

it('updates value', (done) => {
const filePath = 'tests/otherconfig'
const filePath = 'test/test-data/otherconfig'
const expectedConfig = JSON.parse(fs.readFileSync(filePath, 'utf8'))

ctl.config.replace(filePath, (err) => {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('object', () => {

it('returns 500 if the node is invalid', (done) => {
const form = new FormData()
const filePath = 'tests/badnode.json'
const filePath = 'test/test-data/badnode.json'
form.append('file', fs.createReadStream(filePath))
const headers = form.getHeaders()

Expand All @@ -121,7 +121,7 @@ describe('object', () => {

it('updates value', (done) => {
const form = new FormData()
const filePath = 'tests/node.json'
const filePath = 'test/test-data/node.json'
form.append('data', fs.createReadStream(filePath))
const headers = form.getHeaders()
const expectedResult = {
Expand Down Expand Up @@ -298,7 +298,7 @@ describe('object', () => {

it('returns 500 for request with invalid key', (done) => {
const form = new FormData()
const filePath = 'tests/badconfig'
const filePath = 'test/test-data/badconfig'
form.append('file', fs.createReadStream(filePath))
const headers = form.getHeaders()

Expand All @@ -317,7 +317,7 @@ describe('object', () => {

it('updates value', (done) => {
const form = new FormData()
const filePath = 'tests/badconfig'
const filePath = 'test/test-data/badconfig'
form.append('data', fs.createReadStream(filePath))
const headers = form.getHeaders()
const expectedResult = {
Expand Down Expand Up @@ -371,7 +371,7 @@ describe('object', () => {

it('returns 500 for request with invalid key', (done) => {
const form = new FormData()
const filePath = 'tests/badconfig'
const filePath = 'test/test-data/badconfig'
form.append('file', fs.createReadStream(filePath))
const headers = form.getHeaders()

Expand All @@ -390,7 +390,7 @@ describe('object', () => {

it('updates value', (done) => {
const form = new FormData()
const filePath = 'tests/badconfig'
const filePath = 'test/test-data/badconfig'
form.append('data', fs.createReadStream(filePath))
const headers = form.getHeaders()
const expectedResult = {
Expand Down Expand Up @@ -585,7 +585,7 @@ describe('object', () => {

describe('ipfs.object.put', () => {
it('returns error if the node is invalid', (done) => {
const filePath = 'tests/badnode.json'
const filePath = 'test/test-data/badnode.json'

ctl.object.put(filePath, 'json', (err) => {
expect(err).to.exist
Expand All @@ -594,7 +594,7 @@ describe('object', () => {
})

it('updates value', (done) => {
const filePath = 'tests/node.json'
const filePath = 'test/test-data/node.json'
const expectedResult = {
Hash: 'QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm',
Links: [{
Expand Down Expand Up @@ -713,7 +713,7 @@ describe('object', () => {
})

it('returns error for request without data', (done) => {
const filePath = 'tests/badnode.json'
const filePath = 'test/test-data/badnode.json'

ctl.object.patch.appendData(null, filePath, (err) => {
expect(err).to.exist
Expand All @@ -723,7 +723,7 @@ describe('object', () => {

it('updates value', (done) => {
const key = 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n'
const filePath = 'tests/badnode.json'
const filePath = 'test/test-data/badnode.json'
const expectedResult = {
Hash: 'QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6',
Links: []
Expand Down Expand Up @@ -755,7 +755,7 @@ describe('object', () => {
})

it('returns error for request without data', (done) => {
const filePath = 'tests/badnode.json'
const filePath = 'test/test-data/badnode.json'

ctl.object.patch.setData(null, filePath, (err) => {
expect(err).to.exist
Expand All @@ -765,7 +765,7 @@ describe('object', () => {

it('updates value', (done) => {
const key = 'QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6'
const filePath = 'tests/badnode.json'
const filePath = 'test/test-data/badnode.json'
const expectedResult = {
Hash: 'QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6',
Links: []
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 2289ac9

Please sign in to comment.