Skip to content

Commit e2ac02b

Browse files
committed
interop tests, woo!
1 parent 06f3c56 commit e2ac02b

File tree

9 files changed

+56
-7
lines changed

9 files changed

+56
-7
lines changed

src/unixfs-format.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,17 @@ function Data (type, data) {
5959
case 'metadata': type = unixfsData.DataType.Metadata; break
6060
case 'symlink': type = unixfsData.DataType.Symlink; break
6161
}
62+
var fileSize = this.fileSize()
63+
64+
if (fileSize === 0) {
65+
fileSize = undefined
66+
}
6267

6368
return unixfsData.encode({
6469
Type: type,
6570
Data: this.data,
66-
filesize: this.fileSize(),
67-
blocksizes: this.blockSizes
71+
filesize: fileSize,
72+
blocksizes: this.blockSizes.length > 0 ? this.blockSizes : undefined
6873
})
6974
}
7075
}

tests/test-data/directory.unixfs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+


tests/test-data/directory/file.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello UnixFS

tests/test-data/file.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello UnixFS

tests/test-data/file.txt.unixfs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Hello UnixFS
2+


tests/test-data/raw.unixfs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Hello UnixFS
2+


tests/test-data/symlink.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
file.txt

tests/test-data/symlink.txt.unixfs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
file.txt

tests/test-unixfs-format.js

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* globals describe, it */
22

33
const expect = require('chai').expect
4+
const fs = require('fs')
45

56
const UnixfsFormat = require('../src').format
67

@@ -89,10 +90,44 @@ describe('unixfs-format', () => {
8990
})
9091

9192
describe('interop', () => {
92-
it.skip('raw', (done) => {})
93-
it.skip('directory', (done) => {})
94-
it.skip('file', (done) => {})
95-
it.skip('metadata', (done) => {})
96-
it.skip('symlink', (done) => {})
93+
it('raw', (done) => {
94+
var raw = fs.readFileSync(__dirname + '/test-data/raw.unixfs')
95+
const unmarsheled = UnixfsFormat.unmarshal(raw)
96+
expect(unmarsheled.data).to.deep.equal(new Buffer('Hello UnixFS\n'))
97+
expect(unmarsheled.type).to.equal('file')
98+
expect(unmarsheled.marshal()).to.deep.equal(raw)
99+
done()
100+
})
101+
102+
it('directory', (done) => {
103+
var raw = fs.readFileSync(__dirname + '/test-data/directory.unixfs')
104+
const unmarsheled = UnixfsFormat.unmarshal(raw)
105+
expect(unmarsheled.data).to.deep.equal(undefined)
106+
expect(unmarsheled.type).to.equal('directory')
107+
expect(unmarsheled.marshal()).to.deep.equal(raw)
108+
done()
109+
})
110+
111+
it('file', (done) => {
112+
var raw = fs.readFileSync(__dirname + '/test-data/file.txt.unixfs')
113+
const unmarsheled = UnixfsFormat.unmarshal(raw)
114+
expect(unmarsheled.data).to.deep.equal(new Buffer('Hello UnixFS\n'))
115+
expect(unmarsheled.type).to.equal('file')
116+
expect(unmarsheled.marshal()).to.deep.equal(raw)
117+
done()
118+
})
119+
120+
it.skip('metadata', (done) => {
121+
})
122+
123+
it('symlink', (done) => {
124+
var raw = fs.readFileSync(__dirname + '/test-data/symlink.txt.unixfs')
125+
const unmarsheled = UnixfsFormat.unmarshal(raw)
126+
expect(unmarsheled.data).to.deep.equal(new Buffer('file.txt'))
127+
expect(unmarsheled.type).to.equal('symlink')
128+
// TODO: waiting on https://github.com/ipfs/js-ipfs-data-importing/issues/3#issuecomment-182440079
129+
// expect(unmarsheled.marshal()).to.deep.equal(raw)
130+
done()
131+
})
97132
})
98133
})

0 commit comments

Comments
 (0)