This repository was archived by the owner on Feb 2, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy path6.nocache.test.js
65 lines (54 loc) · 1.51 KB
/
6.nocache.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* global describe, it */
'use strict'
const request = require('supertest')
const bodyParser = require('body-parser')
const expect = require('chai').expect
const pump = require('pump')
let gateway, service, close, proxy, gHttpServer
describe('no URLs cache', () => {
it('init', async () => {
const fastProxy = require('../index')({
base: 'http://127.0.0.1:3000',
cacheURLs: 0
})
close = fastProxy.close
proxy = fastProxy.proxy
expect(proxy instanceof Function).to.equal(true)
expect(close instanceof Function).to.equal(true)
})
it('init & start gateway', async () => {
// init gateway
gateway = require('restana')()
gateway.all('/service/*', function (req, res) {
proxy(req, res, req.url, {
onResponse (req, res, stream) {
pump(stream, res)
}
})
})
gHttpServer = await gateway.start(8080)
})
it('init & start remote service', async () => {
// init remote service
service = require('restana')()
service.use(bodyParser.json())
service.get('/service/headers', (req, res) => {
res.setHeader('url', req.url)
res.send()
})
await service.start(3000)
})
it('should 200 on GET /servive/headers', async () => {
await request(gHttpServer)
.get('/service/headers')
.expect(200)
.then((response) => {
expect(response.headers.url).to.equal('/service/headers')
})
})
it('close all', async () => {
close()
await gateway.close()
await service.close()
})
})