-
Notifications
You must be signed in to change notification settings - Fork 23
/
tests_test.go
63 lines (56 loc) · 1.98 KB
/
tests_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package thousandeyes
import (
"github.com/stretchr/testify/assert"
"net/http"
"testing"
)
func TestClient_GetTestStatusCode(t *testing.T) {
setup()
out := `{"tests":[]}`
var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"}
mux.HandleFunc("/tests/1.json", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "GET", r.Method)
w.WriteHeader(http.StatusBadRequest)
_, _ = w.Write([]byte(out))
})
_, err := client.GetTest(1)
teardown()
assert.ErrorContains(t, err, "Response did not contain formatted error: %!s(<nil>). HTTP response code: 400")
}
func TestClient_GetTestsStatusCode(t *testing.T) {
setup()
out := `{"tests":[]}`
var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"}
mux.HandleFunc("/tests.json", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "GET", r.Method)
w.WriteHeader(http.StatusBadRequest)
_, _ = w.Write([]byte(out))
})
_, err := client.GetTests()
teardown()
assert.ErrorContains(t, err, "Response did not contain formatted error: %!s(<nil>). HTTP response code: 400")
}
func TestClient_GetGenericTestsJsonError(t *testing.T) {
out := `{"tests": [test]}`
setup()
var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"}
mux.HandleFunc("/tests.json", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "GET", r.Method)
_, _ = w.Write([]byte(out))
})
_, err := client.GetTests()
assert.Error(t, err)
assert.EqualError(t, err, "could not decode JSON response: invalid character 'e' in literal true (expecting 'r')")
}
func TestClient_GetGenericTestJsonError(t *testing.T) {
out := `{"tests": [test]}`
setup()
var client = &Client{APIEndpoint: server.URL, AuthToken: "foo"}
mux.HandleFunc("/tests/1.json", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "GET", r.Method)
_, _ = w.Write([]byte(out))
})
_, err := client.GetTest(1)
assert.Error(t, err)
assert.EqualError(t, err, "could not decode JSON response: invalid character 'e' in literal true (expecting 'r')")
}