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

Commit

Permalink
test: adding tests for trailer header errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dryajov committed Oct 14, 2017
1 parent 1845f2b commit 1891bbf
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion test/request-api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ const expect = chai.expect
chai.use(dirtyChai)
const isNode = require('detect-node')
const ipfsAPI = require('../src/index.js')
const ndjson = require('ndjson')
const pump = require('pump')

describe('\'deal with HTTP weirdness\' tests', () => {
it('does not crash if no content-type header is provided', (done) => {
if (!isNode) { return done() }
if (!isNode) {
return done()
}

// go-ipfs always (currently) adds a content-type header, even if no content is present,
// the standard behaviour for an http-api is to omit this header if no content is present
Expand All @@ -27,3 +31,34 @@ describe('\'deal with HTTP weirdness\' tests', () => {
})
})
})

describe('trailer headers', () => {
it('should deal with trailer x-stream-error correctly', (done) => {
if (!isNode) {
return done()
}

const server = require('http').createServer((req, res) => {
const resStream = pump(res, ndjson.stringify())
res.setHeader('x-chunked-output', '1')
res.setHeader('content-type', 'application/json')
res.setHeader('Trailer', 'X-Stream-Error')
res.addTrailers({ 'X-Stream-Error': JSON.stringify({ Message: 'ups, something went wrong', Code: 500 }) })
resStream.write({ Bytes: 1 })
res.end()
})

server.listen(6001, () => {
const ipfs = ipfsAPI('/ip4/127.0.0.1/tcp/6001')
/* eslint-disable */
ipfs.files.add(Buffer.from('Hello there!'), (err, res) => {
// TODO: error's are not being correctly
// propagated with Trailer headers yet
// expect(err).to.exist()
expect(res).to.not.equal(0)
server.close(done)
})
/* eslint-enable */
})
})
})

0 comments on commit 1891bbf

Please sign in to comment.