From 754b6b6a65de288b09733604b4dfb5aca55b1892 Mon Sep 17 00:00:00 2001 From: Adam Becevello Date: Mon, 16 Dec 2024 11:03:51 -0500 Subject: [PATCH] Update client readme example to compile with previous API changes (#607) * Update client readme example to compile with previous API changes * More cleanup --- client/README.md | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/client/README.md b/client/README.md index 52c2b7d4..3bd6685e 100644 --- a/client/README.md +++ b/client/README.md @@ -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()`. @@ -91,21 +91,19 @@ proxy.Delete() ```go import ( - "net/http" "testing" "time" 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", @@ -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") @@ -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() @@ -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) - } -} ```