-
Notifications
You must be signed in to change notification settings - Fork 3
/
util_test.go
35 lines (27 loc) · 865 Bytes
/
util_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
package main
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestUtil_GetStatusCode_Ok(t *testing.T) {
actual, err := GetStatusCode("https://www.google.co.jp/")
assert.NoError(t, err)
assert.Equal(t, 200, actual)
}
func TestUtil_GetStatusCode_HttpError(t *testing.T) {
actual, err := GetStatusCode("https://www.google.co.jp/aaa")
assert.NoError(t, err)
assert.Equal(t, 404, actual)
}
func TestUtil_GetStatusCode_NoSuchHost(t *testing.T) {
actual, err := GetStatusCode("https://aaaaaaaaaaaaaaa")
assert.Error(t, err)
assert.Equal(t, 0, actual)
}
func TestUtil_IsSuccessful(t *testing.T) {
assert.Equal(t, false, IsSuccessfulStatus(0))
assert.Equal(t, true, IsSuccessfulStatus(200))
assert.Equal(t, true, IsSuccessfulStatus(302))
assert.Equal(t, false, IsSuccessfulStatus(404))
assert.Equal(t, false, IsSuccessfulStatus(502))
}