-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(agents):
GetAgents
client func and more tests (#13)
* feat(agents): `GetAgents` client func and more tests
- Loading branch information
William Fleming
authored
Feb 17, 2020
1 parent
c6eca40
commit 0d6a7e9
Showing
6 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package thousandeyes | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
func TestClient_GetAgents(t *testing.T) { | ||
out := `{"agents":[{"agentId": 1}, {"agentId": 2}]}` | ||
setup() | ||
var client = &Client{ApiEndpoint: server.URL, AuthToken: "foo"} | ||
mux.HandleFunc("/agents.json", func(w http.ResponseWriter, r *http.Request) { | ||
assert.Equal(t, "GET", r.Method) | ||
_, _ = w.Write([]byte(out)) | ||
}) | ||
|
||
// Define expected values from the API (based on the JSON we print out above) | ||
expected := Agents{ | ||
Agent{ | ||
AgentId: 1, | ||
}, | ||
Agent{ | ||
AgentId: 2, | ||
}, | ||
} | ||
res, err := client.GetAgents() | ||
teardown() | ||
assert.Nil(t, err) | ||
assert.Equal(t, &expected, res) | ||
} | ||
|
||
func TestClient_GetAgentsError(t *testing.T) { | ||
setup() | ||
var client = &Client{ApiEndpoint: server.URL, AuthToken: "foo"} | ||
mux.HandleFunc("/agents.json", func(w http.ResponseWriter, r *http.Request) { | ||
assert.Equal(t, "GET", r.Method) | ||
w.WriteHeader(http.StatusBadRequest) | ||
}) | ||
|
||
_, err := client.GetAgents() | ||
teardown() | ||
assert.Error(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters