Skip to content

Commit

Permalink
test: Add tests for extension handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Apr 8, 2016
1 parent 582f513 commit 8e30075
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
test/test-repo-for*

# Logs
logs
*.log
Expand Down
2 changes: 1 addition & 1 deletion test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const IPFSRepo = require('../src')
describe('IPFS Repo Tests on on Node.js', () => {
const testRepoPath = path.join(__dirname, 'test-repo')
const date = Date.now().toString()
const repoPath = testRepoPath + date
const repoPath = testRepoPath + '-for-' + date

before((done) => {
ncp(testRepoPath, repoPath, (err) => {
Expand Down
49 changes: 49 additions & 0 deletions test/repo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const fileA = isNode
? fs.readFileSync(process.cwd() + '/test/test-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data')
: require('buffer!./test-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data')

const fileAExt = isNode
? fs.readFileSync(process.cwd() + '/test/test-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.ext')
: require('buffer!./test-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.ext')

module.exports = function (repo) {
describe('IPFS Repo Tests', function () {
it('check if Repo exists', (done) => {
Expand Down Expand Up @@ -109,6 +113,7 @@ module.exports = function (repo) {

describe('datastore', function () {
const baseFileHash = 'QmVtU7ths96fMgZ8YSZAbKghyieq7AjxNdcqyVzxTt3qVe'
const baseExtFileHash = 'QmVtU7ths96fMgZ8YSZAbKghyieq7AjxNdcqyVzxTt3qVe'

it('reads block', function (done) {
const buf = new Buffer(base58.decode(baseFileHash))
Expand All @@ -120,6 +125,16 @@ module.exports = function (repo) {
}))
})

it('reads block, with custom extension', function (done) {
const buf = new Buffer(base58.decode(baseFileHash))
repo.datastore.createReadStream(buf, 'ext')
.pipe(bl((err, data) => {
expect(err).to.not.exist
expect(data.equals(fileAExt)).to.equal(true)
done()
}))
})

it('write a block', function (done) {
const rnd = 'QmVtU7ths96fMgZ8YSZAbKghyieq7AjxNdcqyVtesthash'
const mh = new Buffer(base58.decode(rnd))
Expand All @@ -132,6 +147,18 @@ module.exports = function (repo) {
}).end(data)
})

it('write a block with custom extension', function (done) {
const rnd = 'QmVtU7ths96fMgZ8YSZAbKghyieq7AjxNdcqyVtesthash'
const mh = new Buffer(base58.decode(rnd))
const data = new Buffer('Oh the data')

repo.datastore.createWriteStream(mh, 'ext', (err, metadata) => {
expect(err).to.not.exist
expect(metadata.key).to.equal('12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07605f55537ce990.ext')
done()
}).end(data)
})

it('block exists', function (done) {
const buf = new Buffer(base58.decode(baseFileHash))

Expand All @@ -142,6 +169,16 @@ module.exports = function (repo) {
})
})

it('block exists, with custom extension', function (done) {
const buf = new Buffer(base58.decode(baseExtFileHash))

repo.datastore.exists(buf, 'ext', (err, exists) => {
expect(err).to.not.exist
expect(exists).to.equal(true)
done()
})
})

it('check for non existent block', function (done) {
const buf = new Buffer('random buffer')

Expand All @@ -163,6 +200,18 @@ module.exports = function (repo) {
})
})
})

it('remove a block, with custom extension', function (done) {
const buf = new Buffer(base58.decode(baseExtFileHash))
repo.datastore.remove(buf, 'ext', (err) => {
expect(err).to.not.exist
repo.datastore.exists(buf, 'ext', (err, exists) => {
expect(err).to.not.exist
expect(exists).to.equal(false)
done()
})
})
})
})

describe('datastore-legacy', () => {})
Expand Down
Binary file not shown.

0 comments on commit 8e30075

Please sign in to comment.