Open sirupsen opened 9 years ago
I'm interested in having a crack at this, but I'm only minimally familiar with Go.
What I'm doing in my current project is something like this:
func WithProxy(t *testing.T, proxy *toxiproxy.Proxy, f func(proxy *toxiproxy.Proxy)) {
proxy.Enabled = true
client := toxiproxy.NewClient("http://localhost:8474")
proxy = client.NewProxy(proxy)
err := proxy.Create()
if err != nil {
t.Error("Failed to create proxy: ", err)
}
defer proxy.Delete()
f(proxy)
}
func WithProxyDown(t *testing.T, proxy *toxiproxy.Proxy, f func()) {
err := proxy.Delete()
if err != nil {
t.Error("Failed to delete proxy: ", err)
}
defer proxy.Create()
f()
}
The current Go API is pretty low-level, something with closures or a context object would be great.