@@ -20,7 +20,7 @@ client api has changed:
20
20
down a proxy.
21
21
- ` proxy.ToxicsUpstream ` and ` proxy.ToxicsDownstream ` have been merged into a
22
22
single ` ActiveToxics ` list.
23
- - `proxy.Toxics()`` no longer requires a direction to be specified, and will
23
+ - ` proxy.Toxics() ` no longer requires a direction to be specified, and will
24
24
return toxics for both directions.
25
25
- ` proxy.SetToxic() ` has been replaced by ` proxy.AddToxic() ` ,
26
26
` proxy.UpdateToxic() ` , and ` proxy.RemoveToxic() ` .
@@ -91,21 +91,19 @@ proxy.Delete()
91
91
92
92
``` go
93
93
import (
94
- " net/http"
95
94
" testing"
96
95
" time"
97
96
98
97
toxiproxy " github.com/Shopify/toxiproxy/v2/client"
99
- " github.com/garyburd /redigo/redis"
98
+ " github.com/gomodule /redigo/redis"
100
99
)
101
100
102
101
var toxiClient *toxiproxy.Client
103
- var proxies map [string ]*toxiproxy.Proxy
104
102
105
103
func init () {
106
104
var err error
107
105
toxiClient = toxiproxy.NewClient (" localhost:8474" )
108
- proxies , err = toxiClient.Populate ([]toxiproxy.Proxy {{
106
+ _ , err = toxiClient.Populate ([]toxiproxy.Proxy {{
109
107
Name: " redis" ,
110
108
Listen: " localhost:26379" ,
111
109
Upstream: " localhost:6379" ,
@@ -119,8 +117,9 @@ func init() {
119
117
}
120
118
121
119
func TestRedisBackendDown (t *testing .T ) {
122
- proxies[" redis" ].Disable ()
123
- defer proxies[" redis" ].Enable ()
120
+ var proxy , _ = toxiClient.Proxy (" redis" )
121
+ proxy.Disable ()
122
+ defer proxy.Enable ()
124
123
125
124
// Test that redis is down
126
125
_ , err := redis.Dial (" tcp" , " :26379" )
@@ -130,10 +129,11 @@ func TestRedisBackendDown(t *testing.T) {
130
129
}
131
130
132
131
func TestRedisBackendSlow (t *testing .T ) {
133
- proxies[" redis" ].AddToxic (" " , " latency" , " " , 1 , toxiproxy.Attributes {
132
+ var proxy , _ = toxiClient.Proxy (" redis" )
133
+ proxy.AddToxic (" " , " latency" , " " , 1 , toxiproxy.Attributes {
134
134
" latency" : 1000 ,
135
135
})
136
- defer proxies[ " redis " ] .RemoveToxic (" latency_downstream" )
136
+ defer proxy .RemoveToxic (" latency_downstream" )
137
137
138
138
// Test that redis is slow
139
139
start := time.Now ()
@@ -149,17 +149,4 @@ func TestRedisBackendSlow(t *testing.T) {
149
149
t.Fatal (" Redis command did not take long enough:" , time.Since (start))
150
150
}
151
151
}
152
-
153
- func TestEphemeralProxy (t *testing .T ) {
154
- proxy , _ := toxiClient.CreateProxy (" test" , " " , " google.com:80" )
155
- defer proxy.Delete ()
156
-
157
- // Test connection through proxy.Listen
158
- resp , err := http.Get (" http://" + proxy.Listen )
159
- if err != nil {
160
- t.Fatal (err)
161
- } else if resp.StatusCode != 200 {
162
- t.Fatal (" Proxy to google failed:" , resp.StatusCode )
163
- }
164
- }
165
152
```
0 commit comments