MCPcopy
hub / github.com/alibaba/anyproxy / testWrapper

Function testWrapper

test/spec_rule/rule_replace_response_header_spec.js:15–91  ·  view source on GitHub ↗
(protocol)

Source from the content-addressed store, hash-verified

13testWrapper('https');
14
15function testWrapper(protocol) {
16 describe('Rule replaceResponseHeader should be working in :' + protocol, () => {
17 let proxyServer;
18 let serverInstance;
19
20 beforeAll((done) => {
21 jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
22 printLog('Start server for rule_replace_response_header_spec');
23
24 serverInstance = new Server();
25
26 proxyServer = ProxyServerUtil.proxyServerWithRule(rule);
27
28 setTimeout(() => {
29 done();
30 }, 2000);
31 });
32
33 afterAll(() => {
34 serverInstance && serverInstance.close();
35 proxyServer && proxyServer.close();
36 printLog('Close server for rule_replace_response_header_spec');
37 });
38
39 it('Should replace the header in proxy if assertion is true', done => {
40 const url = generateUrl(protocol, '/test/normal_request1');
41 proxyGet(url)
42 .then(proxyRes => {
43 expect(proxyRes.statusCode).toEqual(200);
44 expect(proxyRes.headers.replacedheaderkey).toEqual('replacedHeader_value_in_rule');
45 expect(proxyRes.body).toEqual('body_normal_request1');
46
47 directGet(url)
48 .then(directRes => {
49 expect(directRes.statusCode).toEqual(200);
50 expect(directRes.headers.replacedheaderkey).toBeUndefined();
51 expect(directRes.body).toEqual(proxyRes.body);
52 done();
53 })
54 .catch(error => {
55 console.error('error happened in direct get: ', error);
56 done.fail('error happened in direct get');
57 });
58 })
59 .catch(error => {
60 console.error('error happened in proxy get: ', error);
61 done.fail('error happened in proxy get');
62 });
63 });
64
65 it('Should not replace the header in proxy if the assertion is false', done => {
66 const url = generateUrl(protocol, '/test/normal_request2');
67 proxyGet(url)
68 .then(proxyRes => {
69 expect(proxyRes.statusCode).toEqual(200);
70 expect(proxyRes.headers.replacedheaderkey).toBeUndefined();
71 expect(proxyRes.body).toEqual('body_normal_request2');
72

Calls 5

generateUrlFunction · 0.85
proxyGetFunction · 0.85
directGetFunction · 0.85
printLogFunction · 0.50
closeMethod · 0.45

Tested by

no test coverage detected