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

Commit 3fc853f

Browse files
committed
chore: converted cli tests to async
1 parent 9ad9249 commit 3fc853f

31 files changed

+884
-1246
lines changed

test/cli/bitswap.js

+39-43
Original file line numberDiff line numberDiff line change
@@ -30,69 +30,65 @@ describe('bitswap', () => runOn((thing) => {
3030
})
3131
})
3232

33-
before(function (done) {
34-
const test = (cb) => {
35-
ipfs('bitswap wantlist')
36-
.then(out => cb(null, out.includes(key0) && out.includes(key1)))
37-
.catch(cb)
33+
before(async () => {
34+
const test = async () => {
35+
const out = await ipfs('bitswap wantlist')
36+
37+
return out.includes(key0) && out.includes(key1)
3838
}
3939

40-
waitFor(test, {
40+
await waitFor(test, {
4141
name: `${key0} and ${key1} to be wanted`,
4242
timeout: 60 * 1000
43-
}, done)
43+
})
4444
})
4545

46-
it('wantlist', function () {
47-
return ipfs('bitswap wantlist').then((out) => {
48-
expect(out).to.include(key0)
49-
expect(out).to.include(key1)
50-
})
46+
it('wantlist', async function () {
47+
const out = await ipfs('bitswap wantlist')
48+
expect(out).to.include(key0)
49+
expect(out).to.include(key1)
5150
})
5251

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

60-
it('wantlist peerid', function () {
59+
it('wantlist peerid', async function () {
6160
this.timeout(20 * 1000)
62-
return ipfs('bitswap wantlist ' + peerId).then((out) => {
63-
expect(out).to.eql('')
64-
})
61+
62+
const out = await ipfs('bitswap wantlist ' + peerId)
63+
expect(out).to.eql('')
6564
})
6665

67-
it('stat', function () {
66+
it('stat', async function () {
6867
this.timeout(20 * 1000)
6968

70-
return ipfs('bitswap stat').then((out) => {
71-
expect(out).to.include([
72-
'bitswap status',
73-
' blocks received: 0',
74-
' dup blocks received: 0',
75-
' dup data received: 0B',
76-
// We sometimes pick up partners while the tests run and the order of
77-
// wanted keys is not defined so our assertion ends here.
78-
' wantlist [2 keys]'
79-
].join('\n'))
80-
81-
expect(out).to.include(key0)
82-
expect(out).to.include(key1)
83-
})
69+
const out = await ipfs('bitswap stat')
70+
expect(out).to.include([
71+
'bitswap status',
72+
' blocks received: 0',
73+
' dup blocks received: 0',
74+
' dup data received: 0B',
75+
// We sometimes pick up partners while the tests run and the order of
76+
// wanted keys is not defined so our assertion ends here.
77+
' wantlist [2 keys]'
78+
].join('\n'))
79+
expect(out).to.include(key0)
80+
expect(out).to.include(key1)
8481
})
8582

86-
it('should get stats with wantlist CIDs encoded in specified base', function () {
83+
it('should get stats with wantlist CIDs encoded in specified base', async function () {
8784
this.timeout(20 * 1000)
88-
return ipfs('bitswap stat --cid-base=base64').then((out) => {
89-
expect(out).to.include(new CID(key1).toBaseEncodedString('base64'))
90-
})
85+
86+
const out = await ipfs('bitswap stat --cid-base=base64')
87+
expect(out).to.include(new CID(key1).toBaseEncodedString('base64'))
9188
})
9289

93-
it('unwant', function () {
94-
return ipfs('bitswap unwant ' + key0).then((out) => {
95-
expect(out).to.eql(`Key ${key0} removed from wantlist\n`)
96-
})
90+
it('unwant', async function () {
91+
const out = await ipfs('bitswap unwant ' + key0)
92+
expect(out).to.eql(`Key ${key0} removed from wantlist\n`)
9793
})
9894
}))

test/cli/block.js

+37-48
Original file line numberDiff line numberDiff line change
@@ -11,82 +11,71 @@ describe('block', () => runOnAndOff((thing) => {
1111
ipfs = thing.ipfs
1212
})
1313

14-
it('put', function () {
14+
it('put', async function () {
1515
this.timeout(40 * 1000)
16-
return ipfs('block put test/fixtures/test-data/hello').then((out) => {
17-
expect(out).to.eql('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp\n')
18-
})
16+
17+
const out = await ipfs('block put test/fixtures/test-data/hello')
18+
expect(out).to.eql('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp\n')
1919
})
2020

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

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

29-
it('should put and print CID encoded in specified base', function () {
28+
it('should put and print CID encoded in specified base', async function () {
3029
this.timeout(40 * 1000)
3130

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

37-
it('get', function () {
35+
it('get', async function () {
3836
this.timeout(40 * 1000)
3937

40-
return ipfs('block get QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp')
41-
.then((out) => expect(out).to.eql('hello world\n'))
38+
const out = await ipfs('block get QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp')
39+
expect(out).to.eql('hello world\n')
4240
})
4341

44-
it('get block from file without a final newline', function () {
42+
it('get block from file without a final newline', async function () {
4543
this.timeout(40 * 1000)
4644

47-
return ipfs('block put test/fixtures/test-data/no-newline').then((out) => {
48-
expect(out).to.eql('QmTwbQs4sGcCiPxV97SpbHS7QgmVg9SiKxcG1AcF1Ly2SL\n')
49-
return ipfs('block get QmTwbQs4sGcCiPxV97SpbHS7QgmVg9SiKxcG1AcF1Ly2SL')
50-
})
51-
.then((out) => expect(out).to.eql('there is no newline at end of this file'))
45+
const out = await ipfs('block put test/fixtures/test-data/no-newline')
46+
expect(out).to.eql('QmTwbQs4sGcCiPxV97SpbHS7QgmVg9SiKxcG1AcF1Ly2SL\n')
47+
48+
const out2 = await ipfs('block get QmTwbQs4sGcCiPxV97SpbHS7QgmVg9SiKxcG1AcF1Ly2SL')
49+
expect(out2).to.eql('there is no newline at end of this file')
5250
})
5351

54-
it('stat', function () {
52+
it('stat', async function () {
5553
this.timeout(40 * 1000)
5654

57-
return ipfs('block stat QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp')
58-
.then((out) => {
59-
expect(out).to.eql([
60-
'Key: QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp',
61-
'Size: 12'
62-
].join('\n') + '\n')
63-
})
55+
const out = await ipfs('block stat QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp')
56+
expect(out).to.eql([
57+
'Key: QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp',
58+
'Size: 12'
59+
].join('\n') + '\n')
6460
})
6561

66-
it('should stat and print CID encoded in specified base', function () {
62+
it('should stat and print CID encoded in specified base', async function () {
6763
this.timeout(80 * 1000)
6864

69-
return ipfs('block put test/fixtures/test-data/hello')
70-
.then((out) => {
71-
expect(out).to.eql('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp\n')
72-
return ipfs('block stat QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp --cid-base=base64')
73-
})
74-
.then((out) => {
75-
expect(out).to.eql([
76-
'Key: mAXASIKlIkE8vD0ebj4GXaUswGEsNLtHBzSoewPuF0pmhkqRH',
77-
'Size: 12'
78-
].join('\n') + '\n')
79-
})
65+
const out = await ipfs('block put test/fixtures/test-data/hello')
66+
expect(out).to.eql('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp\n')
67+
68+
const out2 = await ipfs('block stat QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp --cid-base=base64')
69+
expect(out2).to.eql([
70+
'Key: mAXASIKlIkE8vD0ebj4GXaUswGEsNLtHBzSoewPuF0pmhkqRH',
71+
'Size: 12'
72+
].join('\n') + '\n')
8073
})
8174

82-
it.skip('rm', function () {
75+
it.skip('rm', async function () {
8376
this.timeout(40 * 1000)
8477

85-
return ipfs('block rm QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp')
86-
.then((out) => {
87-
expect(out).to.eql(
88-
'removed QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp\n'
89-
)
90-
})
78+
const out = await ipfs('block rm QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp')
79+
expect(out).to.eql('removed QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp\n')
9180
})
9281
}))

test/cli/bootstrap.js

+24-27
Original file line numberDiff line numberDiff line change
@@ -57,50 +57,47 @@ describe('bootstrap', () => runOnAndOff((thing) => {
5757
'/ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD'
5858
]
5959

60-
it('add default', function () {
60+
it('add default', async function () {
6161
this.timeout(40 * 1000)
6262

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

68-
it('list the bootstrap nodes', function () {
67+
it('list the bootstrap nodes', async function () {
6968
this.timeout(40 * 1000)
7069

71-
return ipfs('bootstrap list').then((out) => {
72-
expect(out).to.equal(defaultList.join('\n') + '\n')
73-
})
70+
const out = await ipfs('bootstrap list')
71+
expect(out).to.equal(defaultList.join('\n') + '\n')
7472
})
7573

76-
it('add another bootstrap node', function () {
74+
it('add another bootstrap node', async function () {
7775
this.timeout(40 * 1000)
7876

79-
return ipfs('bootstrap add /ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD').then((out) => {
80-
expect(out).to.equal('/ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD\n')
81-
return ipfs('bootstrap list')
82-
}).then((out) => expect(out).to.equal(updatedList.join('\n') + '\n'))
77+
const out = await ipfs('bootstrap add /ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD')
78+
expect(out).to.equal('/ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD\n')
79+
80+
const out2 = await ipfs('bootstrap list')
81+
expect(out2).to.equal(updatedList.join('\n') + '\n')
8382
})
8483

85-
it('rm a bootstrap node', function () {
84+
it('rm a bootstrap node', async function () {
8685
this.timeout(40 * 1000)
8786

88-
return ipfs('bootstrap rm /ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD').then((out) => {
89-
expect(out).to.equal('/ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD\n')
90-
return ipfs('bootstrap list')
91-
}).then((out) => {
92-
expect(out).to.equal(defaultList.join('\n') + '\n')
93-
})
87+
const out = await ipfs('bootstrap rm /ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD')
88+
expect(out).to.equal('/ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD\n')
89+
90+
const out2 = await ipfs('bootstrap list')
91+
expect(out2).to.equal(defaultList.join('\n') + '\n')
9492
})
9593

96-
it('rm all bootstrap nodes', function () {
94+
it('rm all bootstrap nodes', async function () {
9795
this.timeout(40 * 1000)
9896

99-
return ipfs('bootstrap rm --all').then((out) => {
100-
expect(out).to.equal('')
101-
return ipfs('bootstrap list')
102-
}).then((out) => {
103-
expect(out).to.equal('')
104-
})
97+
const out = await ipfs('bootstrap rm --all')
98+
expect(out).to.equal('')
99+
100+
const out2 = await ipfs('bootstrap list')
101+
expect(out2).to.equal('')
105102
})
106103
}))

test/cli/commands.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ describe('commands', () => runOnAndOff((thing) => {
1313
ipfs = thing.ipfs
1414
})
1515

16-
it('list the commands', () => {
17-
return ipfs('commands').then((out) => {
18-
expect(out.split('\n')).to.have.length(commandCount + 1)
19-
})
16+
it('list the commands', async () => {
17+
const out = await ipfs('commands')
18+
expect(out.split('\n')).to.have.length(commandCount + 1)
2019
})
2120
}))

0 commit comments

Comments
 (0)