forked from webp-sh/webp_server_go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebp-server_test.go
75 lines (64 loc) · 1.78 KB
/
webp-server_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// webp_server_go - webp-server_test
// 2020-11-10 09:41
// Benny <[email protected]>
package main
import (
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"net"
"os"
"runtime"
"testing"
"time"
)
// due to test limit, we can't test for cli param part.
func TestLoadConfig(t *testing.T) {
c := loadConfig("./config.json")
assert.Equal(t, "./exhaust", c.ExhaustPath)
assert.Equal(t, "127.0.0.1", c.Host)
assert.Equal(t, "3333", c.Port)
assert.Equal(t, float32(80), c.Quality)
assert.Equal(t, "./pics", c.ImgPath)
assert.Equal(t, []string{"jpg", "png", "jpeg", "bmp"}, c.AllowedTypes)
}
func TestDeferInit(t *testing.T) {
// test initial value
assert.Equal(t, "", configPath)
assert.False(t, prefetch)
assert.Equal(t, false, dumpSystemd)
assert.Equal(t, false, dumpConfig)
assert.False(t, verboseMode)
}
func TestMainFunction(t *testing.T) {
// first test verbose mode
assert.False(t, verboseMode)
assert.Equal(t, log.GetLevel(), log.InfoLevel)
os.Args = append(os.Args, "-v", "-prefetch")
// run main function
go main()
time.Sleep(time.Second * 5)
// verbose, prefetch
assert.Equal(t, log.GetLevel(), log.DebugLevel)
assert.True(t, verboseMode)
assert.True(t, prefetch)
// test read config value
assert.Equal(t, "config.json", configPath)
assert.Equal(t, runtime.NumCPU(), jobs)
assert.Equal(t, false, dumpSystemd)
assert.Equal(t, false, dumpConfig)
// test port
conn, err := net.DialTimeout("tcp", net.JoinHostPort("127.0.0.1", "3333"), time.Second*2)
assert.Nil(t, err)
assert.NotNil(t, conn)
}
func TestProxySwitch(t *testing.T) {
// real proxy mode
assert.False(t, proxyMode)
config.ImgPath = "https://z.cn"
switchProxyMode()
assert.True(t, proxyMode)
// normal
config.ImgPath = os.TempDir()
switchProxyMode()
assert.False(t, proxyMode)
}