Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update client readme example to compile with previous API changes #607

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 9 additions & 22 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ client api has changed:
down a proxy.
- `proxy.ToxicsUpstream` and `proxy.ToxicsDownstream` have been merged into a
single `ActiveToxics` list.
- `proxy.Toxics()`` no longer requires a direction to be specified, and will
- `proxy.Toxics()` no longer requires a direction to be specified, and will
return toxics for both directions.
- `proxy.SetToxic()` has been replaced by `proxy.AddToxic()`,
`proxy.UpdateToxic()`, and `proxy.RemoveToxic()`.
Expand Down Expand Up @@ -91,21 +91,19 @@ proxy.Delete()

```go
import (
"net/http"
"testing"
"time"
abecevello marked this conversation as resolved.
Show resolved Hide resolved

toxiproxy "github.com/Shopify/toxiproxy/v2/client"
"github.com/garyburd/redigo/redis"
"github.com/gomodule/redigo/redis"
)

var toxiClient *toxiproxy.Client
var proxies map[string]*toxiproxy.Proxy

func init() {
var err error
toxiClient = toxiproxy.NewClient("localhost:8474")
proxies, err = toxiClient.Populate([]toxiproxy.Proxy{{
_, err = toxiClient.Populate([]toxiproxy.Proxy{{
Name: "redis",
Listen: "localhost:26379",
Upstream: "localhost:6379",
Expand All @@ -119,8 +117,9 @@ func init() {
}

func TestRedisBackendDown(t *testing.T) {
proxies["redis"].Disable()
defer proxies["redis"].Enable()
var proxy, _ = toxiClient.Proxy("redis")
proxy.Disable()
defer proxy.Enable()

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

func TestRedisBackendSlow(t *testing.T) {
proxies["redis"].AddToxic("", "latency", "", 1, toxiproxy.Attributes{
var proxy, _ = toxiClient.Proxy("redis")
proxy.AddToxic("", "latency", "", 1, toxiproxy.Attributes{
"latency": 1000,
})
defer proxies["redis"].RemoveToxic("latency_downstream")
defer proxy.RemoveToxic("latency_downstream")

// Test that redis is slow
start := time.Now()
Expand All @@ -149,17 +149,4 @@ func TestRedisBackendSlow(t *testing.T) {
t.Fatal("Redis command did not take long enough:", time.Since(start))
}
}

func TestEphemeralProxy(t *testing.T) {
proxy, _ := toxiClient.CreateProxy("test", "", "google.com:80")
defer proxy.Delete()

// Test connection through proxy.Listen
resp, err := http.Get("http://" + proxy.Listen)
if err != nil {
t.Fatal(err)
} else if resp.StatusCode != 200 {
t.Fatal("Proxy to google failed:", resp.StatusCode)
}
}
abecevello marked this conversation as resolved.
Show resolved Hide resolved
```
Loading