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

Commit 8063f6b

Browse files
kumavisdaviddias
authored andcommitted
feat: block get pipe fix (#903)
* tests - cli - explicitly check newline presence * cli - block.get - dont append newline * test - cli - block - add test for block without final newline
1 parent e2f371b commit 8063f6b

File tree

12 files changed

+51
-43
lines changed

12 files changed

+51
-43
lines changed

src/cli/commands/block/get.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ module.exports = {
1818
}
1919

2020
process.stdout.write(block.data)
21-
process.stdout.write('\n')
2221
})
2322
}
2423
}

test/cli/bitswap.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('bitswap', () => runOn((thing) => {
1818

1919
it('wantlist', () => {
2020
return ipfs('bitswap wantlist').then((out) => {
21-
expect(out).to.eql(key)
21+
expect(out).to.eql(key + '\n')
2222
})
2323
})
2424

@@ -33,7 +33,7 @@ describe('bitswap', () => runOn((thing) => {
3333
` ${key}`,
3434
' partners [0]',
3535
' '
36-
].join('\n'))
36+
].join('\n') + '\n')
3737
})
3838
})
3939
}))

test/cli/block.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,44 @@ describe('block', () => runOnAndOff((thing) => {
1313

1414
it('put', () => {
1515
return ipfs('block put test/test-data/hello').then((out) => {
16-
expect(out).to.eql('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp')
16+
expect(out).to.eql('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp\n')
1717
})
1818
})
1919

2020
it('put with flags, format and mhtype', () => {
2121
return ipfs('block put --format eth-block --mhtype keccak-256 test/test-data/eth-block')
2222
.then((out) =>
23-
expect(out).to.eql('z43AaGF23fmvRnDP56Ub9WcJCfzSfqtmzNCCvmz5eudT8dtdCDS'))
23+
expect(out).to.eql('z43AaGF23fmvRnDP56Ub9WcJCfzSfqtmzNCCvmz5eudT8dtdCDS\n'))
2424
})
2525

2626
it('get', () => {
2727
return ipfs('block get QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp')
2828
.then((out) => expect(out).to.eql('hello world\n'))
2929
})
3030

31+
it('get block from file without a final newline', () => {
32+
return ipfs('block put test/test-data/no-newline').then((out) => {
33+
expect(out).to.eql('QmTwbQs4sGcCiPxV97SpbHS7QgmVg9SiKxcG1AcF1Ly2SL\n')
34+
return ipfs('block get QmTwbQs4sGcCiPxV97SpbHS7QgmVg9SiKxcG1AcF1Ly2SL')
35+
})
36+
.then((out) => expect(out).to.eql('there is no newline at end of this file'))
37+
})
38+
3139
it('stat', () => {
3240
return ipfs('block stat QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp')
3341
.then((out) => {
3442
expect(out).to.eql([
3543
'Key: QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp',
3644
'Size: 12'
37-
].join('\n'))
45+
].join('\n') + '\n')
3846
})
3947
})
4048

4149
it.skip('rm', () => {
4250
return ipfs('block rm QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp')
4351
.then((out) => {
4452
expect(out).to.eql(
45-
'removed QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp'
53+
'removed QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp\n'
4654
)
4755
})
4856
})

test/cli/bootstrap.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,31 @@ describe('bootstrap', () => runOnAndOff((thing) => {
3939

4040
it('add default', () => {
4141
return ipfs('bootstrap add --default').then((out) => {
42-
expect(out).to.be.eql(defaultList.join('\n'))
42+
expect(out).to.be.eql(defaultList.join('\n') + '\n')
4343
})
4444
})
4545

4646
it('list the bootstrap nodes', () => {
4747
return ipfs('bootstrap list').then((out) => {
48-
expect(out).to.eql(defaultList.join('\n'))
48+
expect(out).to.eql(defaultList.join('\n') + '\n')
4949
})
5050
})
5151

5252
it('add another bootstrap node', () => {
5353
return ipfs('bootstrap add /ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD').then((out) => {
54-
expect(out).to.be.eql('/ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD')
54+
expect(out).to.be.eql('/ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD\n')
5555
return ipfs('bootstrap list')
5656
}).then((out) => {
57-
expect(out).to.be.eql(updatedList.join('\n'))
57+
expect(out).to.be.eql(updatedList.join('\n') + '\n')
5858
})
5959
})
6060

6161
it('rm a bootstrap node', () => {
6262
return ipfs('bootstrap rm /ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD').then((out) => {
63-
expect(out).to.be.eql('/ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD')
63+
expect(out).to.be.eql('/ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD\n')
6464
return ipfs('bootstrap list')
6565
}).then((out) => {
66-
expect(out).to.deep.equal(defaultList.join('\n'))
66+
expect(out).to.deep.equal(defaultList.join('\n') + '\n')
6767
})
6868
})
6969

test/cli/commands.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('commands', () => runOnAndOff((thing) => {
1515

1616
it('list the commands', () => {
1717
return ipfs('commands').then((out) => {
18-
expect(out.split('\n')).to.have.length(commandCount)
18+
expect(out.split('\n')).to.have.length(commandCount + 1)
1919
})
2020
})
2121
}))

test/cli/dag.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ describe('dag', () => runOnAndOff.off((thing) => {
1414
it('get', () => {
1515
// put test eth-block
1616
return ipfs('block put --format eth-block --mhtype keccak-256 test/test-data/eth-block').then((out) => {
17-
expect(out).to.eql('z43AaGF23fmvRnDP56Ub9WcJCfzSfqtmzNCCvmz5eudT8dtdCDS')
17+
expect(out).to.eql('z43AaGF23fmvRnDP56Ub9WcJCfzSfqtmzNCCvmz5eudT8dtdCDS\n')
1818
// lookup path on eth-block
1919
return ipfs('dag get z43AaGF23fmvRnDP56Ub9WcJCfzSfqtmzNCCvmz5eudT8dtdCDS/parentHash')
2020
}).then((out) => {
2121
let expectHash = new Buffer('c8c0a17305adea9bbb4b98a52d44f0c1478f5c48fc4b64739ee805242501b256', 'hex')
22-
expect(out).to.be.eql('0x' + expectHash.toString('hex'))
22+
expect(out).to.be.eql('0x' + expectHash.toString('hex') + '\n')
2323
})
2424
})
2525
}))

test/cli/files.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const runOnAndOff = require('../utils/on-and-off')
1111
describe('files', () => runOnAndOff((thing) => {
1212
let ipfs
1313
const readme = fs.readFileSync(path.join(process.cwd(), '/src/init-files/init-docs/readme'))
14-
.toString('utf-8').slice(0, -1)
14+
.toString('utf-8')
1515

1616
before(() => {
1717
ipfs = thing.ipfs
@@ -21,15 +21,15 @@ describe('files', () => runOnAndOff((thing) => {
2121
return ipfs('files add src/init-files/init-docs/readme')
2222
.then((out) => {
2323
expect(out)
24-
.to.eql('added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB readme')
24+
.to.eql('added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB readme\n')
2525
})
2626
})
2727

2828
it('add alias', () => {
2929
return ipfs('add src/init-files/init-docs/readme')
3030
.then((out) => {
3131
expect(out)
32-
.to.eql('added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB readme')
32+
.to.eql('added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB readme\n')
3333
})
3434
})
3535

@@ -123,7 +123,7 @@ describe('files', () => runOnAndOff((thing) => {
123123
'added QmYwUkwNwJN2cevwXKL48DRpbbjbdLWyyLANG3BKTtsTZ8 recursive-get-dir/blocks/CIQBE',
124124
'added QmQQHYDwAQms78fPcvx1uFFsfho23YJNoewfLbi9AtdyJ9 recursive-get-dir/blocks',
125125
'added QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2 recursive-get-dir'
126-
].join('\n'))
126+
].join('\n') + '\n')
127127
})
128128
})
129129

@@ -132,7 +132,7 @@ describe('files', () => runOnAndOff((thing) => {
132132
expect(out).to.be.eql([
133133
'added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB readme',
134134
'added QmapdaVPjHXdcswef82FnGQUauMNpk9xYFkLDZKgAxhMwq'
135-
].join('\n'))
135+
].join('\n') + '\n')
136136
})
137137
})
138138

@@ -154,11 +154,11 @@ describe('files', () => runOnAndOff((thing) => {
154154
return ipfs('files get QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB')
155155
.then((out) => {
156156
expect(out)
157-
.to.eql('Saving file(s) QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB')
157+
.to.eql('Saving file(s) QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB\n')
158158

159159
const file = path.join(process.cwd(), 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB')
160160

161-
expect(fs.readFileSync(file).toString().slice(0, -1)).to.eql(readme)
161+
expect(fs.readFileSync(file).toString()).to.eql(readme)
162162

163163
rimraf(file)
164164
})
@@ -168,11 +168,11 @@ describe('files', () => runOnAndOff((thing) => {
168168
return ipfs('get QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB')
169169
.then((out) => {
170170
expect(out)
171-
.to.eql('Saving file(s) QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB')
171+
.to.eql('Saving file(s) QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB\n')
172172

173173
const file = path.join(process.cwd(), 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB')
174174

175-
expect(fs.readFileSync(file).toString().slice(0, -1)).to.eql(readme)
175+
expect(fs.readFileSync(file).toString()).to.eql(readme)
176176

177177
rimraf(file)
178178
})
@@ -185,7 +185,7 @@ describe('files', () => runOnAndOff((thing) => {
185185
return ipfs('files get QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2')
186186
.then((out) => {
187187
expect(out).to.eql(
188-
'Saving file(s) QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2'
188+
'Saving file(s) QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2\n'
189189
)
190190

191191
const outDir = path.join(process.cwd(), 'QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2')

test/cli/object.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ describe('object', () => runOnAndOff((thing) => {
1515
it('new', () => {
1616
return ipfs('object new').then((out) => {
1717
expect(out).to.eql(
18-
'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n'
18+
'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n\n'
1919
)
2020
})
2121
})
2222

2323
it('new unixfs-dir', () => {
2424
return ipfs('object new unixfs-dir').then((out) => {
2525
expect(out).to.eql(
26-
'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn'
26+
'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn\n'
2727
)
2828
})
2929
})
@@ -39,7 +39,7 @@ describe('object', () => runOnAndOff((thing) => {
3939
it('put', () => {
4040
return ipfs('object put test/test-data/node.json').then((out) => {
4141
expect(out).to.eql(
42-
'added QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm'
42+
'added QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm\n'
4343
)
4444
})
4545
})
@@ -52,20 +52,20 @@ describe('object', () => runOnAndOff((thing) => {
5252
'LinksSize: 53',
5353
'DataSize: 7',
5454
'CumulativeSize: 68'
55-
].join('\n'))
55+
].join('\n') + '\n')
5656
})
5757
})
5858

5959
it('data', () => {
6060
return ipfs('object data QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm').then((out) => {
61-
expect(out).to.eql('another')
61+
expect(out).to.eql('another\n')
6262
})
6363
})
6464

6565
it('links', () => {
6666
return ipfs('object links QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm').then((out) => {
6767
expect(out).to.eql(
68-
'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V 8 some link'
68+
'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V 8 some link\n'
6969
)
7070
})
7171
})
@@ -74,31 +74,31 @@ describe('object', () => runOnAndOff((thing) => {
7474
it('append-data', () => {
7575
return ipfs('object patch append-data QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n test/test-data/badconfig').then((out) => {
7676
expect(out).to.eql(
77-
'QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6'
77+
'QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6\n'
7878
)
7979
})
8080
})
8181

8282
it('set-data', () => {
8383
return ipfs('object patch set-data QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6 test/test-data/badconfig').then((out) => {
8484
expect(out).to.eql(
85-
'QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6'
85+
'QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6\n'
8686
)
8787
})
8888
})
8989

9090
it('add-link', () => {
9191
return ipfs('object patch add-link QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n foo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn').then((out) => {
9292
expect(out).to.eql(
93-
'QmdVHE8fUD6FLNLugtNxqDFyhaCgdob372hs6BYEe75VAK'
93+
'QmdVHE8fUD6FLNLugtNxqDFyhaCgdob372hs6BYEe75VAK\n'
9494
)
9595
})
9696
})
9797

9898
it('rm-link', () => {
9999
return ipfs('object patch rm-link QmdVHE8fUD6FLNLugtNxqDFyhaCgdob372hs6BYEe75VAK foo').then((out) => {
100100
expect(out).to.eql(
101-
'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n'
101+
'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n\n'
102102
)
103103
})
104104
})

test/cli/swarm.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,32 +49,32 @@ describe('swarm', () => {
4949
describe('daemon on (through http-api)', () => {
5050
it('connect', () => {
5151
return ipfsA('swarm', 'connect', bMultiaddr).then((out) => {
52-
expect(out).to.eql(`connect ${bMultiaddr} success`)
52+
expect(out).to.eql(`connect ${bMultiaddr} success\n`)
5353
})
5454
})
5555

5656
it('peers', () => {
5757
return ipfsA('swarm peers').then((out) => {
58-
expect(out).to.be.eql(bMultiaddr)
58+
expect(out).to.be.eql(bMultiaddr + '\n')
5959
})
6060
})
6161

6262
it('addrs', () => {
6363
return ipfsA('swarm addrs').then((out) => {
64-
expect(out).to.have.length.above(0)
64+
expect(out).to.have.length.above(1)
6565
})
6666
})
6767

6868
it('addrs local', () => {
6969
return ipfsA('swarm addrs local').then((out) => {
70-
expect(out).to.have.length.above(0)
70+
expect(out).to.have.length.above(1)
7171
})
7272
})
7373

7474
it('disconnect', () => {
7575
return ipfsA('swarm', 'disconnect', bMultiaddr).then((out) => {
7676
expect(out).to.eql(
77-
`disconnect ${bMultiaddr} success`
77+
`disconnect ${bMultiaddr} success\n`
7878
)
7979
})
8080
})

test/cli/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('version', () => runOnAndOff((thing) => {
1515
it('get the version', () => {
1616
return ipfs('version').then((out) => {
1717
expect(out).to.be.eql(
18-
`js-ipfs version: ${pkgversion}`
18+
`js-ipfs version: ${pkgversion}\n`
1919
)
2020
})
2121
})

0 commit comments

Comments
 (0)