-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathchecked_http_client_test.go
More file actions
44 lines (34 loc) · 872 Bytes
/
checked_http_client_test.go
File metadata and controls
44 lines (34 loc) · 872 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
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"net/url"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCheckedHttpClientFailWithValidStatusCode(t *testing.T) {
u, err := url.Parse(testUrl)
assert.Nil(t, err)
r, err := newCheckedHttpClient(
newFakeHttpClient(
func(u *url.URL) (*fakeHttpResponse, error) {
return newFakeHttpResponse(200, testUrl, nil, nil), nil
},
),
statusCodeSet{{200, 201}: {}},
).Get(u, nil)
assert.Nil(t, err)
assert.NotNil(t, r)
}
func TestCheckedHttpClientFailWithInvalidStatusCode(t *testing.T) {
u, err := url.Parse(testUrl)
assert.Nil(t, err)
r, err := newCheckedHttpClient(
newFakeHttpClient(
func(u *url.URL) (*fakeHttpResponse, error) {
return newFakeHttpResponse(404, testUrl, nil, nil), nil
},
),
statusCodeSet{{200, 201}: {}},
).Get(u, nil)
assert.Nil(t, r)
assert.Equal(t, err.Error(), "404")
}