toxiproxy 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/bin/start-toxiproxy.sh +10 -2
- data/circle.yml +4 -0
- data/lib/toxiproxy.rb +25 -8
- data/lib/toxiproxy/toxic.rb +2 -2
- data/lib/toxiproxy/version.rb +1 -1
- data/test/test_helper.rb +2 -0
- data/test/toxiproxy_test.rb +31 -0
- data/toxiproxy.gemspec +1 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c94b91428b8f1e4b982ae184a2e022748eb7902
|
4
|
+
data.tar.gz: abe80ecccc2bb359a74f2614403316741a208c72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84344059667bddf413e3521cb7cdd35ee99fdda1e9d80f50311ce5916dc5dfcf8117420fe7b89451df799905d731f8d7b67193bc8c83106871a274e830a5316b
|
7
|
+
data.tar.gz: bb9a1bec25d40ae9062823a72fd92b4a4e21ec9ffd869e9bbc0a6d3439324addaeeae0b29d59caeed7c9dde0cf8f7e0fd87bf6736c31f178edca510a2285885a
|
data/README.md
CHANGED
@@ -93,7 +93,7 @@ Toxiproxy.populate([{
|
|
93
93
|
|
94
94
|
This will create the proxies passed, or replace the proxies if they already exist in Toxiproxy.
|
95
95
|
It's recommended to do this early as early in boot as possible, see the
|
96
|
-
[Toxiproxy README](https://github.com/shopify/toxiproxy#
|
96
|
+
[Toxiproxy README](https://github.com/shopify/toxiproxy#usage). If you have many
|
97
97
|
proxies, we recommend storing the Toxiproxy configs in a configuration file and
|
98
98
|
deserializing it into `Toxiproxy.populate`.
|
99
99
|
|
data/bin/start-toxiproxy.sh
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
#!/bin/bash -e
|
2
2
|
|
3
|
-
VERSION='v2.0.
|
3
|
+
VERSION='v2.0.0'
|
4
4
|
TOXIPROXY_LOG_DIR=${CIRCLE_ARTIFACTS:-'/tmp'}
|
5
5
|
|
6
|
+
if [[ "$OSTYPE" == "linux"* ]]; then
|
7
|
+
DOWNLOAD_TYPE="linux-amd64"
|
8
|
+
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
9
|
+
DOWNLOAD_TYPE="darwin-amd64"
|
10
|
+
fi
|
11
|
+
|
12
|
+
echo "[dowload toxiproxy for $DOWNLOAD_TYPE]"
|
13
|
+
curl --silent -L https://github.com/Shopify/toxiproxy/releases/download/$VERSION/toxiproxy-server-$DOWNLOAD_TYPE -o ./bin/toxiproxy-server
|
14
|
+
|
6
15
|
echo "[start toxiproxy]"
|
7
|
-
curl --silent -L https://github.com/Shopify/toxiproxy/releases/download/$VERSION/toxiproxy-server-linux-amd64 -o ./bin/toxiproxy-server
|
8
16
|
chmod +x ./bin/toxiproxy-server
|
9
17
|
nohup bash -c "./bin/toxiproxy-server > ${TOXIPROXY_LOG_DIR}/toxiproxy.log 2>&1 &"
|
data/circle.yml
CHANGED
data/lib/toxiproxy.rb
CHANGED
@@ -31,7 +31,7 @@ class Toxiproxy
|
|
31
31
|
# Re-enables all proxies and disables all toxics.
|
32
32
|
def self.reset
|
33
33
|
request = Net::HTTP::Post.new("/reset")
|
34
|
-
response =
|
34
|
+
response = http_request(request)
|
35
35
|
assert_response(response)
|
36
36
|
self
|
37
37
|
end
|
@@ -40,7 +40,7 @@ class Toxiproxy
|
|
40
40
|
return false unless running?
|
41
41
|
|
42
42
|
request = Net::HTTP::Get.new("/version")
|
43
|
-
response =
|
43
|
+
response = http_request(request)
|
44
44
|
assert_response(response)
|
45
45
|
response.body
|
46
46
|
end
|
@@ -48,7 +48,7 @@ class Toxiproxy
|
|
48
48
|
# Returns a collection of all currently active Toxiproxies.
|
49
49
|
def self.all
|
50
50
|
request = Net::HTTP::Get.new("/proxies")
|
51
|
-
response =
|
51
|
+
response = http_request(request)
|
52
52
|
assert_response(response)
|
53
53
|
|
54
54
|
proxies = JSON.parse(response.body).map { |name, attrs|
|
@@ -148,7 +148,7 @@ class Toxiproxy
|
|
148
148
|
hash = {enabled: false}
|
149
149
|
request.body = hash.to_json
|
150
150
|
|
151
|
-
response =
|
151
|
+
response = http_request(request)
|
152
152
|
assert_response(response)
|
153
153
|
self
|
154
154
|
end
|
@@ -160,7 +160,7 @@ class Toxiproxy
|
|
160
160
|
hash = {enabled: true}
|
161
161
|
request.body = hash.to_json
|
162
162
|
|
163
|
-
response =
|
163
|
+
response = http_request(request)
|
164
164
|
assert_response(response)
|
165
165
|
self
|
166
166
|
end
|
@@ -174,7 +174,7 @@ class Toxiproxy
|
|
174
174
|
hash = {upstream: upstream, name: name, listen: listen, enabled: enabled}
|
175
175
|
request.body = hash.to_json
|
176
176
|
|
177
|
-
response =
|
177
|
+
response = http_request(request)
|
178
178
|
assert_response(response)
|
179
179
|
|
180
180
|
new = JSON.parse(response.body)
|
@@ -186,7 +186,7 @@ class Toxiproxy
|
|
186
186
|
# Destroys a Toxiproxy.
|
187
187
|
def destroy
|
188
188
|
request = Net::HTTP::Delete.new("/proxies/#{name}")
|
189
|
-
response =
|
189
|
+
response = http_request(request)
|
190
190
|
assert_response(response)
|
191
191
|
self
|
192
192
|
end
|
@@ -194,7 +194,7 @@ class Toxiproxy
|
|
194
194
|
# Returns an array of the current toxics for a direction.
|
195
195
|
def toxics
|
196
196
|
request = Net::HTTP::Get.new("/proxies/#{name}/toxics")
|
197
|
-
response =
|
197
|
+
response = http_request(request)
|
198
198
|
assert_response(response)
|
199
199
|
|
200
200
|
JSON.parse(response.body).map { |attrs|
|
@@ -211,6 +211,23 @@ class Toxiproxy
|
|
211
211
|
|
212
212
|
private
|
213
213
|
|
214
|
+
def self.http_request(request)
|
215
|
+
ensure_webmock_whitelists_toxiproxy if defined? WebMock
|
216
|
+
http.request(request)
|
217
|
+
end
|
218
|
+
|
219
|
+
def http_request(request)
|
220
|
+
self.class.http_request(request)
|
221
|
+
end
|
222
|
+
|
223
|
+
def self.ensure_webmock_whitelists_toxiproxy
|
224
|
+
endpoint = "#{uri.host}:#{uri.port}"
|
225
|
+
WebMock::Config.instance.allow ||= []
|
226
|
+
unless WebMock::Config.instance.allow.include?(endpoint)
|
227
|
+
WebMock::Config.instance.allow << endpoint
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
214
231
|
def self.uri
|
215
232
|
@uri ||= ::URI.parse(DEFAULT_URI)
|
216
233
|
end
|
data/lib/toxiproxy/toxic.rb
CHANGED
@@ -18,7 +18,7 @@ class Toxiproxy
|
|
18
18
|
|
19
19
|
request.body = as_json
|
20
20
|
|
21
|
-
response = Toxiproxy.
|
21
|
+
response = Toxiproxy.http_request(request)
|
22
22
|
Toxiproxy.assert_response(response)
|
23
23
|
|
24
24
|
json = JSON.parse(response.body)
|
@@ -30,7 +30,7 @@ class Toxiproxy
|
|
30
30
|
|
31
31
|
def destroy
|
32
32
|
request = Net::HTTP::Delete.new("/proxies/#{proxy.name}/toxics/#{name}")
|
33
|
-
response = Toxiproxy.
|
33
|
+
response = Toxiproxy.http_request(request)
|
34
34
|
Toxiproxy.assert_response(response)
|
35
35
|
self
|
36
36
|
end
|
data/lib/toxiproxy/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
data/test/toxiproxy_test.rb
CHANGED
@@ -426,8 +426,39 @@ class ToxiproxyTest < MiniTest::Unit::TestCase
|
|
426
426
|
end
|
427
427
|
end
|
428
428
|
|
429
|
+
def test_whitelists_webmock_when_allow_is_nil
|
430
|
+
with_webmock_enabled do
|
431
|
+
WebMock::Config.instance.allow = nil
|
432
|
+
Toxiproxy.version # This should initialize the list.
|
433
|
+
assert WebMock::Config.instance.allow.include?(@endpoint)
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
def test_whitelisting_webmock_does_not_override_other_configuration
|
438
|
+
with_webmock_enabled do
|
439
|
+
WebMock::Config.instance.allow = ['some-other-host']
|
440
|
+
Toxiproxy.version
|
441
|
+
# 'some-other-host' should not be overriden.
|
442
|
+
assert WebMock::Config.instance.allow.include?('some-other-host')
|
443
|
+
assert WebMock::Config.instance.allow.include?(@endpoint)
|
444
|
+
|
445
|
+
Toxiproxy.version
|
446
|
+
# Endpoint should not be duplicated.
|
447
|
+
assert_equal 1, WebMock::Config.instance.allow.count(@endpoint)
|
448
|
+
end
|
449
|
+
end
|
450
|
+
|
429
451
|
private
|
430
452
|
|
453
|
+
def with_webmock_enabled
|
454
|
+
WebMock.enable!
|
455
|
+
WebMock.disable_net_connect!
|
456
|
+
@endpoint = "#{Toxiproxy.uri.host}:#{Toxiproxy.uri.port}"
|
457
|
+
yield
|
458
|
+
ensure
|
459
|
+
WebMock.disable!
|
460
|
+
end
|
461
|
+
|
431
462
|
def assert_proxy_available(proxy)
|
432
463
|
connect_to_proxy proxy
|
433
464
|
end
|
data/toxiproxy.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toxiproxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Eskildsen
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-03-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -53,6 +53,20 @@ dependencies:
|
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: webmock
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
56
70
|
description: A Ruby library for controlling Toxiproxy. Can be used in resiliency testing.
|
57
71
|
email: simon.eskildsen@shopify.com
|
58
72
|
executables: []
|
@@ -95,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
109
|
version: '0'
|
96
110
|
requirements: []
|
97
111
|
rubyforge_project:
|
98
|
-
rubygems_version: 2.2
|
112
|
+
rubygems_version: 2.5.2
|
99
113
|
signing_key:
|
100
114
|
specification_version: 4
|
101
115
|
summary: Ruby library for Toxiproxy
|