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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
28 changes: 8 additions & 20 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,15 @@ import (
"time"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small typo that can be fixed on line 23 here


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 +118,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 +130,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 +150,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)
}
}
Comment on lines -153 to -164

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're planning on cleaning up this test, we could probably get rid of the net/http import as well since this is the only test that uses it.

```
Loading