forked from steinfletcher/apitest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassert_test.go
More file actions
32 lines (30 loc) · 828 Bytes
/
assert_test.go
File metadata and controls
32 lines (30 loc) · 828 Bytes
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
package apitest
import (
"net/http"
"testing"
)
func TestApiTest_Assert_StatusCodes(t *testing.T) {
tests := []struct {
responseStatus []int
assertFunc Assert
isSuccess bool
}{
{[]int{200, 312, 399}, IsSuccess, true},
{[]int{400, 404, 499}, IsClientError, true},
{[]int{500, 503}, IsServerError, true},
{[]int{400, 500}, IsSuccess, false},
{[]int{200, 500}, IsClientError, false},
{[]int{200, 400}, IsServerError, false},
}
for _, test := range tests {
for _, status := range test.responseStatus {
response := &http.Response{StatusCode: status}
err := test.assertFunc(response, nil)
if test.isSuccess && err != nil {
t.Fatalf("Expecteted nil but received %s", err)
} else if !test.isSuccess && err == nil {
t.Fatalf("Expected error but didn't receive one")
}
}
}
}