Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
chore: rebase and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Shaw committed Jan 13, 2020
1 parent 5dcc69b commit c3ee120
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 151 deletions.
3 changes: 1 addition & 2 deletions src/cli/flush.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module.exports = {

builder: {
'cid-base': {
default: 'base58btc',
describe: 'CID base to use.'
}
},
Expand All @@ -28,7 +27,7 @@ module.exports = {
const ipfs = await getIpfs()
let cid = await ipfs.files.flush(path || FILE_SEPARATOR, {})

if (cidBase !== 'base58btc' && cid.version === 0) {
if (cidBase && cidBase !== 'base58btc' && cid.version === 0) {
cid = cid.toV1()
}

Expand Down
2 changes: 0 additions & 2 deletions src/cli/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module.exports = {
describe: 'Sort entries by name'
},
'cid-base': {
default: 'base58btc',
describe: 'CID base to use.'
}
},
Expand All @@ -50,7 +49,6 @@ module.exports = {
const ipfs = await getIpfs()

const printListing = file => {
console.log(file)
if (long) {
print(`${formatMode(file.mode, file.type === 1)}\t${formatMtime(file.mtime)}\t${file.name}\t${file.cid.toString(cidBase)}\t${file.size}`)
} else {
Expand Down
1 change: 0 additions & 1 deletion src/cli/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ Mtime: <mtime>`,
describe: 'Compute the amount of the dag that is local, and if possible the total size'
},
'cid-base': {
default: 'base58btc',
describe: 'CID base to use.'
}
},
Expand Down
4 changes: 2 additions & 2 deletions src/http/flush.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const mfsFlush = {

let cid = await ipfs.files.flush(arg || FILE_SEPARATOR, {})

if (cidBase !== 'base58btc' && cid.version === 0) {
if (cidBase && cidBase !== 'base58btc' && cid.version === 0) {
cid = cid.toV1()
}

Expand All @@ -36,7 +36,7 @@ const mfsFlush = {
},
query: Joi.object().keys({
arg: Joi.string(),
cidBase: Joi.string().default('base58btc')
cidBase: Joi.string()
})
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/http/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
PassThrough
} = require('stream')
const toStream = require('it-to-stream')
const all = require('it-all')

const mapEntry = (entry, options) => {
options = options || {}
Expand Down Expand Up @@ -67,7 +68,7 @@ const mfsLs = {
return h.response(responseStream).header('X-Stream-Output', '1')
}

const files = await ipfs.files.ls(arg)
const files = await all(ipfs.files.ls(arg))

return h.response({
Entries: files.map(entry => mapEntry(entry, { cidBase, long }))
Expand All @@ -82,7 +83,7 @@ const mfsLs = {
query: Joi.object().keys({
arg: Joi.string().default('/'),
long: Joi.boolean().default(false),
cidBase: Joi.string().default('base58btc'),
cidBase: Joi.string(),
stream: Joi.boolean().default(false)
})
.rename('l', 'long', {
Expand Down
2 changes: 1 addition & 1 deletion src/http/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const mfsStat = {
hash: Joi.boolean().default(false),
size: Joi.boolean().default(false),
withLocal: Joi.boolean().default(false),
cidBase: Joi.string().default('base58btc')
cidBase: Joi.string()
})
}
}
Expand Down
96 changes: 61 additions & 35 deletions test/cli/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const expect = require('../helpers/chai')
const cli = require('../helpers/cli')
const sinon = require('sinon')
const isNode = require('detect-node')
const CID = require('cids')
const fileCid = new CID('bafybeigyov3nzxrqjismjpq7ghkkjorcmozy5rgaikvyieakoqpxfc3rvu')

describe('ls', () => {
if (!isNode) {
Expand All @@ -19,7 +21,7 @@ describe('ls', () => {
output = ''
ipfs = {
files: {
ls: sinon.stub().resolves([])
ls: sinon.stub().returns([])
}
}
print = (msg = '', newline = true) => {
Expand Down Expand Up @@ -49,87 +51,102 @@ describe('ls', () => {

it('should list a path with details', async () => {
const files = [{
hash: 'file-name',
cid: fileCid,
name: 'file-name',
size: 'file-size',
mode: 'file-mode',
mtime: 'file-mtime'
mode: 0o755,
mtime: {
secs: Date.now() / 1000,
nsecs: 0
}
}]

ipfs.files.ls = sinon.stub().resolves(files)
ipfs.files.ls = sinon.stub().returns(files)

await cli('files ls --long /foo', { ipfs, print })

expect(ipfs.files.ls.callCount).to.equal(1)
expect(output).to.include(files[0].hash)
expect(output).to.include(files[0].cid.toString())
expect(output).to.include(files[0].name)
expect(output).to.include(files[0].size)
})

it('should list a path with details (short option)', async () => {
const files = [{
hash: 'file-name',
cid: fileCid,
name: 'file-name',
size: 'file-size',
mode: 'file-mode',
mtime: 'file-mtime'
mode: 0o755,
mtime: {
secs: Date.now() / 1000,
nsecs: 0
}
}]

ipfs.files.ls = sinon.stub().resolves(files)
ipfs.files.ls = sinon.stub().returns(files)

await cli('files ls -l /foo', { ipfs, print })

expect(ipfs.files.ls.callCount).to.equal(1)
expect(output).to.include(files[0].hash)
expect(output).to.include(files[0].cid.toString())
expect(output).to.include(files[0].name)
expect(output).to.include(files[0].size)
})

it('should list a path with details', async () => {
const files = [{
hash: 'file-name',
cid: fileCid,
name: 'file-name',
size: 'file-size',
mode: 'file-mode',
mtime: 'file-mtime'
mode: 0o755,
mtime: {
secs: Date.now() / 1000,
nsecs: 0
}
}]

ipfs.files.ls = sinon.stub().resolves(files)
ipfs.files.ls = sinon.stub().returns(files)

await cli('files ls --long /foo', { ipfs, print })

expect(ipfs.files.ls.callCount).to.equal(1)
expect(output).to.include(files[0].hash)
expect(output).to.include(files[0].cid.toString())
expect(output).to.include(files[0].name)
expect(output).to.include(files[0].size)
})

it('should list a path with details (short option)', async () => {
const files = [{
hash: 'file-name',
cid: fileCid,
name: 'file-name',
size: 'file-size',
mode: 'file-mode',
mtime: 'file-mtime'
mode: 0o755,
mtime: {
secs: Date.now() / 1000,
nsecs: 0
}
}]

ipfs.files.ls = sinon.stub().resolves(files)
ipfs.files.ls = sinon.stub().returns(files)

await cli('files ls -l /foo', { ipfs, print })

expect(ipfs.files.ls.callCount).to.equal(1)
expect(output).to.include(files[0].hash)
expect(output).to.include(files[0].cid.toString())
expect(output).to.include(files[0].name)
expect(output).to.include(files[0].size)
})

it('should list a path without sorting', async () => {
const files = [{
hash: 'file-name',
cid: fileCid,
name: 'file-name',
size: 'file-size',
mode: 'file-mode',
mtime: 'file-mtime'
mode: 0o755,
mtime: {
secs: Date.now() / 1000,
nsecs: 0
}
}]

ipfs.files.ls = sinon.stub().returns(files)
Expand All @@ -142,11 +159,14 @@ describe('ls', () => {

it('should list a path without sorting (short option)', async () => {
const files = [{
hash: 'file-name',
cid: fileCid,
name: 'file-name',
size: 'file-size',
mode: 'file-mode',
mtime: 'file-mtime'
mode: 0o755,
mtime: {
secs: Date.now() / 1000,
nsecs: 0
}
}]

ipfs.files.ls = sinon.stub().returns(files)
Expand All @@ -159,38 +179,44 @@ describe('ls', () => {

it('should list a path with details without sorting', async () => {
const files = [{
hash: 'file-name',
cid: fileCid,
name: 'file-name',
size: 'file-size',
mode: 'file-mode',
mtime: 'file-mtime'
mode: 0o755,
mtime: {
secs: Date.now() / 1000,
nsecs: 0
}
}]

ipfs.files.ls = sinon.stub().returns(files)

await cli('files ls --long --sort false /foo', { ipfs, print })

expect(ipfs.files.ls.callCount).to.equal(1)
expect(output).to.include(files[0].hash)
expect(output).to.include(files[0].cid.toString())
expect(output).to.include(files[0].name)
expect(output).to.include(files[0].size)
})

it('should list a path with details without sorting (short option)', async () => {
const files = [{
hash: 'file-name',
cid: fileCid,
name: 'file-name',
size: 'file-size',
mode: 'file-mode',
mtime: 'file-mtime'
mode: 0o755,
mtime: {
secs: Date.now() / 1000,
nsecs: 0
}
}]

ipfs.files.ls = sinon.stub().returns(files)

await cli('files ls -l -s false /foo', { ipfs, print })

expect(ipfs.files.ls.callCount).to.equal(1)
expect(output).to.include(files[0].hash)
expect(output).to.include(files[0].cid.toString())
expect(output).to.include(files[0].name)
expect(output).to.include(files[0].size)
})
Expand Down
8 changes: 5 additions & 3 deletions test/cli/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const expect = require('../helpers/chai')
const cli = require('../helpers/cli')
const sinon = require('sinon')
const isNode = require('detect-node')
const CID = require('cids')
const fileCid = new CID('bafybeigyov3nzxrqjismjpq7ghkkjorcmozy5rgaikvyieakoqpxfc3rvu')

function defaultOptions (modification = {}) {
const options = {
Expand Down Expand Up @@ -33,7 +35,7 @@ describe('stat', () => {
ipfs = {
files: {
stat: sinon.stub().resolves({
hash: 'stats-hash',
cid: fileCid,
size: 'stats-size',
cumulativeSize: 'stats-cumulativeSize',
blocks: 'stats-blocks',
Expand Down Expand Up @@ -93,7 +95,7 @@ describe('stat', () => {
path,
defaultOptions()
])
expect(output).to.equal('stats-hash\n')
expect(output).to.equal(`${fileCid}\n`)
})

it('should stat a path and only show hashes (short option)', async () => {
Expand All @@ -104,7 +106,7 @@ describe('stat', () => {
path,
defaultOptions()
])
expect(output).to.equal('stats-hash\n')
expect(output).to.equal(`${fileCid}\n`)
})

it('should stat a path and only show sizes', async () => {
Expand Down
Loading

0 comments on commit c3ee120

Please sign in to comment.