-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
101 lines (99 loc) · 2.8 KB
/
index.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
const rp = require("request-promise-native");
/**
* @type {Cypress.PluginConfig}
*/
// eslint-disable-next-line no-unused-vars
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
on("task", {
async "toxiproxy:createProxy"({ host, body }) {
console.log('%s, %s', host, body)
debugger;
let res = await rp.post({
body: JSON.parse(body),
json: true,
url: host + "/proxies",
headers: {
'User-Agent': 'PostmanRuntime/7.28.1'
}
});
return res;
},
async "toxiproxy:ProxyDown"({ host, proxyName }) {
console.log('%s, %s', host, proxyName)
debugger;
let body ={
enabled: false
}
let res = await rp.post({
body: body,
json: true,
url: host + "/proxies/"+proxyName,
headers: {
'User-Agent': 'PostmanRuntime/7.28.1'
}
});
return res;
},
async "toxiproxy:ProxyUp"({ host, proxyName }) {
console.log('%s, %s', host, proxyName)
debugger;
let body ={
enabled: true
}
let res = await rp.post({
body: body,
json: true,
url: host + "/proxies/"+proxyName,
headers: {
'User-Agent': 'PostmanRuntime/7.28.1'
}
});
return res;
},
async "toxiproxy:addToxic"({ host, proxyName, details }) {
// POST /proxies/{proxy}/toxics
let res = await rp.post({
body: JSON.parse(details),
json: true,
url: host + "/proxies/" + proxyName + "/toxics",
headers: {
'User-Agent': 'PostmanRuntime/7.28.1'
}
});
return res;
},
async "toxiproxy:removeToxic"({ host, proxyName, toxisName }) {
// DELETE /proxies/{proxy}/toxics/{toxic}
let res = await rp.delete({
url: host + "/proxies/" + proxyName + "/toxics/" + toxisName,
headers: {
'User-Agent': 'PostmanRuntime/7.28.1'
}
});
return res
},
async "toxiproxy:destroyProxy"({ host, name }) {
let res = await rp.delete({
url: host + "/proxies/" + name,
headers: {
'User-Agent': 'PostmanRuntime/7.28.1'
}
});
return res
}
})
}