diff --git a/.aegir.js b/.aegir.js index e254dd4812..8fe6f90d9d 100644 --- a/.aegir.js +++ b/.aegir.js @@ -3,6 +3,7 @@ const createServer = require('ipfsd-ctl').createServer const server = createServer() + module.exports = { karma: { files: [{ diff --git a/.gitignore b/.gitignore index 7455bdffdb..a68f6491c0 100644 --- a/.gitignore +++ b/.gitignore @@ -34,9 +34,9 @@ node_modules lib dist -test/test-data/go-ipfs-repo/LOCK -test/test-data/go-ipfs-repo/LOG -test/test-data/go-ipfs-repo/LOG.old +test/fixtures/go-ipfs-repo/LOCK +test/fixtures/go-ipfs-repo/LOG +test/fixtures/go-ipfs-repo/LOG.old # while testing npm5 package-lock.json diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile new file mode 100644 index 0000000000..a7da2e54f3 --- /dev/null +++ b/ci/Jenkinsfile @@ -0,0 +1,2 @@ +// Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories. +javascript() diff --git a/test/cli/daemon.js b/test/cli/daemon.js index ae4bf9caf3..3245400320 100644 --- a/test/cli/daemon.js +++ b/test/cli/daemon.js @@ -4,6 +4,7 @@ const expect = require('chai').expect const clean = require('../utils/clean') const ipfsCmd = require('../utils/ipfs-exec') +const isWindows = require('../utils/platforms').isWindows const pull = require('pull-stream') const toPull = require('stream-to-pull-stream') const os = require('os') @@ -11,7 +12,7 @@ const path = require('path') const hat = require('hat') const fs = require('fs') -const isWindows = os.platform() === 'win32' +const skipOnWindows = isWindows() ? it.skip : it const checkLock = (repo, cb) => { // skip on windows @@ -28,9 +29,13 @@ const checkLock = (repo, cb) => { } function testSignal (ipfs, sig) { - let proc = null return ipfs('init').then(() => { - proc = ipfs('daemon') + return ipfs('config', 'Addresses', JSON.stringify({ + API: '/ip4/127.0.0.1/tcp/0', + Gateway: '/ip4/127.0.0.1/tcp/0' + }), '--json') + }).then(() => { + const proc = ipfs('daemon') return new Promise((resolve, reject) => { pull( toPull(proc.stdout), @@ -72,11 +77,12 @@ describe('daemon', () => { afterEach(() => clean(repoPath)) - it('do not crash if Addresses.Swarm is empty', function (done) { + skipOnWindows('do not crash if Addresses.Swarm is empty', function (done) { this.timeout(100 * 1000) ipfs('init').then(() => { return ipfs('config', 'Addresses', JSON.stringify({ + Swarm: [], API: '/ip4/127.0.0.1/tcp/0', Gateway: '/ip4/127.0.0.1/tcp/0' }), '--json') @@ -85,10 +91,10 @@ describe('daemon', () => { }).then((res) => { expect(res).to.have.string('Daemon is ready') done() - }).catch((err) => done(err)) + }).catch(err => done(err)) }) - it('should handle SIGINT gracefully', function (done) { + skipOnWindows('should handle SIGINT gracefully', function (done) { this.timeout(100 * 1000) testSignal(ipfs, 'SIGINT').then(() => { @@ -96,7 +102,7 @@ describe('daemon', () => { }).catch(done) }) - it('should handle SIGTERM gracefully', function (done) { + skipOnWindows('should handle SIGTERM gracefully', function (done) { this.timeout(100 * 1000) testSignal(ipfs, 'SIGTERM').then(() => { diff --git a/test/core/bitswap.spec.js b/test/core/bitswap.spec.js index edf703bc6f..d9c9db978c 100644 --- a/test/core/bitswap.spec.js +++ b/test/core/bitswap.spec.js @@ -17,14 +17,17 @@ const multihashing = require('multihashing-async') const CID = require('cids') const IPFSFactory = require('ipfsd-ctl') -const fDaemon = IPFSFactory.create({ type: 'js' }) -const fInProc = IPFSFactory.create({ type: 'proc' }) // This gets replaced by '../utils/create-repo-browser.js' in the browser const createTempRepo = require('../utils/create-repo-nodejs.js') const IPFS = require('../../src/core') +// TODO bitswap tests on windows is failing, missing proper shutdown of daemon +// https://github.com/ipfs/js-ipfsd-ctl/pull/205 +const isWindows = require('../utils/platforms').isWindows +const skipOnWindows = isWindows() ? describe.skip : describe + function makeBlock (callback) { const d = Buffer.from(`IPFS is awesome ${Math.random()}`) @@ -67,7 +70,7 @@ function connectNodes (remoteNode, inProcNode, callback) { let nodes = [] -function addNode (inProcNode, callback) { +function addNode (fDaemon, inProcNode, callback) { fDaemon.spawn({ exec: './src/cli/bin.js', initOptions: { bits: 512 }, @@ -89,10 +92,17 @@ function addNode (inProcNode, callback) { }) } -describe('bitswap', function () { +skipOnWindows('bitswap', function () { this.timeout(80 * 1000) let inProcNode // Node spawned inside this process + let fDaemon + let fInProc + + before(function () { + fDaemon = IPFSFactory.create({ type: 'js' }) + fInProc = IPFSFactory.create({ type: 'proc' }) + }) beforeEach(function (done) { this.timeout(60 * 1000) @@ -150,7 +160,7 @@ describe('bitswap', function () { waterfall([ (cb) => parallel([ (cb) => makeBlock(cb), - (cb) => addNode(inProcNode, cb) + (cb) => addNode(fDaemon, inProcNode, cb) ], cb), (res, cb) => { block = res[0] @@ -178,11 +188,11 @@ describe('bitswap', function () { blocks = _blocks cb() }), - (cb) => addNode(inProcNode, (err, _ipfs) => { + (cb) => addNode(fDaemon, inProcNode, (err, _ipfs) => { remoteNodes.push(_ipfs) cb(err) }), - (cb) => addNode(inProcNode, (err, _ipfs) => { + (cb) => addNode(fDaemon, inProcNode, (err, _ipfs) => { remoteNodes.push(_ipfs) cb(err) }), @@ -213,14 +223,17 @@ describe('bitswap', function () { }) }) - describe('transfer a file between', () => { + describe('transfer a file between', function () { + this.timeout(160 * 1000) + it('2 peers', (done) => { // TODO make this test more interesting (10Mb file) + // TODO remove randomness from the test const file = Buffer.from(`I love IPFS <3 ${Math.random()}`) waterfall([ // 0. Start node - (cb) => addNode(inProcNode, cb), + (cb) => addNode(fDaemon, inProcNode, cb), // 1. Add file to tmp instance (remote, cb) => { remote.files.add([{ path: 'awesome.txt', content: file }], cb) diff --git a/test/fixtures/go-ipfs-repo/blocks/_README b/test/fixtures/go-ipfs-repo/blocks/_README index 23cb090956..ac3b6034c3 100644 --- a/test/fixtures/go-ipfs-repo/blocks/_README +++ b/test/fixtures/go-ipfs-repo/blocks/_README @@ -6,25 +6,17 @@ All the object files are placed in a tree of directories, based on a function of the CID. This is a form of sharding similar to the objects directory in git repositories. Previously, we used prefixes, we now use the next-to-last two charters. - func NextToLast(base32cid string) { nextToLastLen := 2 offset := len(base32cid) - nextToLastLen - 1 return str[offset : offset+nextToLastLen] } - For example, an object with a base58 CIDv1 of - zb2rhYSxw4ZjuzgCnWSt19Q94ERaeFhu9uSqRgjSdx9bsgM6f - has a base32 CIDv1 of - BAFKREIA22FLID5AJ2KU7URG47MDLROZIH6YF2KALU2PWEFPVI37YLKRSCA - and will be placed at - SC/AFKREIA22FLID5AJ2KU7URG47MDLROZIH6YF2KALU2PWEFPVI37YLKRSCA.data - with 'SC' being the last-to-next two characters and the 'B' at the beginning of the CIDv1 string is the multibase prefix that is not stored in the filename. diff --git a/test/fixtures/go-ipfs-repo/config b/test/fixtures/go-ipfs-repo/config index 7498da51bf..00f467f95f 100644 --- a/test/fixtures/go-ipfs-repo/config +++ b/test/fixtures/go-ipfs-repo/config @@ -1,52 +1,52 @@ -{ - "Identity":{ - "PeerID":"QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A", - "PrivKey":"CAASpgkwggSiAgEAAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAECggEAZtju/bcKvKFPz0mkHiaJcpycy9STKphorpCT83srBVQi59CdFU6Mj+aL/xt0kCPMVigJw8P3/YCEJ9J+rS8BsoWE+xWUEsJvtXoT7vzPHaAtM3ci1HZd302Mz1+GgS8Epdx+7F5p80XAFLDUnELzOzKftvWGZmWfSeDnslwVONkL/1VAzwKy7Ce6hk4SxRE7l2NE2OklSHOzCGU1f78ZzVYKSnS5Ag9YrGjOAmTOXDbKNKN/qIorAQ1bovzGoCwx3iGIatQKFOxyVCyO1PsJYT7JO+kZbhBWRRE+L7l+ppPER9bdLFxs1t5CrKc078h+wuUr05S1P1JjXk68pk3+kQKBgQDeK8AR11373Mzib6uzpjGzgNRMzdYNuExWjxyxAzz53NAR7zrPHvXvfIqjDScLJ4NcRO2TddhXAfZoOPVH5k4PJHKLBPKuXZpWlookCAyENY7+Pd55S8r+a+MusrMagYNljb5WbVTgN8cgdpim9lbbIFlpN6SZaVjLQL3J8TWH6wKBgQDSChzItkqWX11CNstJ9zJyUE20I7LrpyBJNgG1gtvz3ZMUQCn3PxxHtQzN9n1P0mSSYs+jBKPuoSyYLt1wwe10/lpgL4rkKWU3/m1Myt0tveJ9WcqHh6tzcAbb/fXpUFT/o4SWDimWkPkuCb+8j//2yiXk0a/T2f36zKMuZvujqQKBgC6B7BAQDG2H2B/ijofp12ejJU36nL98gAZyqOfpLJ+FeMz4TlBDQ+phIMhnHXA5UkdDapQ+zA3SrFk+6yGk9Vw4Hf46B+82SvOrSbmnMa+PYqKYIvUzR4gg34rL/7AhwnbEyD5hXq4dHwMNsIDq+l2elPjwm/U9V0gdAl2+r50HAoGALtsKqMvhv8HucAMBPrLikhXP/8um8mMKFMrzfqZ+otxfHzlhI0L08Bo3jQrb0Z7ByNY6M8epOmbCKADsbWcVre/AAY0ZkuSZK/CaOXNX/AhMKmKJh8qAOPRY02LIJRBCpfS4czEdnfUhYV/TYiFNnKRj57PPYZdTzUsxa/yVTmECgYBr7slQEjb5Onn5mZnGDh+72BxLNdgwBkhO0OCdpdISqk0F0Pxby22DFOKXZEpiyI9XYP1C8wPiJsShGm2yEwBPWXnrrZNWczaVuCbXHrZkWQogBDG3HGXNdU4MAWCyiYlyinIBpPpoAJZSzpGLmWbMWh28+RJS6AQX6KHrK1o2uw==" +{ + "Identity": { + "PeerID": "QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A", + "PrivKey": "CAASpgkwggSiAgEAAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAECggEAZtju/bcKvKFPz0mkHiaJcpycy9STKphorpCT83srBVQi59CdFU6Mj+aL/xt0kCPMVigJw8P3/YCEJ9J+rS8BsoWE+xWUEsJvtXoT7vzPHaAtM3ci1HZd302Mz1+GgS8Epdx+7F5p80XAFLDUnELzOzKftvWGZmWfSeDnslwVONkL/1VAzwKy7Ce6hk4SxRE7l2NE2OklSHOzCGU1f78ZzVYKSnS5Ag9YrGjOAmTOXDbKNKN/qIorAQ1bovzGoCwx3iGIatQKFOxyVCyO1PsJYT7JO+kZbhBWRRE+L7l+ppPER9bdLFxs1t5CrKc078h+wuUr05S1P1JjXk68pk3+kQKBgQDeK8AR11373Mzib6uzpjGzgNRMzdYNuExWjxyxAzz53NAR7zrPHvXvfIqjDScLJ4NcRO2TddhXAfZoOPVH5k4PJHKLBPKuXZpWlookCAyENY7+Pd55S8r+a+MusrMagYNljb5WbVTgN8cgdpim9lbbIFlpN6SZaVjLQL3J8TWH6wKBgQDSChzItkqWX11CNstJ9zJyUE20I7LrpyBJNgG1gtvz3ZMUQCn3PxxHtQzN9n1P0mSSYs+jBKPuoSyYLt1wwe10/lpgL4rkKWU3/m1Myt0tveJ9WcqHh6tzcAbb/fXpUFT/o4SWDimWkPkuCb+8j//2yiXk0a/T2f36zKMuZvujqQKBgC6B7BAQDG2H2B/ijofp12ejJU36nL98gAZyqOfpLJ+FeMz4TlBDQ+phIMhnHXA5UkdDapQ+zA3SrFk+6yGk9Vw4Hf46B+82SvOrSbmnMa+PYqKYIvUzR4gg34rL/7AhwnbEyD5hXq4dHwMNsIDq+l2elPjwm/U9V0gdAl2+r50HAoGALtsKqMvhv8HucAMBPrLikhXP/8um8mMKFMrzfqZ+otxfHzlhI0L08Bo3jQrb0Z7ByNY6M8epOmbCKADsbWcVre/AAY0ZkuSZK/CaOXNX/AhMKmKJh8qAOPRY02LIJRBCpfS4czEdnfUhYV/TYiFNnKRj57PPYZdTzUsxa/yVTmECgYBr7slQEjb5Onn5mZnGDh+72BxLNdgwBkhO0OCdpdISqk0F0Pxby22DFOKXZEpiyI9XYP1C8wPiJsShGm2yEwBPWXnrrZNWczaVuCbXHrZkWQogBDG3HGXNdU4MAWCyiYlyinIBpPpoAJZSzpGLmWbMWh28+RJS6AQX6KHrK1o2uw==" }, - "Datastore":{ - "Type":"", - "Path":"", - "StorageMax":"", - "StorageGCWatermark":0, - "GCPeriod":"", - "Params":null, - "NoSync":false + "Datastore": { + "Type": "", + "Path": "", + "StorageMax": "", + "StorageGCWatermark": 0, + "GCPeriod": "", + "Params": null, + "NoSync": false }, - "Addresses":{ - "Swarm":[ - "/ip4/127.0.0.1/tcp/9999", - "/ip4/127.0.0.1/tcp/9990/ws" + "Addresses": { + "Swarm": [ + "/ip4/127.0.0.1/tcp/0", + "/ip4/127.0.0.1/tcp/0/ws" ], - "API":"/ip4/127.0.0.1/tcp/6001", - "Gateway":"/ip4/127.0.0.1/tcp/0" + "API": "/ip4/127.0.0.1/tcp/0", + "Gateway": "/ip4/127.0.0.1/tcp/0" }, - "Mounts":{ - "IPFS":"/ipfs", - "IPNS":"/ipns", - "FuseAllowOther":false + "Mounts": { + "IPFS": "/ipfs", + "IPNS": "/ipns", + "FuseAllowOther": false }, - "Version":{ - "Current":"0.4.0-dev", - "Check":"error", - "CheckDate":"0001-01-01T00:00:00Z", - "CheckPeriod":"172800000000000", - "AutoUpdate":"minor" + "Version": { + "Current": "0.4.0-dev", + "Check": "error", + "CheckDate": "0001-01-01T00:00:00Z", + "CheckPeriod": "172800000000000", + "AutoUpdate": "minor" }, - "Discovery":{ - "MDNS":{ - "Enabled":false, - "Interval":10 + "Discovery": { + "MDNS": { + "Enabled": false, + "Interval": 10 }, "webRTCStar": { "Enabled": false } }, - "Ipns":{ - "RepublishPeriod":"", - "RecordLifetime":"", - "ResolveCacheSize":128 + "Ipns": { + "RepublishPeriod": "", + "RecordLifetime": "", + "ResolveCacheSize": 128 }, - "Bootstrap":[ + "Bootstrap": [ "/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z", "/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", "/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM", @@ -67,16 +67,16 @@ "/dns4/wss0.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic", "/dns4/wss1.bootstrap.libp2p.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6" ], - "Tour":{ - "Last":"" + "Tour": { + "Last": "" }, - "Gateway":{ - "HTTPHeaders":null, - "RootRedirect":"", - "Writable":false + "Gateway": { + "HTTPHeaders": null, + "RootRedirect": "", + "Writable": false }, - "SupernodeRouting":{ - "Servers":[ + "SupernodeRouting": { + "Servers": [ "/ip4/104.236.176.52/tcp/4002/ipfs/QmXdb7tWTxdFEQEFgWBqkuYSrZd3mXrC7HxkD4krGNYx2U", "/ip4/104.236.179.241/tcp/4002/ipfs/QmVRqViDByUxjUMoPnjurjKvZhaEMFDtK35FJXHAM4Lkj6", "/ip4/104.236.151.122/tcp/4002/ipfs/QmSZwGx8Tn8tmcM4PtDJaMeUQNRhNFdBLVGPzRiNaRJtFH", @@ -87,15 +87,23 @@ "/ip4/178.62.61.185/tcp/4002/ipfs/QmVw6fGNqBixZE4bewRLT2VXX7fAHUHs8JyidDiJ1P7RUN" ] }, - "API":{ - "HTTPHeaders":null + "API": { + "HTTPHeaders": null }, - "Swarm":{ - "AddrFilters":null + "Swarm": { + "AddrFilters": null }, - "Log":{ - "MaxSizeMB":250, - "MaxBackups":1, - "MaxAgeDays":0 + "Log": { + "MaxSizeMB": 250, + "MaxBackups": 1, + "MaxAgeDays": 0 + }, + "Keychain": { + "dek": { + "keyLength": 64, + "iterationCount": 10000, + "salt": "co5EbMmrhFwmhHjedZU73zhL", + "hash": "sha2-512" + } } -} +} \ No newline at end of file diff --git a/test/fixtures/go-ipfs-repo/datastore/CURRENT b/test/fixtures/go-ipfs-repo/datastore/CURRENT index 23b73d9100..056df57bb7 100644 --- a/test/fixtures/go-ipfs-repo/datastore/CURRENT +++ b/test/fixtures/go-ipfs-repo/datastore/CURRENT @@ -1 +1 @@ -MANIFEST-000014 +MANIFEST-000017 diff --git a/test/fixtures/go-ipfs-repo/datastore/LOG b/test/fixtures/go-ipfs-repo/datastore/LOG index 96e7909dfc..f009994607 100644 --- a/test/fixtures/go-ipfs-repo/datastore/LOG +++ b/test/fixtures/go-ipfs-repo/datastore/LOG @@ -1,29 +1 @@ -=============== Aug 25, 2016 (CEST) =============== -17:21:42.391799 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed -17:21:42.393115 db@open opening -17:21:42.399749 db@janitor F·5 G·1 -17:21:42.399774 db@janitor removing manifest-4 -17:21:42.399904 db@open done T·6.754896ms -=============== Aug 25, 2016 (CEST) =============== -17:36:56.009638 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed -17:36:56.009849 version@stat F·[2] S·1KiB[1KiB] Sc·[0.50] -17:36:56.009874 db@open opening -17:36:56.009943 journal@recovery F·1 -17:36:56.010918 journal@recovery recovering @8 -17:36:56.012317 memdb@flush created L0@10 N·4 S·1KiB "/ip..\xf6\xe4\xa9,d12":"/pk..TOA,v9" -17:36:56.013451 version@stat F·[3] S·2KiB[2KiB] Sc·[0.75] -17:36:56.014779 db@janitor F·5 G·0 -17:36:56.014815 db@open done T·4.928147ms -17:36:56.030081 db@close closing -17:36:56.030223 db@close done T·138.943µs -=============== Aug 25, 2016 (CEST) =============== -17:37:32.735975 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed -17:37:32.736209 version@stat F·[3] S·2KiB[2KiB] Sc·[0.75] -17:37:32.736230 db@open opening -17:37:32.736304 journal@recovery F·1 -17:37:32.737385 journal@recovery recovering @11 -17:37:32.738575 version@stat F·[3] S·2KiB[2KiB] Sc·[0.75] -17:37:32.739466 db@janitor F·5 G·0 -17:37:32.739492 db@open done T·3.248709ms -17:37:51.684973 db@close closing -17:37:51.685242 db@close done T·168.908µs +2018/02/27-08:48:29.247686 7000091b5000 Delete type=3 #15 diff --git a/test/fixtures/go-ipfs-repo/datastore/LOG.old b/test/fixtures/go-ipfs-repo/datastore/LOG.old index 863b68fd57..15709837f7 100644 --- a/test/fixtures/go-ipfs-repo/datastore/LOG.old +++ b/test/fixtures/go-ipfs-repo/datastore/LOG.old @@ -1,10 +1 @@ -=============== Dec 10, 2015 (PST) =============== -07:50:02.056578 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed -07:50:02.057231 db@open opening -07:50:02.057312 journal@recovery F·1 -07:50:02.057514 journal@recovery recovering @3 -07:50:02.058921 mem@flush created L0@5 N·4 S·1KiB "/ip..\xf6\xe4\xa9,v5":"/pk..\xf6\xe4\xa9,v6" -07:50:02.059983 db@janitor F·4 G·0 -07:50:02.060001 db@open done T·2.755926ms -07:50:02.073183 db@close closing -07:50:02.073285 db@close done T·97.522µs +2018/02/26-08:13:54.065997 70000aad6000 Delete type=3 #14 diff --git a/test/fixtures/go-ipfs-repo/datastore/MANIFEST-000014 b/test/fixtures/go-ipfs-repo/datastore/MANIFEST-000017 similarity index 79% rename from test/fixtures/go-ipfs-repo/datastore/MANIFEST-000014 rename to test/fixtures/go-ipfs-repo/datastore/MANIFEST-000017 index bda0ce84e5..fb6bc82f41 100644 Binary files a/test/fixtures/go-ipfs-repo/datastore/MANIFEST-000014 and b/test/fixtures/go-ipfs-repo/datastore/MANIFEST-000017 differ diff --git a/test/gateway/index.js b/test/gateway/index.js index 8b9eb1c3ab..84ce39914a 100644 --- a/test/gateway/index.js +++ b/test/gateway/index.js @@ -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: { diff --git a/test/http-api/extra/block.js b/test/http-api/block.js similarity index 68% rename from test/http-api/extra/block.js rename to test/http-api/block.js index dd66c99836..d0133bbc67 100644 --- a/test/http-api/extra/block.js +++ b/test/http-api/block.js @@ -9,7 +9,26 @@ chai.use(dirtyChai) const multihash = require('multihashes') const waterfall = require('async/waterfall') -module.exports = (ctl) => { +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) + +describe('block endpoint', () => { + let ipfs = null + let ipfsd = null + + before(function (done) { + this.timeout(20 * 1000) + + df.spawn({ initOptions: { bits: 512 } }, (err, _ipfsd) => { + expect(err).to.not.exist() + ipfsd = _ipfsd + ipfs = ipfsd.api + done() + }) + }) + + after((done) => ipfsd.stop(done)) + describe('.block', () => { describe('.put', () => { it('updates value', (done) => { @@ -20,7 +39,7 @@ module.exports = (ctl) => { } waterfall([ - (cb) => ctl.block.put(data, cb), + (cb) => ipfs.block.put(data, cb), (block, cb) => { expect(block.cid.multihash).to.eql( multihash.fromB58String(expectedResult.key) @@ -33,14 +52,14 @@ module.exports = (ctl) => { describe('.get', () => { it('returns error for request with invalid argument', (done) => { - ctl.block.get('invalid', (err, result) => { + ipfs.block.get('invalid', (err, result) => { expect(err).to.exist() done() }) }) it('returns value', (done) => { - ctl.block.get('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp', (err, result) => { + ipfs.block.get('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp', (err, result) => { expect(err).to.not.exist() expect(result.data.toString()) .to.equal('hello world\n') @@ -51,21 +70,21 @@ module.exports = (ctl) => { describe('.stat', () => { it('returns error for request without argument', (done) => { - ctl.block.stat(null, (err, result) => { + ipfs.block.stat(null, (err, result) => { expect(err).to.exist() done() }) }) it('returns error for request with invalid argument', (done) => { - ctl.block.stat('invalid', (err, result) => { + ipfs.block.stat('invalid', (err, result) => { expect(err).to.exist() done() }) }) it('returns value', (done) => { - ctl.block.stat('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp', (err, result) => { + ipfs.block.stat('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp', (err, result) => { expect(err).to.not.exist() expect(result.key) .to.equal('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp') @@ -75,4 +94,4 @@ module.exports = (ctl) => { }) }) }) -} +}) diff --git a/test/http-api/extra/bootstrap.js b/test/http-api/bootstrap.js similarity index 73% rename from test/http-api/extra/bootstrap.js rename to test/http-api/bootstrap.js index 1c6ad4ca60..98a3610609 100644 --- a/test/http-api/extra/bootstrap.js +++ b/test/http-api/bootstrap.js @@ -1,3 +1,4 @@ +/* eslint max-nested-callbacks: ["error", 8] */ /* eslint-env mocha */ 'use strict' @@ -6,7 +7,25 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -module.exports = (ctl) => { +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) + +describe('bootstrap endpoint', () => { + let ipfs = null + let ipfsd = null + before(function (done) { + this.timeout(20 * 1000) + + df.spawn({ initOptions: { bits: 512 } }, (err, _ipfsd) => { + expect(err).to.not.exist() + ipfsd = _ipfsd + ipfs = ipfsd.api + done() + }) + }) + + after((done) => ipfsd.stop(done)) + describe('.bootstrap', () => { const invalidArg = 'this/Is/So/Invalid/' const validIp4 = '/ip4/101.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z' @@ -16,14 +35,14 @@ module.exports = (ctl) => { this.timeout(40 * 1000) it('returns an error when called with an invalid arg', (done) => { - ctl.bootstrap.add(invalidArg, (err) => { + ipfs.bootstrap.add(invalidArg, (err) => { expect(err).to.be.an.instanceof(Error) done() }) }) it('returns a list of containing the bootstrap peer when called with a valid arg (ip4)', (done) => { - ctl.bootstrap.add(validIp4, (err, res) => { + ipfs.bootstrap.add(validIp4, (err, res) => { expect(err).to.not.exist() expect(res).to.be.eql({ Peers: [validIp4] }) done() @@ -31,20 +50,20 @@ module.exports = (ctl) => { }) it('prevents duplicate inserts of bootstrap peers', () => { - return ctl + return ipfs .bootstrap .rm(null, { all: true }) .then((res) => { expect(res.Peers.length).to.equal(0) - return ctl.bootstrap.add(validIp4) + return ipfs.bootstrap.add(validIp4) }) .then(res => { expect(res).to.be.eql({ Peers: [validIp4] }) - return ctl.bootstrap.add(validIp4) + return ipfs.bootstrap.add(validIp4) }) .then((res) => { expect(res).to.be.eql({ Peers: [validIp4] }) - return ctl.bootstrap.list() + return ipfs.bootstrap.list() }) .then((res) => { expect(res).to.exist() @@ -55,7 +74,7 @@ module.exports = (ctl) => { }) it('returns a list of bootstrap peers when called with the default option', (done) => { - ctl.bootstrap.add({ default: true }, (err, res) => { + ipfs.bootstrap.add({ default: true }, (err, res) => { expect(err).to.not.exist() peers = res.Peers expect(peers).to.exist() @@ -67,7 +86,7 @@ module.exports = (ctl) => { describe('.list', () => { it('returns a list of peers', (done) => { - ctl.bootstrap.list((err, res) => { + ipfs.bootstrap.list((err, res) => { expect(err).to.not.exist() peers = res.Peers expect(peers).to.exist() @@ -78,14 +97,14 @@ module.exports = (ctl) => { describe('.rm', () => { it('returns an error when called with an invalid arg', (done) => { - ctl.bootstrap.rm(invalidArg, (err) => { + ipfs.bootstrap.rm(invalidArg, (err) => { expect(err).to.be.an.instanceof(Error) done() }) }) it('returns empty list because no peers removed when called without an arg or options', (done) => { - ctl.bootstrap.rm(null, (err, res) => { + ipfs.bootstrap.rm(null, (err, res) => { expect(err).to.not.exist() peers = res.Peers expect(peers).to.exist() @@ -95,7 +114,7 @@ module.exports = (ctl) => { }) it('returns list containing the peer removed when called with a valid arg (ip4)', (done) => { - ctl.bootstrap.rm(validIp4, (err, res) => { + ipfs.bootstrap.rm(validIp4, (err, res) => { expect(err).to.not.exist() peers = res.Peers @@ -106,7 +125,7 @@ module.exports = (ctl) => { }) it('returns list of all peers removed when all option is passed', (done) => { - ctl.bootstrap.rm(null, { all: true }, (err, res) => { + ipfs.bootstrap.rm(null, { all: true }, (err, res) => { expect(err).to.not.exist() peers = res.Peers expect(peers).to.exist() @@ -115,4 +134,4 @@ module.exports = (ctl) => { }) }) }) -} +}) diff --git a/test/http-api/extra/config.js b/test/http-api/config.js similarity index 51% rename from test/http-api/extra/config.js rename to test/http-api/config.js index 2a8b9081ed..0d14504d1a 100644 --- a/test/http-api/extra/config.js +++ b/test/http-api/config.js @@ -6,28 +6,75 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) +const ncp = require('ncp').ncp +const rimraf = require('rimraf') +const waterfall = require('async/waterfall') + +const isWindows = require('../utils/platforms').isWindows +const skipOnWindows = isWindows() ? describe.skip : describe + const fs = require('fs') const path = require('path') -module.exports = (ctl) => { - describe('.config', () => { - const configPath = path.join(__dirname, '../../repo-tests-run/config') +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) + +skipOnWindows('config endpoint', () => { + const repoExample = path.join(__dirname, '../fixtures/go-ipfs-repo') + const repoPath = path.join(__dirname, '../repo-tests-run') + + let updatedConfig = null + + let ipfs = null + let ipfsd = null + before(function (done) { + this.timeout(20 * 1000) + + ncp(repoExample, repoPath, (err) => { + expect(err).to.not.exist() + + waterfall([ + (cb) => df.spawn({ + repoPath: repoPath, + initOptions: { bits: 512 }, + disposable: false, + start: true + }, cb), + (_ipfsd, cb) => { + ipfsd = _ipfsd + ipfsd.start(cb) + } + ], (err) => { + expect(err).to.not.exist() + ipfs = ipfsd.api + + updatedConfig = () => { + const config = fs.readFileSync(path.join(__dirname, '../repo-tests-run/config')) + return JSON.parse(config, 'utf8') + } - let updatedConfig + done() + }) + }) + }) - before(() => { - updatedConfig = () => JSON.parse(fs.readFileSync(configPath, 'utf8')) + after((done) => { + rimraf(repoPath, (err) => { + expect(err).to.not.exist() + ipfsd.stop(done) }) + }) + describe('.config', () => { it('.get returns error for request with invalid argument', (done) => { - ctl.config.get('kittens', (err, res) => { + ipfs.config.get('kittens', (err, res) => { expect(err).to.exist() done() }) }) it('.get returns value for request with argument', (done) => { - ctl.config.get('API.HTTPHeaders', (err, value) => { + ipfs.config.get('API.HTTPHeaders', (err, value) => { expect(err).not.to.exist() expect(value).to.equal(null) done() @@ -35,35 +82,35 @@ module.exports = (ctl) => { }) it('.set updates value for request with both args', (done) => { - ctl.config.set('Datastore.Path', 'kitten', (err) => { + ipfs.config.set('Datastore.Path', 'kitten', (err) => { expect(err).not.to.exist() done() }) }) it('.set returns error for request with both args and JSON flag with invalid JSON argument', (done) => { - ctl.config.set('Datastore.Path', 'kitten', { json: true }, (err) => { + ipfs.config.set('Datastore.Path', 'kitten', { json: true }, (err) => { expect(err).to.exist() done() }) }) it('.set updates value for request with both args and bool flag and true argument', (done) => { - ctl.config.set('Datastore.Path', true, (err) => { + ipfs.config.set('Datastore.Path', true, (err) => { expect(err).not.to.exist() done() }) }) it('.set updates value for request with both args and bool flag and false argument', (done) => { - ctl.config.set('Datastore.Path', false, (err) => { + ipfs.config.set('Datastore.Path', false, (err) => { expect(err).not.to.exist() done() }) }) it('.get updatedConfig', (done) => { - ctl.config.get((err, config) => { + ipfs.config.get((err, config) => { expect(err).not.to.exist() expect(config).to.be.eql(updatedConfig()) done() @@ -76,7 +123,7 @@ module.exports = (ctl) => { it('returns error if the config is invalid', (done) => { const filePath = 'test/fixtures/test-data/badconfig' - ctl.config.replace(filePath, (err) => { + ipfs.config.replace(filePath, (err) => { expect(err).to.exist() done() }) @@ -86,7 +133,7 @@ module.exports = (ctl) => { const filePath = 'test/fixtures/test-data/otherconfig' const expectedConfig = JSON.parse(fs.readFileSync(filePath, 'utf8')) - ctl.config.replace(filePath, (err) => { + ipfs.config.replace(filePath, (err) => { expect(err).not.to.exist() expect(expectedConfig).to.deep.equal(updatedConfig()) done() @@ -94,4 +141,4 @@ module.exports = (ctl) => { }) }) }) -} +}) diff --git a/test/http-api/dns.js b/test/http-api/dns.js new file mode 100644 index 0000000000..3d8b1e669d --- /dev/null +++ b/test/http-api/dns.js @@ -0,0 +1,36 @@ +/* eslint-env mocha */ +'use strict' + +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) + +describe('dns endpoint', () => { + let ipfs = null + let ipfsd = null + before(function (done) { + this.timeout(20 * 1000) + df.spawn({ initOptions: { bits: 512 } }, (err, _ipfsd) => { + expect(err).to.not.exist() + ipfsd = _ipfsd + ipfs = ipfsd.api + done() + }) + }) + + after((done) => ipfsd.stop(done)) + + describe('.dns', () => { + it('resolve ipfs.io dns', (done) => { + ipfs.dns('ipfs.io', (err, result) => { + expect(err).to.not.exist() + expect(result).to.exist() + done() + }) + }) + }) +}) diff --git a/test/http-api/extra/dns.js b/test/http-api/extra/dns.js deleted file mode 100644 index bb6ab6046f..0000000000 --- a/test/http-api/extra/dns.js +++ /dev/null @@ -1,19 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(dirtyChai) - -module.exports = (ctl) => { - describe('.dns', () => { - it('resolve ipfs.io dns', (done) => { - ctl.dns('ipfs.io', (err, result) => { - expect(err).to.not.exist() - expect(result).to.exist() - done() - }) - }) - }) -} diff --git a/test/http-api/extra/id.js b/test/http-api/extra/id.js deleted file mode 100644 index 2e7b75e5d7..0000000000 --- a/test/http-api/extra/id.js +++ /dev/null @@ -1,32 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(dirtyChai) - -module.exports = (ctl) => { - describe('.id', () => { - it('get the identity', (done) => { - ctl.id((err, result) => { - expect(err).to.not.exist() - expect(result.id).to.equal(idResult.ID) - expect(result.publicKey).to.equal(idResult.PublicKey) - const agentComponents = result.agentVersion.split('/') - expect(agentComponents).lengthOf.above(1) - expect(agentComponents[0]).to.equal(idResult.AgentVersion) - expect(result.protocolVersion).to.equal(idResult.ProtocolVersion) - done() - }) - }) - }) -} - -const idResult = { - ID: 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A', - PublicKey: 'CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAE=', - Addresses: [ '/ip4/0.0.0.0/tcp/0' ], - AgentVersion: 'js-ipfs', - ProtocolVersion: '9000' -} diff --git a/test/http-api/extra/version.js b/test/http-api/extra/version.js deleted file mode 100644 index 0b5ec17136..0000000000 --- a/test/http-api/extra/version.js +++ /dev/null @@ -1,21 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(dirtyChai) - -module.exports = (ctl) => { - describe('.version', () => { - it('get the version', (done) => { - ctl.version((err, result) => { - expect(err).to.not.exist() - expect(result).to.have.a.property('version') - expect(result).to.have.a.property('commit') - expect(result).to.have.a.property('repo') - done() - }) - }) - }) -} diff --git a/test/http-api/id.js b/test/http-api/id.js new file mode 100644 index 0000000000..055badf72b --- /dev/null +++ b/test/http-api/id.js @@ -0,0 +1,80 @@ +/* eslint-env mocha */ +'use strict' + +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) + +const ncp = require('ncp').ncp +const rimraf = require('rimraf') +const waterfall = require('async/waterfall') +const path = require('path') + +const isWindows = require('../utils/platforms').isWindows +const skipOnWindows = isWindows() ? describe.skip : describe + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) + +skipOnWindows('id endpoint', () => { + const repoExample = path.join(__dirname, '../fixtures/go-ipfs-repo') + const repoPath = path.join(__dirname, '../repo-tests-run') + + let ipfs = null + let ipfsd = null + before(function (done) { + this.timeout(20 * 1000) + + ncp(repoExample, repoPath, (err) => { + expect(err).to.not.exist() + + waterfall([ + (cb) => df.spawn({ + repoPath: repoPath, + initOptions: { bits: 512 }, + disposable: false, + start: true + }, cb), + (_ipfsd, cb) => { + ipfsd = _ipfsd + ipfsd.start(cb) + } + ], (err) => { + expect(err).to.not.exist() + ipfs = ipfsd.api + done() + }) + }) + }) + + after((done) => { + rimraf(repoPath, (err) => { + expect(err).to.not.exist() + ipfsd.stop(done) + }) + }) + + describe('.id', () => { + it('get the identity', (done) => { + ipfs.id((err, result) => { + expect(err).to.not.exist() + expect(result.id).to.equal(idResult.ID) + expect(result.publicKey).to.equal(idResult.PublicKey) + const agentComponents = result.agentVersion.split('/') + expect(agentComponents).lengthOf.above(1) + expect(agentComponents[0]).to.equal(idResult.AgentVersion) + expect(result.protocolVersion).to.equal(idResult.ProtocolVersion) + done() + }) + }) + }) +}) + +const idResult = { + ID: 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A', + PublicKey: 'CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAE=', + Addresses: ['/ip4/0.0.0.0/tcp/0'], + AgentVersion: 'js-ipfs', + ProtocolVersion: '9000' +} diff --git a/test/http-api/index.js b/test/http-api/index.js index 1fa11622ad..44d48f7f1f 100644 --- a/test/http-api/index.js +++ b/test/http-api/index.js @@ -1,60 +1,11 @@ -/* eslint-env mocha */ 'use strict' -const fs = require('fs') -const chai = require('chai') -const dirtyChai = require('dirty-chai') -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') - -describe('HTTP API', () => { - const repoExample = path.join(__dirname, '../fixtures/go-ipfs-repo') - const repoTests = path.join(__dirname, '../repo-tests-run') - - let http = {} - - before(function (done) { - this.timeout(60 * 1000) - - const options = { - pass: hat(), - enablePubsubExperiment: true - } - http.api = new API(repoTests, null, options) - - ncp(repoExample, repoTests, (err) => { - expect(err).to.not.exist() - - http.api.start(false, done) - }) - }) - - after((done) => http.api.stop((err) => { - expect(err).to.not.exist() - clean(repoTests) - done() - })) - - describe('## http-api spec tests', () => { - fs.readdirSync(path.join(__dirname, '/spec')) - .forEach((file) => require('./spec/' + file)(http)) - }) - - describe('## interface-ipfs-core over ipfs-api', () => { - fs.readdirSync(path.join(__dirname, '/interface')) - .forEach((file) => require('./interface/' + file)) - }) - - 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)) - }) -}) +require('./interface') +require('./inject') +require('./block') +require('./bootstrap') +require('./config') +require('./dns') +require('./id') +require('./object') +require('./version') diff --git a/test/http-api/spec/bitswap.js b/test/http-api/inject/bitswap.js similarity index 100% rename from test/http-api/spec/bitswap.js rename to test/http-api/inject/bitswap.js diff --git a/test/http-api/spec/block.js b/test/http-api/inject/block.js similarity index 100% rename from test/http-api/spec/block.js rename to test/http-api/inject/block.js diff --git a/test/http-api/spec/bootstrap.js b/test/http-api/inject/bootstrap.js similarity index 100% rename from test/http-api/spec/bootstrap.js rename to test/http-api/inject/bootstrap.js diff --git a/test/http-api/spec/config.js b/test/http-api/inject/config.js similarity index 100% rename from test/http-api/spec/config.js rename to test/http-api/inject/config.js diff --git a/test/http-api/spec/dns.js b/test/http-api/inject/dns.js similarity index 100% rename from test/http-api/spec/dns.js rename to test/http-api/inject/dns.js diff --git a/test/http-api/spec/files.js b/test/http-api/inject/files.js similarity index 100% rename from test/http-api/spec/files.js rename to test/http-api/inject/files.js diff --git a/test/http-api/spec/id.js b/test/http-api/inject/id.js similarity index 100% rename from test/http-api/spec/id.js rename to test/http-api/inject/id.js diff --git a/test/http-api/inject/index.js b/test/http-api/inject/index.js new file mode 100644 index 0000000000..24d94ebc4e --- /dev/null +++ b/test/http-api/inject/index.js @@ -0,0 +1,63 @@ +/* eslint-env mocha */ +'use strict' + +const fs = require('fs') +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) +const hat = require('hat') +const API = require('../../../src/http/index') +const ncp = require('ncp').ncp +const path = require('path') +const clean = require('../../utils/clean') + +describe('HTTP API', () => { + const repoExample = path.join(__dirname, '../../fixtures/go-ipfs-repo') + const repoTests = path.join(__dirname, '../../repo-tests-run') + + let http = {} + + const startHttpAPI = (cb) => { + const options = { + pass: hat(), + enablePubsubExperiment: true + } + http.api = new API(repoTests, null, options) + + ncp(repoExample, repoTests, (err) => { + if (err) { + return cb(err) + } + + http.api.start(false, (err) => { + if (err) { + return cb(err) + } + cb(null, http) + }) + }) + } + + before(function (done) { + this.timeout(60 * 1000) + startHttpAPI((err, _http) => { + if (err) { + throw err + } + http = _http + done() + }) + }) + + after((done) => http.api.stop((err) => { + expect(err).to.not.exist() + clean(repoTests) + done() + })) + + describe('## http-api spec tests', () => { + fs.readdirSync(path.join(__dirname)) + .forEach((file) => file !== 'index.js' && require(`./${file}`)(http)) + }) +}) diff --git a/test/http-api/spec/object.js b/test/http-api/inject/object.js similarity index 100% rename from test/http-api/spec/object.js rename to test/http-api/inject/object.js diff --git a/test/http-api/spec/pubsub.js b/test/http-api/inject/pubsub.js similarity index 100% rename from test/http-api/spec/pubsub.js rename to test/http-api/inject/pubsub.js diff --git a/test/http-api/spec/version.js b/test/http-api/inject/version.js similarity index 100% rename from test/http-api/spec/version.js rename to test/http-api/inject/version.js diff --git a/test/http-api/interface/block.js b/test/http-api/interface/block.js index a3a7717f03..ef9e63f370 100644 --- a/test/http-api/interface/block.js +++ b/test/http-api/interface/block.js @@ -12,9 +12,7 @@ const common = { setup: function (callback) { callback(null, { spawnNode: (cb) => { - df.spawn({ - initOptions: { bits: 512 } - }, (err, _ipfsd) => { + df.spawn({ initOptions: { bits: 512 } }, (err, _ipfsd) => { if (err) { return cb(err) } diff --git a/test/http-api/interface/index.js b/test/http-api/interface/index.js new file mode 100644 index 0000000000..7239f09e3a --- /dev/null +++ b/test/http-api/interface/index.js @@ -0,0 +1,10 @@ +/* eslint-env mocha */ +'use strict' + +const fs = require('fs') +const path = require('path') + +describe('## interface-ipfs-core over ipfs-api', () => { + fs.readdirSync(path.join(__dirname)) + .forEach((file) => file !== 'index.js' && require(`./${file}`)) +}) diff --git a/test/http-api/extra/object.js b/test/http-api/object.js similarity index 75% rename from test/http-api/extra/object.js rename to test/http-api/object.js index 913e0b3d08..dfde75d3d4 100644 --- a/test/http-api/extra/object.js +++ b/test/http-api/object.js @@ -11,6 +11,9 @@ const fs = require('fs') const dagPB = require('ipld-dag-pb') const DAGLink = dagPB.DAGLink +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) + function asJson (cb) { return (err, result) => { expect(err).to.not.exist() @@ -19,10 +22,25 @@ function asJson (cb) { } } -module.exports = (ctl) => { +describe('object endpoint', () => { + let ipfs = null + let ipfsd = null + before(function (done) { + this.timeout(20 * 1000) + + df.spawn({ initOptions: { bits: 512 } }, (err, _ipfsd) => { + expect(err).to.not.exist() + ipfsd = _ipfsd + ipfs = ipfsd.api + done() + }) + }) + + after((done) => ipfsd.stop(done)) + describe('.object', () => { it('.new', (done) => { - ctl.object.new(asJson((err, res) => { + ipfs.object.new(asJson((err, res) => { expect(err).to.not.exist() expect(res.multihash) .to.equal('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n') @@ -33,21 +51,21 @@ module.exports = (ctl) => { describe('.get', () => { it('returns error for request without argument', (done) => { - ctl.object.get(null, (err, result) => { + ipfs.object.get(null, (err, result) => { expect(err).to.exist() done() }) }) it('returns error for request with invalid argument', (done) => { - ctl.object.get('invalid', {enc: 'base58'}, (err, result) => { + ipfs.object.get('invalid', { enc: 'base58' }, (err, result) => { expect(err).to.exist() done() }) }) it('returns value', (done) => { - ctl.object.get('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n', {enc: 'base58'}, asJson((err, res) => { + ipfs.object.get('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n', { enc: 'base58' }, asJson((err, res) => { expect(err).to.not.exist() expect(res.links).to.be.eql([]) expect(res.data).to.eql(Buffer.from('')) @@ -60,7 +78,7 @@ module.exports = (ctl) => { it('returns error if the node is invalid', (done) => { const filePath = 'test/fixtures/test-data/badnode.json' - ctl.object.put(filePath, {enc: 'json'}, (err) => { + ipfs.object.put(filePath, { enc: 'json' }, (err) => { expect(err).to.exist() done() }) @@ -79,7 +97,7 @@ module.exports = (ctl) => { size: 68 } - ctl.object.put(filePath, {enc: 'json'}, asJson((err, res) => { + ipfs.object.put(filePath, { enc: 'json' }, asJson((err, res) => { expect(err).to.not.exist() expect(res).to.eql(expectedResult) done() @@ -89,21 +107,21 @@ module.exports = (ctl) => { describe('.stat', () => { it('returns error for request without argument', (done) => { - ctl.object.stat(null, (err, result) => { + ipfs.object.stat(null, (err, result) => { expect(err).to.exist() done() }) }) it('returns error for request with invalid argument', (done) => { - ctl.object.stat('invalid', {enc: 'base58'}, (err, result) => { + ipfs.object.stat('invalid', { enc: 'base58' }, (err, result) => { expect(err).to.exist() done() }) }) it('returns value', (done) => { - ctl.object.stat('QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm', {enc: 'base58'}, (err, result) => { + ipfs.object.stat('QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm', { enc: 'base58' }, (err, result) => { expect(err).to.not.exist() expect(result.Hash).to.equal('QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm') expect(result.NumLinks).to.equal(1) @@ -118,21 +136,21 @@ module.exports = (ctl) => { describe('.data', () => { it('returns error for request without argument', (done) => { - ctl.object.data(null, (err, result) => { + ipfs.object.data(null, (err, result) => { expect(err).to.exist() done() }) }) it('returns error for request with invalid argument', (done) => { - ctl.object.data('invalid', {enc: 'base58'}, (err, result) => { + ipfs.object.data('invalid', { enc: 'base58' }, (err, result) => { expect(err).to.exist() done() }) }) it('returns value', (done) => { - ctl.object.data('QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm', {enc: 'base58'}, (err, result) => { + ipfs.object.data('QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm', { enc: 'base58' }, (err, result) => { expect(err).to.not.exist() expect(result.toString()).to.equal('another') done() @@ -142,14 +160,14 @@ module.exports = (ctl) => { describe('.links', () => { it('returns error for request without argument', (done) => { - ctl.object.links(null, (err, result) => { + ipfs.object.links(null, (err, result) => { expect(err).to.exist() done() }) }) it('returns error for request with invalid argument', (done) => { - ctl.object.links('invalid', {enc: 'base58'}, (err, result) => { + ipfs.object.links('invalid', { enc: 'base58' }, (err, result) => { expect(err).to.exist() done() }) @@ -162,7 +180,7 @@ module.exports = (ctl) => { size: 8 } - ctl.object.links('QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm', {enc: 'base58'}, (err, result) => { + ipfs.object.links('QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm', { enc: 'base58' }, (err, result) => { expect(err).to.not.exist() expect(result[0].toJSON()).to.deep.equal(expectedResult) done() @@ -172,7 +190,7 @@ module.exports = (ctl) => { describe('.patch.appendData', () => { it('returns error for request without key & data', (done) => { - ctl.object.patch.appendData(null, null, (err) => { + ipfs.object.patch.appendData(null, null, (err) => { expect(err).to.exist() done() }) @@ -181,7 +199,7 @@ module.exports = (ctl) => { it('returns error for request without data', (done) => { const filePath = 'test/fixtures/test-data/badnode.json' - ctl.object.patch.appendData(null, filePath, (err) => { + ipfs.object.patch.appendData(null, filePath, (err) => { expect(err).to.exist() done() }) @@ -197,7 +215,7 @@ module.exports = (ctl) => { size: 19 } - ctl.object.patch.appendData(key, filePath, {enc: 'base58'}, asJson((err, res) => { + ipfs.object.patch.appendData(key, filePath, { enc: 'base58' }, asJson((err, res) => { expect(err).to.not.exist() expect(res).to.eql(expectedResult) done() @@ -207,7 +225,7 @@ module.exports = (ctl) => { describe('.patch.setData', () => { it('returns error for request without key & data', (done) => { - ctl.object.patch.setData(null, null, (err) => { + ipfs.object.patch.setData(null, null, (err) => { expect(err).to.exist() done() }) @@ -216,7 +234,7 @@ module.exports = (ctl) => { it('returns error for request without data', (done) => { const filePath = 'test/fixtures/test-data/badnode.json' - ctl.object.patch.setData(null, filePath, (err) => { + ipfs.object.patch.setData(null, filePath, (err) => { expect(err).to.exist() done() }) @@ -232,7 +250,7 @@ module.exports = (ctl) => { size: 19 } - ctl.object.patch.setData(key, filePath, {enc: 'base58'}, asJson((err, res) => { + ipfs.object.patch.setData(key, filePath, { enc: 'base58' }, asJson((err, res) => { expect(err).to.not.exist() expect(res).to.eql(expectedResult) done() @@ -242,14 +260,14 @@ module.exports = (ctl) => { describe('.patch.addLink', () => { it('returns error for request without arguments', (done) => { - ctl.object.patch.addLink(null, null, null, (err) => { + ipfs.object.patch.addLink(null, null, null, (err) => { expect(err).to.exist() done() }) }) it('returns error for request only one invalid argument', (done) => { - ctl.object.patch.addLink('invalid', null, null, (err) => { + ipfs.object.patch.addLink('invalid', null, null, (err) => { expect(err).to.exist() done() }) @@ -260,7 +278,7 @@ module.exports = (ctl) => { const name = '' const ref = 'QmTz3oc4gdpRMKP2sdGUPZTAGRngqjsi99BPoztyP53JMM' const link = new DAGLink(name, 2, ref) - ctl.object.patch.addLink(root, link, {enc: 'base58'}, (err) => { + ipfs.object.patch.addLink(root, link, { enc: 'base58' }, (err) => { expect(err).to.exist() done() }) @@ -271,7 +289,7 @@ module.exports = (ctl) => { const name = 'foo' const ref = 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn' const link = new DAGLink(name, 10, ref) - ctl.object.patch.addLink(root, link, {enc: 'base58'}, asJson((err, res) => { + ipfs.object.patch.addLink(root, link, { enc: 'base58' }, asJson((err, res) => { expect(err).not.to.exist() expect(res.multihash).to.equal('QmdVHE8fUD6FLNLugtNxqDFyhaCgdob372hs6BYEe75VAK') expect(res.links[0]).to.eql({ @@ -286,14 +304,14 @@ module.exports = (ctl) => { describe('.patch.rmLink', () => { it('returns error for request without arguments', (done) => { - ctl.object.patch.rmLink(null, null, (err) => { + ipfs.object.patch.rmLink(null, null, (err) => { expect(err).to.exist() done() }) }) it('returns error for request only one invalid argument', (done) => { - ctl.object.patch.rmLink('invalid', null, (err) => { + ipfs.object.patch.rmLink('invalid', null, (err) => { expect(err).to.exist() done() }) @@ -303,11 +321,11 @@ module.exports = (ctl) => { const root = '' const link = 'foo' - ctl.object.patch.rmLink(root, link, (err) => { + ipfs.object.patch.rmLink(root, link, (err) => { expect(err).to.exist() done() }) }) }) }) -} +}) diff --git a/test/http-api/version.js b/test/http-api/version.js new file mode 100644 index 0000000000..2f0d1b2925 --- /dev/null +++ b/test/http-api/version.js @@ -0,0 +1,38 @@ +/* eslint-env mocha */ +'use strict' + +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) + +describe('version endpoint', () => { + let ipfs = null + let ipfsd = null + before(function (done) { + this.timeout(20 * 1000) + df.spawn({ initOptions: { bits: 512 } }, (err, _ipfsd) => { + expect(err).to.not.exist() + ipfsd = _ipfsd + ipfs = ipfsd.api + done() + }) + }) + + after((done) => ipfsd.stop(done)) + + describe('.version', () => { + it('get the version', (done) => { + ipfs.version((err, result) => { + expect(err).to.not.exist() + expect(result).to.have.a.property('version') + expect(result).to.have.a.property('commit') + expect(result).to.have.a.property('repo') + done() + }) + }) + }) +}) diff --git a/test/utils/platforms.js b/test/utils/platforms.js new file mode 100644 index 0000000000..584452f97e --- /dev/null +++ b/test/utils/platforms.js @@ -0,0 +1,16 @@ +'use strict' + +const os = require('os') +const current = os.platform() + +module.exports = { + isWindows: () => { + return current === 'win32' + }, + isMacOS: () => { + return current === 'darwin' + }, + isLinux: () => { + return current === 'linux' + } +}