-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsloop_test.go
121 lines (86 loc) · 2.25 KB
/
sloop_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package dawn
import (
"os"
"testing"
"time"
"github.com/go-dawn/dawn/config"
"github.com/gofiber/fiber/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
var (
m = mockModule{}
)
func Test_Sloop_New(t *testing.T) {
t.Parallel()
app := fiber.New()
s := New(Config{App: app}).AddModulers(m)
assert.Equal(t, app, s.app)
assert.Len(t, s.mods, 1)
assert.Equal(t, "anonymous", s.mods[0].String())
}
func Test_Sloop_Default(t *testing.T) {
t.Parallel()
config.Set("debug", true)
s := Default(fiber.Config{})
require.NotNil(t, s.app)
assert.Len(t, s.app.Stack()[0], 1)
}
func Test_Sloop_AddModulers(t *testing.T) {
t.Parallel()
s := New().AddModulers(m)
assert.Len(t, s.mods, 1)
assert.Equal(t, "anonymous", s.mods[0].String())
}
func Test_Sloop_Run(t *testing.T) {
t.Parallel()
assert.NotNil(t, New().Run(""))
s := New(Config{App: fiber.New()}).AddModulers(m)
go func() {
time.Sleep(time.Millisecond * 100)
assert.NoError(t, s.app.Shutdown())
}()
assert.NoError(t, s.Run(""))
}
func Test_Sloop_RunTls(t *testing.T) {
assert.NotNil(t, New().RunTls("", "", ""))
s := New(Config{App: fiber.New()})
t.Run("invalid addr", func(t *testing.T) {
t.Parallel()
assert.NotNil(t, s.RunTls(":99999", "./.github/testdata/ssl.pem", "./.github/testdata/ssl.key"))
})
t.Run("invalid ssl info", func(t *testing.T) {
t.Parallel()
assert.NotNil(t, s.RunTls("", "./.github/README.md", "./.github/README.md"))
})
t.Run("with ssl", func(t *testing.T) {
t.Parallel()
go func() {
time.Sleep(time.Millisecond * 100)
assert.NoError(t, s.app.Shutdown())
}()
assert.NoError(t, s.RunTls("", "./.github/testdata/ssl.pem", "./.github/testdata/ssl.key"))
})
}
func Test_Sloop_Shutdown(t *testing.T) {
t.Parallel()
require.NotNil(t, (&Sloop{}).Shutdown())
require.Nil(t, New(Config{App: fiber.New()}).Shutdown())
}
func Test_Sloop_Router(t *testing.T) {
t.Parallel()
require.Nil(t, (&Sloop{}).Router())
require.NotNil(t, New(Config{App: fiber.New()}).Router())
}
func Test_Sloop_Watch(t *testing.T) {
t.Parallel()
s := &Sloop{
sigCh: make(chan os.Signal, 1),
}
go s.Watch()
select {
case s.sigCh <- os.Interrupt:
case <-time.NewTimer(time.Second).C:
assert.Fail(t, "should receive signal")
}
}