Skip to content

Commit b53a9f1

Browse files
Support reset_peer toxic (#6)
* Support reset_peer toxic Besides adding the new toxic, this commit removes a number of deprecated libraries and tools from the project. The `requests` library was replaced by `axios` which is actively maintained. The development tools used in this project were also outdated. `tslint` was replaced by `eslint` and `ava` was replaced by `jest`. The `tslint` migration as well as the `ava` migration were conducted mostly automatic with only a few manual modifications. * Support limit_data toxic and add documentation for public API
1 parent 5adff63 commit b53a9f1

24 files changed

+8085
-707
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.tsconfig.json
2+
example-code/

.eslintrc.js

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
👋 Hi! This file was autogenerated by tslint-to-eslint-config.
3+
https://github.com/typescript-eslint/tslint-to-eslint-config
4+
5+
It represents the closest reasonable ESLint configuration to this
6+
project's original TSLint configuration.
7+
8+
We recommend eventually switching this configuration to extend from
9+
the recommended rulesets in typescript-eslint.
10+
https://github.com/typescript-eslint/tslint-to-eslint-config/blob/master/docs/FAQs.md
11+
12+
Happy linting! 💖
13+
*/
14+
module.exports = {
15+
"env": {
16+
"browser": true,
17+
"es6": true
18+
},
19+
"parser": "@typescript-eslint/parser",
20+
"parserOptions": {
21+
"project": "tsconfig.json",
22+
"sourceType": "module"
23+
},
24+
"plugins": [
25+
"@typescript-eslint",
26+
"@typescript-eslint/tslint"
27+
],
28+
"root": true,
29+
"rules": {
30+
"@typescript-eslint/indent": "error",
31+
"@typescript-eslint/member-delimiter-style": [
32+
"error",
33+
{
34+
"multiline": {
35+
"delimiter": "semi",
36+
"requireLast": true
37+
},
38+
"singleline": {
39+
"delimiter": "semi",
40+
"requireLast": false
41+
}
42+
}
43+
],
44+
"@typescript-eslint/naming-convention": [
45+
"error",
46+
{
47+
"selector": "variable",
48+
"format": [
49+
"camelCase",
50+
"UPPER_CASE"
51+
],
52+
"leadingUnderscore": "forbid",
53+
"trailingUnderscore": "forbid"
54+
}
55+
],
56+
"@typescript-eslint/prefer-namespace-keyword": "error",
57+
"@typescript-eslint/quotes": [
58+
"error",
59+
"double"
60+
],
61+
"@typescript-eslint/semi": [
62+
"error",
63+
"always"
64+
],
65+
"@typescript-eslint/type-annotation-spacing": "error",
66+
"brace-style": [
67+
"error",
68+
"1tbs"
69+
],
70+
"eqeqeq": [
71+
"error",
72+
"smart"
73+
],
74+
"id-denylist": [
75+
"error",
76+
"any",
77+
"Number",
78+
"number",
79+
"String",
80+
"string",
81+
"Boolean",
82+
"boolean",
83+
"Undefined",
84+
"undefined"
85+
],
86+
"id-match": "error",
87+
"indent": "off",
88+
"no-eval": "error",
89+
"no-redeclare": "error",
90+
"no-trailing-spaces": "error",
91+
"no-underscore-dangle": "error",
92+
"no-var": "error",
93+
"quotes": "off",
94+
"semi": "off",
95+
"spaced-comment": [
96+
"error",
97+
"always",
98+
{
99+
"markers": [
100+
"/"
101+
]
102+
}
103+
],
104+
"@typescript-eslint/tslint/config": [
105+
"error",
106+
{
107+
"rules": {
108+
"object-literal-sort-keys": true,
109+
"whitespace": [
110+
true,
111+
"check-branch",
112+
"check-decl",
113+
"check-operator",
114+
"check-separator",
115+
"check-type"
116+
]
117+
}
118+
}
119+
]
120+
}
121+
};

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ node_modules
22
npm-debug.log
33
.vscode
44

5-
dist
5+
dist
6+
7+
.idea

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,10 @@ getToxic("bandwidth", <Bandwidth>{ rate: 1000 })
8383

8484
## Documentation
8585
Additional examples can be found in the `examples` directory for expected usage.
86+
87+
## Docker setup for development and testing
88+
89+
A Toxiproxy instance is needed to run the tests. The easiest way to get one is to use the official Docker image which will make it available on port 8474. The URL (http://localhost:8474) is hard-coded in the tests.
90+
```
91+
docker run --rm -p 8474:8474 ghcr.io/shopify/toxiproxy:latest
92+
```

example-code/typescript-example.ts

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
import {
2-
Toxiproxy,
3-
ICreateProxyBody,
4-
Toxic, ICreateToxicBody, Bandwidth
5-
} from "../dist/";
1+
import { Bandwidth, ICreateProxyBody, ICreateToxicBody, Toxic } from "../src";
2+
import Toxiproxy from "../src/Toxiproxy";
3+
64

75
const getToxic = async <T>(type: string, attributes: T): Promise<Toxic<T>> => {
8-
const toxiproxy = new Toxiproxy("http://localhost:8474");
9-
const proxyBody = <ICreateProxyBody>{
10-
listen: "localhost:0",
11-
name: "ihsw_test_redis_master",
12-
upstream: "localhost:6379"
13-
};
14-
const proxy = await toxiproxy.createProxy(proxyBody);
6+
const toxiproxy = new Toxiproxy("http://localhost:8474");
7+
const proxyBody = <ICreateProxyBody>{
8+
listen: "localhost:0",
9+
name: "ihsw_test_redis_master",
10+
upstream: "localhost:6379"
11+
};
12+
const proxy = await toxiproxy.createProxy(proxyBody);
1513

16-
const toxicBody = <ICreateToxicBody<T>>{
17-
attributes: attributes,
18-
type: type
19-
};
20-
return await proxy.addToxic(new Toxic(proxy, toxicBody));
14+
const toxicBody = <ICreateToxicBody<T>>{
15+
attributes: attributes,
16+
type: type
17+
};
18+
return await proxy.addToxic(new Toxic(proxy, toxicBody));
2119
};
2220

2321
// { attributes: { rate: 1000 },
@@ -26,5 +24,5 @@ const getToxic = async <T>(type: string, attributes: T): Promise<Toxic<T>> => {
2624
// toxicity: 1,
2725
// type: 'bandwidth' }
2826
getToxic("bandwidth", <Bandwidth>{ rate: 1000 })
29-
.then((toxic) => console.log(toxic.toJson()))
30-
.catch(console.error);
27+
.then((toxic) => console.log(toxic.toJson()))
28+
.catch(console.error);

jest.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
rootDir: 'src',
6+
};

0 commit comments

Comments
 (0)