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

Faster tests #1336

Closed
wants to merge 4 commits into from
Closed
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
6 changes: 3 additions & 3 deletions src/cli/commands/bitswap/stat.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
'use strict'

const CID = require('cids')
const print = require('../../utils').print

module.exports = {
command: 'stat',

Expand All @@ -11,6 +8,9 @@ module.exports = {
builder: {},

handler (argv) {
const CID = require('cids')
const print = require('../../utils').print

argv.ipfs.bitswap.stat((err, stats) => {
if (err) {
throw err
Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/bitswap/wantlist.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict'

const print = require('../../utils').print

module.exports = {
command: 'wantlist',

Expand All @@ -16,6 +14,8 @@ module.exports = {
},

handler (argv) {
const print = require('../../utils').print

// TODO: handle argv.peer
argv.ipfs.bitswap.wantlist((err, res) => {
if (err) {
Expand Down
3 changes: 1 addition & 2 deletions src/cli/commands/block/get.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict'

const CID = require('cids')

module.exports = {
command: 'get <key>',

Expand All @@ -10,6 +8,7 @@ module.exports = {
builder: {},

handler (argv) {
const CID = require('cids')
const cid = new CID(argv.key)

argv.ipfs.block.get(cid, (err, block) => {
Expand Down
62 changes: 31 additions & 31 deletions src/cli/commands/block/put.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,5 @@
'use strict'

const CID = require('cids')
const multihashing = require('multihashing-async')
const bl = require('bl')
const fs = require('fs')
const Block = require('ipfs-block')
const waterfall = require('async/waterfall')
const print = require('../../utils').print

function addBlock (data, opts) {
const ipfs = opts.ipfs
let cid

waterfall([
(cb) => multihashing(data, opts.mhtype || 'sha2-256', cb),
(multihash, cb) => {
if (opts.format !== 'dag-pb' || opts.version !== 0) {
cid = new CID(1, opts.format || 'dag-pb', multihash)
} else {
cid = new CID(0, 'dag-pb', multihash)
}

ipfs.block.put(new Block(data, cid), cb)
}
], (err) => {
if (err) {
throw err
}
print(cid.toBaseEncodedString())
})
}

module.exports = {
command: 'put [block]',

Expand Down Expand Up @@ -58,6 +27,37 @@ module.exports = {
},

handler (argv) {
const CID = require('cids')
const multihashing = require('multihashing-async')
const bl = require('bl')
const fs = require('fs')
const Block = require('ipfs-block')
const waterfall = require('async/waterfall')
const print = require('../../utils').print

function addBlock (data, opts) {
const ipfs = opts.ipfs
let cid

waterfall([
(cb) => multihashing(data, opts.mhtype || 'sha2-256', cb),
(multihash, cb) => {
if (opts.format !== 'dag-pb' || opts.version !== 0) {
cid = new CID(1, opts.format || 'dag-pb', multihash)
} else {
cid = new CID(0, 'dag-pb', multihash)
}

ipfs.block.put(new Block(data, cid), cb)
}
], (err) => {
if (err) {
throw err
}
print(cid.toBaseEncodedString())
})
}

if (argv.block) {
const buf = fs.readFileSync(argv.block)
return addBlock(buf, argv)
Expand Down
7 changes: 3 additions & 4 deletions src/cli/commands/block/rm.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
'use strict'

const utils = require('../../utils')
const mh = require('multihashes')
const print = utils.print

module.exports = {
command: 'rm <key>',

Expand All @@ -12,6 +8,9 @@ module.exports = {
builder: {},

handler (argv) {
const utils = require('../../utils')
const print = utils.print
const mh = require('multihashes')
if (utils.isDaemonOn()) {
// TODO implement this once `js-ipfs-api` supports it
throw new Error('rm block with daemon running is not yet implemented')
Expand Down
5 changes: 2 additions & 3 deletions src/cli/commands/block/stat.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
'use strict'

const CID = require('cids')
const print = require('../../utils').print

module.exports = {
command: 'stat <key>',

Expand All @@ -11,6 +8,8 @@ module.exports = {
builder: {},

handler (argv) {
const CID = require('cids')
const print = require('../../utils').print
argv.ipfs.block.stat(new CID(argv.key), (err, stats) => {
if (err) {
throw err
Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/bootstrap/add.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict'

const print = require('../../utils').print

module.exports = {
command: 'add [<peer>]',

Expand All @@ -16,6 +14,8 @@ module.exports = {
},

handler (argv) {
const print = require('../../utils').print

argv.ipfs.bootstrap.add(argv.peer, {
default: argv.default
}, (err, list) => {
Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/bootstrap/list.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict'

const print = require('../../utils').print

module.exports = {
command: 'list',

Expand All @@ -10,6 +8,8 @@ module.exports = {
builder: {},

handler (argv) {
const print = require('../../utils').print

argv.ipfs.bootstrap.list((err, list) => {
if (err) {
throw err
Expand Down
10 changes: 5 additions & 5 deletions src/cli/commands/bootstrap/rm.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
'use strict'

const debug = require('debug')
const log = debug('cli:bootstrap')
log.error = debug('cli:bootstrap:error')
const print = require('../../utils').print

module.exports = {
command: 'rm [<peer>]',

Expand All @@ -19,6 +14,11 @@ module.exports = {
},

handler (argv) {
const debug = require('debug')
const log = debug('cli:bootstrap')
log.error = debug('cli:bootstrap:error')
const print = require('../../utils').print

argv.ipfs.bootstrap.rm(argv.peer, {
all: argv.all
}, (err, list) => {
Expand Down
6 changes: 3 additions & 3 deletions src/cli/commands/commands.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict'
const print = require('../utils').print
const path = require('path')
const glob = require('glob').sync

module.exports = {
command: 'commands',

describe: 'List all available commands',

handler () {
const print = require('../utils').print
const path = require('path')
const glob = require('glob').sync
const basePath = path.resolve(__dirname, '..')

// modeled after https://github.com/vdemedes/ronin/blob/master/lib/program.js#L78
Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict'
const print = require('../utils').print

module.exports = {
command: 'config <key> [value]',

Expand All @@ -24,6 +22,8 @@ module.exports = {
},

handler (argv) {
const print = require('../utils').print

if (argv._handled) {
return
}
Expand Down
13 changes: 6 additions & 7 deletions src/cli/commands/config/edit.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
'use strict'

const spawn = require('child_process').spawn
const fs = require('fs')
const temp = require('temp')
const waterfall = require('async/waterfall')

const utils = require('../../utils')

module.exports = {
command: 'edit',

Expand All @@ -15,6 +8,12 @@ module.exports = {
builder: {},

handler (argv) {
const spawn = require('child_process').spawn
const fs = require('fs')
const temp = require('temp')
const waterfall = require('async/waterfall')

const utils = require('../../utils')
if (argv._handled) return
argv._handled = true

Expand Down
8 changes: 4 additions & 4 deletions src/cli/commands/config/replace.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
'use strict'

const path = require('path')
const fs = require('fs')
const utils = require('../../utils')

module.exports = {
command: 'replace <file>',

Expand All @@ -12,6 +8,10 @@ module.exports = {
builder: {},

handler (argv) {
const path = require('path')
const fs = require('fs')
const utils = require('../../utils')

if (argv._handled) return
argv._handled = true

Expand Down
10 changes: 5 additions & 5 deletions src/cli/commands/config/show.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
'use strict'

const debug = require('debug')
const log = debug('cli:config')
log.error = debug('cli:config:error')
const print = require('../../utils').print

module.exports = {
command: 'show',

Expand All @@ -13,6 +8,11 @@ module.exports = {
builder: {},

handler (argv) {
const debug = require('debug')
const log = debug('cli:config')
log.error = debug('cli:config:error')
const print = require('../../utils').print

if (argv._handled) return
argv._handled = true

Expand Down
6 changes: 2 additions & 4 deletions src/cli/commands/daemon.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
'use strict'

const HttpAPI = require('../../http')
const utils = require('../utils')
const print = utils.print

let httpAPI

module.exports = {
command: 'daemon',

Expand All @@ -29,10 +26,11 @@ module.exports = {
},

handler (argv) {
const HttpAPI = require('../../http')
print('Initializing daemon...')

const repoPath = utils.getRepoPath()
httpAPI = new HttpAPI(process.env.IPFS_PATH, null, argv)
const httpAPI = new HttpAPI(process.env.IPFS_PATH, null, argv)

httpAPI.start((err) => {
if (err && err.code === 'ENOENT' && err.message.match(/Uninitalized repo/i)) {
Expand Down
6 changes: 3 additions & 3 deletions src/cli/commands/dag/get.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
'use strict'

const CID = require('cids')
const print = require('../../utils').print

module.exports = {
command: 'get <cid path>',

Expand All @@ -16,6 +13,9 @@ module.exports = {
},

handler (argv) {
const CID = require('cids')
const print = require('../../utils').print

const refParts = argv.cidpath.split('/')
const cidString = refParts[0]
const path = refParts.slice(1).join('/')
Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/dns.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict'
const print = require('../utils').print

module.exports = {
command: 'dns <domain>',

Expand All @@ -13,6 +11,8 @@ module.exports = {
},

handler (argv) {
const print = require('../utils').print

argv.ipfs.dns(argv['domain'], (err, path) => {
if (err) {
throw err
Expand Down
Loading