-
-
Notifications
You must be signed in to change notification settings - Fork 72
/
utils_unix_test.go
69 lines (53 loc) · 1.44 KB
/
utils_unix_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
//go:build !windows
// +build !windows
package atreugo
import (
"os"
"path"
"testing"
"github.com/savsgio/gotils/bytes"
"github.com/valyala/fasthttp/prefork"
)
func Test_chmodFileToSocket(t *testing.T) {
cwd, err := os.Getwd()
if err != nil {
t.Fatalf("os.Getwd() error: %v", err)
}
filepath := path.Join(cwd, "atreugo-test-"+string(bytes.Rand(make([]byte, 10)))+".sock")
f, err := os.Create(filepath)
if err != nil {
panic(err)
}
defer func() {
f.Close()
os.Remove(filepath)
}()
if err := chmodFileToSocket(filepath); err != nil {
t.Errorf("Unexpected error: %v", err)
}
if err := chmodFileToSocket("243sdf$T%&$/"); err == nil {
t.Errorf("Expected error for invalid file path")
}
}
func Test_newPreforkServer(t *testing.T) {
cfg := Config{
Logger: testLog,
GracefulShutdown: false,
}
t.Run("Normal", func(t *testing.T) {
s := New(cfg)
sPrefork := newPreforkServer(s).(*prefork.Prefork) // nolint:forcetypeassert
testPerforkServer(t, s, sPrefork)
if !isEqual(sPrefork.ServeFunc, s.Serve) {
t.Errorf("Prefork.ServeFunc == %p, want %p", sPrefork.ServeFunc, s.ServeGracefully)
}
})
t.Run("Graceful", func(t *testing.T) {
cfg.GracefulShutdown = true
s := New(cfg)
sPrefork := newPreforkServer(s).(*prefork.Prefork) // nolint:forcetypeassert
if !isEqual(sPrefork.ServeFunc, s.ServeGracefully) {
t.Errorf("Prefork.ServeFunc == %p, want %p", sPrefork.ServeFunc, s.ServeGracefully)
}
})
}