Skip to content

Commit

Permalink
Fixed tests, added pump, updated deps (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Dec 18, 2018
1 parent dfd19bf commit a750665
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 189 deletions.
15 changes: 8 additions & 7 deletions package.json
Expand Up @@ -27,23 +27,24 @@
},
"homepage": "https://github.com/fastify/fastify-reply-from#readme",
"devDependencies": {
"fastify": "^1.11.2",
"got": "^9.2.1",
"fastify": "^1.13.2",
"got": "^9.4.0",
"h2url": "^0.1.2",
"msgpack5": "^4.2.0",
"msgpack5": "^4.2.1",
"nock": "^10.0.0",
"pre-commit": "^1.2.2",
"proxyquire": "^2.1.0",
"simple-get": "^3.0.3",
"snazzy": "^8.0.0",
"standard": "^12.0.1",
"tap": "^12.0.1"
"tap": "^12.1.1"
},
"dependencies": {
"end-of-stream": "^1.4.1",
"fastify-plugin": "^1.2.0",
"semver": "^5.5.1",
"fastify-plugin": "^1.3.0",
"pump": "^3.0.0",
"semver": "^5.6.0",
"tiny-lru": "^5.0.1",
"undici": "^0.3.2"
"undici": "^0.3.3"
}
}
58 changes: 25 additions & 33 deletions test/http2/full-post-http2.js
@@ -1,33 +1,33 @@
'use strict'

const t = require('tap')
const { test } = require('tap')
const Fastify = require('fastify')
const From = require('../..')
const got = require('got')

const instance = Fastify()
test('http -> http2', async function (t) {
const instance = Fastify()

t.tearDown(instance.close.bind(instance))
t.tearDown(instance.close.bind(instance))

const target = Fastify({
http2: true
})
const target = Fastify({
http2: true
})

target.post('/', (request, reply) => {
t.pass('request proxied')
t.deepEqual(request.body, { something: 'else' })
reply.code(200).header('x-my-header', 'hello!').send({
hello: 'world'
target.post('/', (request, reply) => {
t.pass('request proxied')
t.deepEqual(request.body, { something: 'else' })
reply.code(200).header('x-my-header', 'hello!').send({
hello: 'world'
})
})
})

instance.post('/', (request, reply) => {
reply.from()
})
instance.post('/', (request, reply) => {
reply.from()
})

t.tearDown(target.close.bind(target))
t.tearDown(target.close.bind(target))

async function run () {
await target.listen(0)

instance.register(From, {
Expand All @@ -37,20 +37,12 @@ async function run () {

await instance.listen(0)

t.test('http -> http2', async (t) => {
try {
const { headers, body, statusCode } = await got(`http://localhost:${instance.server.address().port}`, {
body: { something: 'else' },
json: true
})
t.equal(statusCode, 200)
t.equal(headers['x-my-header'], 'hello!')
t.match(headers['content-type'], /application\/json/)
t.deepEqual(body, { hello: 'world' })
} catch (err) {
t.error(err)
}
const { headers, body, statusCode } = await got(`http://localhost:${instance.server.address().port}`, {
body: { something: 'else' },
json: true
})
}

run()
t.equal(statusCode, 200)
t.equal(headers['x-my-header'], 'hello!')
t.match(headers['content-type'], /application\/json/)
t.deepEqual(body, { hello: 'world' })
})
63 changes: 30 additions & 33 deletions test/http2/http-http2.js
@@ -1,32 +1,32 @@
'use strict'

const t = require('tap')
const { test } = require('tap')
const Fastify = require('fastify')
const From = require('../..')
const got = require('got')

const instance = Fastify()
test('http -> http2', async (t) => {
const instance = Fastify()

t.tearDown(instance.close.bind(instance))
t.tearDown(instance.close.bind(instance))

const target = Fastify({
http2: true
})
const target = Fastify({
http2: true
})

target.get('/', (request, reply) => {
t.pass('request proxied')
reply.code(404).header('x-my-header', 'hello!').send({
hello: 'world'
target.get('/', (request, reply) => {
t.pass('request proxied')
reply.code(404).header('x-my-header', 'hello!').send({
hello: 'world'
})
})
})

instance.get('/', (request, reply) => {
reply.from()
})
instance.get('/', (request, reply) => {
reply.from()
})

t.tearDown(target.close.bind(target))
t.tearDown(target.close.bind(target))

async function run () {
await target.listen(0)

instance.register(From, {
Expand All @@ -36,20 +36,17 @@ async function run () {

await instance.listen(0)

t.test('http -> http2', async (t) => {
try {
await got(`http://localhost:${instance.server.address().port}`, {
rejectUnauthorized: false
})
} catch (err) {
t.equal(err.response.statusCode, 404)
t.equal(err.response.headers['x-my-header'], 'hello!')
t.match(err.response.headers['content-type'], /application\/json/)
t.deepEqual(JSON.parse(err.response.body), { hello: 'world' })
return
}
t.fail()
})
}

run()
try {
await got(`http://localhost:${instance.server.address().port}`, {
rejectUnauthorized: false
})
} catch (err) {
t.equal(err.response.statusCode, 404)
t.equal(err.response.headers['x-my-header'], 'hello!')
t.match(err.response.headers['content-type'], /application\/json/)
t.deepEqual(JSON.parse(err.response.body), { hello: 'world' })
return
}

t.fail()
})
51 changes: 23 additions & 28 deletions test/http2/http2-invalid-target.js
@@ -1,43 +1,38 @@
'use strict'

const t = require('tap')
const { test } = require('tap')
const Fastify = require('fastify')
const From = require('../..')
const got = require('got')

const instance = Fastify()
test('http -> http2', async (t) => {
const instance = Fastify()

t.tearDown(instance.close.bind(instance))
t.tearDown(instance.close.bind(instance))

instance.get('/', (request, reply) => {
reply.from()
})

async function run () {
instance.get('/', (request, reply) => {
reply.from()
})
instance.register(From, {
base: `http://abc.xyz1`,
http2: true
})

await instance.listen(0)

t.test('http -> http2', async (t) => {
try {
await got(`http://localhost:${instance.server.address().port}`, {
rejectUnauthorized: false
})
} catch (err) {
t.equal(err.response.statusCode, 503)
t.match(err.response.headers['content-type'], /application\/json/)
t.deepEqual(JSON.parse(err.response.body), {
statusCode: 503,
error: 'Service Unavailable',
message: 'Service Unavailable'
})
return
}
t.fail()
})
}

run()
try {
await got(`http://localhost:${instance.server.address().port}`, {
rejectUnauthorized: false
})
} catch (err) {
t.equal(err.response.statusCode, 503)
t.match(err.response.headers['content-type'], /application\/json/)
t.deepEqual(JSON.parse(err.response.body), {
statusCode: 503,
error: 'Service Unavailable',
message: 'Service Unavailable'
})
return
}
t.fail()
})
70 changes: 33 additions & 37 deletions test/http2/http2-target-crash.js
@@ -1,32 +1,32 @@
'use strict'

const t = require('tap')
const { test } = require('tap')
const Fastify = require('fastify')
const From = require('../..')
const got = require('got')

const instance = Fastify()
test('http -> http2 crash', async (t) => {
const instance = Fastify()

t.tearDown(instance.close.bind(instance))
t.tearDown(instance.close.bind(instance))

const target = Fastify({
http2: true
})
const target = Fastify({
http2: true
})

target.get('/', (request, reply) => {
t.pass('request proxied')
reply.code(200).send({
hello: 'world'
target.get('/', (request, reply) => {
t.pass('request proxied')
reply.code(200).send({
hello: 'world'
})
})
})

instance.get('/', (request, reply) => {
reply.from()
})
instance.get('/', (request, reply) => {
reply.from()
})

t.tearDown(target.close.bind(target))
t.tearDown(target.close.bind(target))

async function run () {
await target.listen(0)

instance.register(From, {
Expand All @@ -36,24 +36,20 @@ async function run () {

await instance.listen(0)

t.test('http -> http2 crash', async (t) => {
try {
await target.close()
await got(`http://localhost:${instance.server.address().port}`, {
rejectUnauthorized: false
})
} catch (err) {
t.equal(err.response.statusCode, 503)
t.match(err.response.headers['content-type'], /application\/json/)
t.deepEqual(JSON.parse(err.response.body), {
statusCode: 503,
error: 'Service Unavailable',
message: 'Service Unavailable'
})
return
}
t.fail()
})
}

run()
try {
await target.close()
await got(`http://localhost:${instance.server.address().port}`, {
rejectUnauthorized: false
})
} catch (err) {
t.equal(err.response.statusCode, 503)
t.match(err.response.headers['content-type'], /application\/json/)
t.deepEqual(JSON.parse(err.response.body), {
statusCode: 503,
error: 'Service Unavailable',
message: 'Service Unavailable'
})
return
}
t.fail()
})

0 comments on commit a750665

Please sign in to comment.