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

client.Populate assign client to proxy #291

Merged
merged 4 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Store all the executable `main` packages in `cmd` folder. (#335, @miry)
* Extract common test helpers to own files. (#336, @miry)
* Client: Allow HTTPS endpoints. (#338, @chen-anders)
* client.Populate assign client to proxy. (#291, @hellodudu)

# [2.2.0]

Expand Down
30 changes: 30 additions & 0 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,36 @@ func TestPopulateProxyWithBadDataShouldReturnError(t *testing.T) {
})
}

func TestPopulateAddToxic(t *testing.T) {
WithServer(t, func(addr string) {
testProxies, err := client.Populate([]tclient.Proxy{
{
Name: "one",
Listen: "localhost:7070",
Upstream: "localhost:7171",
Enabled: true,
},
})

if err != nil {
t.Fatal("Unable to populate:", err)
}

if len(testProxies) != 1 {
t.Fatalf("Wrong number of proxies returned: %d != %d", len(testProxies), 1)
}

if testProxies[0].Name != "one" {
t.Fatalf("Wrong proxy name returned: %s != one", testProxies[0].Name)
}

_, err = testProxies[0].AddToxic("", "latency", "downstream", 1, nil)
if err != nil {
t.Fatal("Failed to AddToxic.")
}
})
}

func TestListingProxies(t *testing.T) {
WithServer(t, func(addr string) {
_, err := client.CreateProxy("mysql_master", "localhost:3310", "localhost:20001")
Expand Down
7 changes: 7 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ func (client *Client) Populate(config []Proxy) ([]*Proxy, error) {

resp.Body = ioutil.NopCloser(&body)
err = checkError(resp, http.StatusCreated, "Populate")
if err != nil {
return proxies.Proxies, err
}

for _, proxy := range proxies.Proxies {
proxy.client = client
}
return proxies.Proxies, err
}

Expand Down