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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3198b51c84d89ef6d0b26c989ee633e4def9c4e9
4
- data.tar.gz: 65dd1628c34e6e4ba4ff7b387b9f1136ff66cfa1
3
+ metadata.gz: 2c94b91428b8f1e4b982ae184a2e022748eb7902
4
+ data.tar.gz: abe80ecccc2bb359a74f2614403316741a208c72
5
5
  SHA512:
6
- metadata.gz: 4c91be80c0853f0ad1a8ce5b504f757a99e2b458c61e0a809da82c6918d8f796e8f51377d6580f100cde96b27b16adbf2f686befc67e2a0167c92a28b5582875
7
- data.tar.gz: b44f5c8d012507b5b4321c80f3ced96f19c9d33114941c6a7ef924b858ce6596324744d2c805aa494b23d049d7119e213d0928f3c100a2f944b0b38d1bd896b4
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#Usage). If you have many
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
 
@@ -1,9 +1,17 @@
1
1
  #!/bin/bash -e
2
2
 
3
- VERSION='v2.0.0rc2'
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
@@ -5,3 +5,7 @@ dependencies:
5
5
  test:
6
6
  override:
7
7
  - bundle exec rake test
8
+
9
+ machine:
10
+ ruby:
11
+ version: 2.4.0
@@ -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 = http.request(request)
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 = http.request(request)
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 = http.request(request)
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 = http.request(request)
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 = http.request(request)
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 = http.request(request)
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 = http.request(request)
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 = http.request(request)
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
@@ -18,7 +18,7 @@ class Toxiproxy
18
18
 
19
19
  request.body = as_json
20
20
 
21
- response = Toxiproxy.http.request(request)
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.http.request(request)
33
+ response = Toxiproxy.http_request(request)
34
34
  Toxiproxy.assert_response(response)
35
35
  self
36
36
  end
@@ -1,3 +1,3 @@
1
1
  class Toxiproxy
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -1,2 +1,4 @@
1
1
  require 'minitest/autorun'
2
2
  require_relative "../lib/toxiproxy"
3
+ require 'webmock/minitest'
4
+ WebMock.disable!
@@ -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
@@ -17,4 +17,5 @@ Gem::Specification.new do |spec|
17
17
  spec.add_development_dependency "bundler", "~> 1.3"
18
18
  spec.add_development_dependency "minitest"
19
19
  spec.add_development_dependency "rake"
20
+ spec.add_development_dependency "webmock"
20
21
  end
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.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: 2016-04-25 00:00:00.000000000 Z
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.3
112
+ rubygems_version: 2.5.2
99
113
  signing_key:
100
114
  specification_version: 4
101
115
  summary: Ruby library for Toxiproxy