Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
feat(factory): use factory instead, also make files tests to not assu…
Browse files Browse the repository at this point in the history
…me that some files exist in the test repo
  • Loading branch information
daviddias committed Aug 10, 2016
1 parent f81a001 commit d12c8d5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 25 deletions.
2 changes: 1 addition & 1 deletion API/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Note that this operation will **not** spark the restart of any service, i.e: if

#### `config.replace`

> Adds or replaces a config value.
> Adds or replaces a config file.
##### `Go` **WIP**

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@
"greenkeeperio-bot <support@greenkeeper.io>",
"nginnever <ginneversource@gmail.com>"
]
}
}
9 changes: 6 additions & 3 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ module.exports = (common) => {
let ipfs

before((done) => {
common.setup((err, _ipfs) => {
common.setup((err, factory) => {
expect(err).to.not.exist
ipfs = _ipfs
done()
factory.spawnNode((err, node) => {
expect(err).to.not.exist
ipfs = node
done()
})
})
})

Expand Down
37 changes: 20 additions & 17 deletions src/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ module.exports = (common) => {
'files/ipfs.txt': fs.readFileSync(path.join(__dirname, './data/test-folder/files/ipfs.txt'))
}

common.setup((err, _ipfs) => {
common.setup((err, factory) => {
expect(err).to.not.exist
ipfs = _ipfs
done()
factory.spawnNode((err, node) => {
expect(err).to.not.exist
ipfs = node
done()
})
})
})

Expand Down Expand Up @@ -187,24 +190,24 @@ module.exports = (common) => {

describe('.cat', () => {
it('with a base58 string encoded multihash', (done) => {
const hash = 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB'
const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
ipfs.cat(hash, (err, stream) => {
expect(err).to.not.exist
stream.pipe(bl((err, data) => {
expect(err).to.not.exist
expect(data.toString()).to.contain('Check out some of the other files in this directory:')
expect(data.toString()).to.contain('Plz add me!')
done()
}))
})
})

it('with a multihash', (done) => {
const mhBuf = new Buffer(bs58.decode('QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB'))
const mhBuf = new Buffer(bs58.decode('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'))
ipfs.cat(mhBuf, (err, stream) => {
expect(err).to.not.exist
stream.pipe(bl((err, data) => {
expect(err).to.not.exist
expect(data.toString()).to.contain('Check out some of the other files in this directory:')
expect(data.toString()).to.contain('Plz add me!')
done()
}))
})
Expand Down Expand Up @@ -240,13 +243,13 @@ module.exports = (common) => {

describe('.cat', () => {
it('with a base58 multihash encoded string', () => {
const hash = 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB'
const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'

return ipfs.cat(hash)
.then((stream) => {
stream.pipe(bl((err, data) => {
expect(err).to.not.exist
expect(data.toString()).to.contain('Check out some of the other files in this directory:')
expect(data.toString()).to.contain('Plz add me!')
}))
})
})
Expand All @@ -268,12 +271,12 @@ module.exports = (common) => {
})

it('with a multihash', () => {
const hash = new Buffer(bs58.decode('QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB'))
const hash = new Buffer(bs58.decode('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'))
return ipfs.cat(hash)
.then((stream) => {
stream.pipe(bl((err, data) => {
expect(err).to.not.exist
expect(data.toString()).to.contain('Check out some of the other files in this directory:')
expect(data.toString()).to.contain('Plz add me!')
}))
})
})
Expand All @@ -282,31 +285,31 @@ module.exports = (common) => {

describe('.get', () => {
it('with a base58 encoded multihash', (done) => {
const hash = 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB'
const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
ipfs.files.get(hash, (err, stream) => {
expect(err).to.not.exist
stream.pipe(concat((files) => {
expect(err).to.not.exist
expect(files).to.be.length(1)
expect(files[0].path).to.equal(hash)
files[0].content.pipe(concat((content) => {
expect(content.toString()).to.contain('Check out some of the other files in this directory:')
expect(content.toString()).to.contain('Plz add me!')
done()
}))
}))
})
})

it('with a multihash', (done) => {
const hash = 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB'
const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
const mhBuf = new Buffer(bs58.decode(hash))
ipfs.files.get(mhBuf, (err, stream) => {
expect(err).to.not.exist
stream.pipe(concat((files) => {
expect(files).to.be.length(1)
expect(files[0].path).to.deep.equal(hash)
files[0].content.pipe(concat((content) => {
expect(content.toString()).to.contain('Check out some of the other files in this directory:')
expect(content.toString()).to.contain('Plz add me!')
done()
}))
}))
Expand Down Expand Up @@ -398,14 +401,14 @@ module.exports = (common) => {

describe('promise', () => {
it('with a base58 encoded string', (done) => {
const hash = 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB'
const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
ipfs.files.get(hash)
.then((stream) => {
stream.pipe(concat((files) => {
expect(files).to.be.length(1)
expect(files[0].path).to.equal(hash)
files[0].content.pipe(concat((content) => {
expect(content.toString()).to.contain('Check out some of the other files in this directory:')
expect(content.toString()).to.contain('Plz add me!')
done()
}))
}))
Expand Down
9 changes: 6 additions & 3 deletions src/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ module.exports = (common) => {
let ipfs

before((done) => {
common.setup((err, _ipfs) => {
common.setup((err, factory) => {
expect(err).to.not.exist
ipfs = _ipfs
done()
factory.spawnNode((err, node) => {
expect(err).to.not.exist
ipfs = node
done()
})
})
})

Expand Down

0 comments on commit d12c8d5

Please sign in to comment.