Skip to content

Commit 754b6b6

Browse files
authored
Update client readme example to compile with previous API changes (#607)
* Update client readme example to compile with previous API changes * More cleanup
1 parent 85cd59a commit 754b6b6

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

client/README.md

+9-22
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ client api has changed:
2020
down a proxy.
2121
- `proxy.ToxicsUpstream` and `proxy.ToxicsDownstream` have been merged into a
2222
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
2424
return toxics for both directions.
2525
- `proxy.SetToxic()` has been replaced by `proxy.AddToxic()`,
2626
`proxy.UpdateToxic()`, and `proxy.RemoveToxic()`.
@@ -91,21 +91,19 @@ proxy.Delete()
9191

9292
```go
9393
import (
94-
"net/http"
9594
"testing"
9695
"time"
9796

9897
toxiproxy "github.com/Shopify/toxiproxy/v2/client"
99-
"github.com/garyburd/redigo/redis"
98+
"github.com/gomodule/redigo/redis"
10099
)
101100

102101
var toxiClient *toxiproxy.Client
103-
var proxies map[string]*toxiproxy.Proxy
104102

105103
func init() {
106104
var err error
107105
toxiClient = toxiproxy.NewClient("localhost:8474")
108-
proxies, err = toxiClient.Populate([]toxiproxy.Proxy{{
106+
_, err = toxiClient.Populate([]toxiproxy.Proxy{{
109107
Name: "redis",
110108
Listen: "localhost:26379",
111109
Upstream: "localhost:6379",
@@ -119,8 +117,9 @@ func init() {
119117
}
120118

121119
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()
124123

125124
// Test that redis is down
126125
_, err := redis.Dial("tcp", ":26379")
@@ -130,10 +129,11 @@ func TestRedisBackendDown(t *testing.T) {
130129
}
131130

132131
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{
134134
"latency": 1000,
135135
})
136-
defer proxies["redis"].RemoveToxic("latency_downstream")
136+
defer proxy.RemoveToxic("latency_downstream")
137137

138138
// Test that redis is slow
139139
start := time.Now()
@@ -149,17 +149,4 @@ func TestRedisBackendSlow(t *testing.T) {
149149
t.Fatal("Redis command did not take long enough:", time.Since(start))
150150
}
151151
}
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-
}
165152
```

0 commit comments

Comments
 (0)