-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathutils_test.go
46 lines (34 loc) · 911 Bytes
/
utils_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
package rux
import (
"errors"
"os"
"testing"
"github.com/gookit/goutil/testutil/assert"
)
func TestHelper(t *testing.T) {
// resolveAddress
_ = os.Setenv("PORT", "")
addr := resolveAddress(nil)
assert.Eq(t, "0.0.0.0:8080", addr)
addr = resolveAddress([]string{"9090"})
assert.Eq(t, "0.0.0.0:9090", addr)
addr = resolveAddress([]string{":9090"})
assert.Eq(t, "0.0.0.0:9090", addr)
addr = resolveAddress([]string{"127.0.0.1:9090"})
assert.Eq(t, "127.0.0.1:9090", addr)
// use ENV for resolveAddress
mockEnvValue("PORT", "1234", func() {
addr = resolveAddress(nil)
assert.Eq(t, "0.0.0.0:1234", addr)
})
// debugPrintError
debugPrintError(errors.New("error msg"))
// parseAccept
ss := parseAccept("")
assert.Len(t, ss, 0)
ss = parseAccept(",")
assert.Len(t, ss, 0)
ss = parseAccept("application/json")
assert.Len(t, ss, 1)
assert.Eq(t, []string{"application/json"}, ss)
}