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

chore: convert tests to async/await #2495

Merged
merged 4 commits into from
Oct 2, 2019
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
"execa": "^2.0.4",
"form-data": "^2.5.1",
"hat": "0.0.3",
"interface-ipfs-core": "^0.115.0",
"interface-ipfs-core": "^0.115.1",
"ipfs-interop": "~0.1.0",
"ipfsd-ctl": "^0.47.2",
"libp2p-websocket-star": "~0.10.2",
Expand Down
82 changes: 39 additions & 43 deletions test/cli/bitswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,69 +30,65 @@ describe('bitswap', () => runOn((thing) => {
})
})

before(function (done) {
const test = (cb) => {
ipfs('bitswap wantlist')
.then(out => cb(null, out.includes(key0) && out.includes(key1)))
.catch(cb)
before(async () => {
const test = async () => {
const out = await ipfs('bitswap wantlist')

return out.includes(key0) && out.includes(key1)
}

waitFor(test, {
await waitFor(test, {
name: `${key0} and ${key1} to be wanted`,
timeout: 60 * 1000
}, done)
})
})

it('wantlist', function () {
return ipfs('bitswap wantlist').then((out) => {
expect(out).to.include(key0)
expect(out).to.include(key1)
})
it('wantlist', async function () {
const out = await ipfs('bitswap wantlist')
expect(out).to.include(key0)
expect(out).to.include(key1)
})

it('should get wantlist with CIDs encoded in specified base', function () {
it('should get wantlist with CIDs encoded in specified base', async function () {
this.timeout(20 * 1000)
return ipfs('bitswap wantlist --cid-base=base64').then((out) => {
expect(out).to.include(new CID(key1).toBaseEncodedString('base64') + '\n')
})

const out = await ipfs('bitswap wantlist --cid-base=base64')
expect(out).to.include(new CID(key1).toBaseEncodedString('base64') + '\n')
})

it('wantlist peerid', function () {
it('wantlist peerid', async function () {
this.timeout(20 * 1000)
return ipfs('bitswap wantlist ' + peerId).then((out) => {
expect(out).to.eql('')
})

const out = await ipfs('bitswap wantlist ' + peerId)
expect(out).to.eql('')
})

it('stat', function () {
it('stat', async function () {
this.timeout(20 * 1000)

return ipfs('bitswap stat').then((out) => {
expect(out).to.include([
'bitswap status',
' blocks received: 0',
' dup blocks received: 0',
' dup data received: 0B',
// We sometimes pick up partners while the tests run and the order of
// wanted keys is not defined so our assertion ends here.
' wantlist [2 keys]'
].join('\n'))

expect(out).to.include(key0)
expect(out).to.include(key1)
})
const out = await ipfs('bitswap stat')
expect(out).to.include([
'bitswap status',
' blocks received: 0',
' dup blocks received: 0',
' dup data received: 0B',
// We sometimes pick up partners while the tests run and the order of
// wanted keys is not defined so our assertion ends here.
' wantlist [2 keys]'
].join('\n'))
expect(out).to.include(key0)
expect(out).to.include(key1)
})

it('should get stats with wantlist CIDs encoded in specified base', function () {
it('should get stats with wantlist CIDs encoded in specified base', async function () {
this.timeout(20 * 1000)
return ipfs('bitswap stat --cid-base=base64').then((out) => {
expect(out).to.include(new CID(key1).toBaseEncodedString('base64'))
})

const out = await ipfs('bitswap stat --cid-base=base64')
expect(out).to.include(new CID(key1).toBaseEncodedString('base64'))
})

it('unwant', function () {
return ipfs('bitswap unwant ' + key0).then((out) => {
expect(out).to.eql(`Key ${key0} removed from wantlist\n`)
})
it('unwant', async function () {
const out = await ipfs('bitswap unwant ' + key0)
expect(out).to.eql(`Key ${key0} removed from wantlist\n`)
})
}))
85 changes: 37 additions & 48 deletions test/cli/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,82 +11,71 @@ describe('block', () => runOnAndOff((thing) => {
ipfs = thing.ipfs
})

it('put', function () {
it('put', async function () {
this.timeout(40 * 1000)
return ipfs('block put test/fixtures/test-data/hello').then((out) => {
expect(out).to.eql('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp\n')
})

const out = await ipfs('block put test/fixtures/test-data/hello')
expect(out).to.eql('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp\n')
})

it('put with flags, format and mhtype', function () {
it('put with flags, format and mhtype', async function () {
this.timeout(40 * 1000)

return ipfs('block put --format eth-block --mhtype keccak-256 test/fixtures/test-data/eth-block')
.then((out) =>
expect(out).to.eql('bagiacgzarkhijr4xmbp345ovwwxra7kcecrnwcwtl7lg3g7d2ogyprdswjwq\n'))
const out = await ipfs('block put --format eth-block --mhtype keccak-256 test/fixtures/test-data/eth-block')
expect(out).to.eql('bagiacgzarkhijr4xmbp345ovwwxra7kcecrnwcwtl7lg3g7d2ogyprdswjwq\n')
})

it('should put and print CID encoded in specified base', function () {
it('should put and print CID encoded in specified base', async function () {
this.timeout(40 * 1000)

return ipfs('block put test/fixtures/test-data/hello --cid-base=base64').then((out) => {
expect(out).to.eql('mAXASIKlIkE8vD0ebj4GXaUswGEsNLtHBzSoewPuF0pmhkqRH\n')
})
const out = await ipfs('block put test/fixtures/test-data/hello --cid-base=base64')
expect(out).to.eql('mAXASIKlIkE8vD0ebj4GXaUswGEsNLtHBzSoewPuF0pmhkqRH\n')
})

it('get', function () {
it('get', async function () {
this.timeout(40 * 1000)

return ipfs('block get QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp')
.then((out) => expect(out).to.eql('hello world\n'))
const out = await ipfs('block get QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp')
expect(out).to.eql('hello world\n')
})

it('get block from file without a final newline', function () {
it('get block from file without a final newline', async function () {
this.timeout(40 * 1000)

return ipfs('block put test/fixtures/test-data/no-newline').then((out) => {
expect(out).to.eql('QmTwbQs4sGcCiPxV97SpbHS7QgmVg9SiKxcG1AcF1Ly2SL\n')
return ipfs('block get QmTwbQs4sGcCiPxV97SpbHS7QgmVg9SiKxcG1AcF1Ly2SL')
})
.then((out) => expect(out).to.eql('there is no newline at end of this file'))
const out = await ipfs('block put test/fixtures/test-data/no-newline')
expect(out).to.eql('QmTwbQs4sGcCiPxV97SpbHS7QgmVg9SiKxcG1AcF1Ly2SL\n')

const out2 = await ipfs('block get QmTwbQs4sGcCiPxV97SpbHS7QgmVg9SiKxcG1AcF1Ly2SL')
expect(out2).to.eql('there is no newline at end of this file')
})

it('stat', function () {
it('stat', async function () {
this.timeout(40 * 1000)

return ipfs('block stat QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp')
.then((out) => {
expect(out).to.eql([
'Key: QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp',
'Size: 12'
].join('\n') + '\n')
})
const out = await ipfs('block stat QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp')
expect(out).to.eql([
'Key: QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp',
'Size: 12'
].join('\n') + '\n')
})

it('should stat and print CID encoded in specified base', function () {
it('should stat and print CID encoded in specified base', async function () {
this.timeout(80 * 1000)

return ipfs('block put test/fixtures/test-data/hello')
.then((out) => {
expect(out).to.eql('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp\n')
return ipfs('block stat QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp --cid-base=base64')
})
.then((out) => {
expect(out).to.eql([
'Key: mAXASIKlIkE8vD0ebj4GXaUswGEsNLtHBzSoewPuF0pmhkqRH',
'Size: 12'
].join('\n') + '\n')
})
const out = await ipfs('block put test/fixtures/test-data/hello')
expect(out).to.eql('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp\n')

const out2 = await ipfs('block stat QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp --cid-base=base64')
expect(out2).to.eql([
'Key: mAXASIKlIkE8vD0ebj4GXaUswGEsNLtHBzSoewPuF0pmhkqRH',
'Size: 12'
].join('\n') + '\n')
})

it.skip('rm', function () {
it.skip('rm', async function () {
this.timeout(40 * 1000)

return ipfs('block rm QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp')
.then((out) => {
expect(out).to.eql(
'removed QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp\n'
)
})
const out = await ipfs('block rm QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp')
expect(out).to.eql('removed QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp\n')
})
}))
51 changes: 24 additions & 27 deletions test/cli/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,50 +57,47 @@ describe('bootstrap', () => runOnAndOff((thing) => {
'/ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD'
]

it('add default', function () {
it('add default', async function () {
this.timeout(40 * 1000)

return ipfs('bootstrap add --default').then((out) => {
expect(out).to.equal(defaultList.join('\n') + '\n')
})
const out = await ipfs('bootstrap add --default')
expect(out).to.equal(defaultList.join('\n') + '\n')
})

it('list the bootstrap nodes', function () {
it('list the bootstrap nodes', async function () {
this.timeout(40 * 1000)

return ipfs('bootstrap list').then((out) => {
expect(out).to.equal(defaultList.join('\n') + '\n')
})
const out = await ipfs('bootstrap list')
expect(out).to.equal(defaultList.join('\n') + '\n')
})

it('add another bootstrap node', function () {
it('add another bootstrap node', async function () {
this.timeout(40 * 1000)

return ipfs('bootstrap add /ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD').then((out) => {
expect(out).to.equal('/ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD\n')
return ipfs('bootstrap list')
}).then((out) => expect(out).to.equal(updatedList.join('\n') + '\n'))
const out = await ipfs('bootstrap add /ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD')
expect(out).to.equal('/ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD\n')

const out2 = await ipfs('bootstrap list')
expect(out2).to.equal(updatedList.join('\n') + '\n')
})

it('rm a bootstrap node', function () {
it('rm a bootstrap node', async function () {
this.timeout(40 * 1000)

return ipfs('bootstrap rm /ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD').then((out) => {
expect(out).to.equal('/ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD\n')
return ipfs('bootstrap list')
}).then((out) => {
expect(out).to.equal(defaultList.join('\n') + '\n')
})
const out = await ipfs('bootstrap rm /ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD')
expect(out).to.equal('/ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD\n')

const out2 = await ipfs('bootstrap list')
expect(out2).to.equal(defaultList.join('\n') + '\n')
})

it('rm all bootstrap nodes', function () {
it('rm all bootstrap nodes', async function () {
this.timeout(40 * 1000)

return ipfs('bootstrap rm --all').then((out) => {
expect(out).to.equal('')
return ipfs('bootstrap list')
}).then((out) => {
expect(out).to.equal('')
})
const out = await ipfs('bootstrap rm --all')
expect(out).to.equal('')

const out2 = await ipfs('bootstrap list')
expect(out2).to.equal('')
})
}))
7 changes: 3 additions & 4 deletions test/cli/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ describe('commands', () => runOnAndOff((thing) => {
ipfs = thing.ipfs
})

it('list the commands', () => {
return ipfs('commands').then((out) => {
expect(out.split('\n')).to.have.length(commandCount + 1)
})
it('list the commands', async () => {
const out = await ipfs('commands')
expect(out.split('\n')).to.have.length(commandCount + 1)
})
}))
Loading