@@ -3,39 +3,48 @@ package encodingcom
3
3
import (
4
4
"net/http"
5
5
"net/http/httptest"
6
-
7
- "gopkg.in/check.v1 "
6
+ "reflect"
7
+ "testing "
8
8
)
9
9
10
- func ( s * S ) TestAPIStatus (c * check. C ) {
10
+ func TestAPIStatus (t * testing. T ) {
11
11
server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
12
12
w .Write ([]byte (`{"status":"Encoding Queue Processing Delays","status_code":"queue_slow","incident":"Our encoding queue is processing slower than normal. Check back for updates."}` ))
13
13
}))
14
14
defer server .Close ()
15
15
resp , err := APIStatus (server .URL )
16
- c .Assert (err , check .IsNil )
17
- c .Assert (* resp , check .DeepEquals , APIStatusResponse {
16
+ if err != nil {
17
+ t .Fatal (err )
18
+ }
19
+ expectedResp := APIStatusResponse {
18
20
Status : "Encoding Queue Processing Delays" ,
19
21
StatusCode : "queue_slow" ,
20
22
Incident : "Our encoding queue is processing slower than normal. Check back for updates." ,
21
- })
23
+ }
24
+ if ! reflect .DeepEqual (* resp , expectedResp ) {
25
+ t .Errorf ("wrong response returned\n want %#v\n got %#v" , expectedResp , * resp )
26
+ }
22
27
}
23
28
24
- func ( s * S ) TestAPIStatusFailToConnect (c * check. C ) {
29
+ func TestAPIStatusFailToConnect (t * testing. T ) {
25
30
_ , err := APIStatus ("http://192.0.2.13:8080" )
26
- c .Assert (err , check .NotNil )
31
+ if err == nil {
32
+ t .Fatal ("unexpected <nil> error" )
33
+ }
27
34
}
28
35
29
- func ( s * S ) TestAPIStatusInvalidResponse (c * check. C ) {
36
+ func TestAPIStatusInvalidResponse (t * testing. T ) {
30
37
server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
31
38
w .Write ([]byte (`{not a valid json}` ))
32
39
}))
33
40
defer server .Close ()
34
41
_ , err := APIStatus (server .URL )
35
- c .Assert (err , check .NotNil )
42
+ if err == nil {
43
+ t .Fatal ("unexpected <nil> error" )
44
+ }
36
45
}
37
46
38
- func ( s * S ) TestAPIStatusOK (c * check. C ) {
47
+ func TestAPIStatusOK (t * testing. T ) {
39
48
var tests = []struct {
40
49
input string
41
50
want bool
@@ -47,8 +56,12 @@ func (s *S) TestAPIStatusOK(c *check.C) {
47
56
{"pc_queue_slow" , false },
48
57
}
49
58
for _ , test := range tests {
50
- status := APIStatusResponse {StatusCode : test .input }
51
- got := status .OK ()
52
- c .Check (got , check .Equals , test .want )
59
+ t .Run (test .input , func (t * testing.T ) {
60
+ status := APIStatusResponse {StatusCode : test .input }
61
+ got := status .OK ()
62
+ if got != test .want {
63
+ t .Errorf ("wrong status returned\n want %v\n got %v" , test .want , got )
64
+ }
65
+ })
53
66
}
54
67
}
0 commit comments