-
Notifications
You must be signed in to change notification settings - Fork 2
/
server_test.go
56 lines (47 loc) · 1.04 KB
/
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
package raiden_test
import (
"os"
"os/exec"
"syscall"
"testing"
"time"
"github.com/sev-2/raiden"
"github.com/stretchr/testify/assert"
)
func MockMiddlewareFn() raiden.MiddlewareFn {
return func(next raiden.RouteHandlerFn) raiden.RouteHandlerFn {
return nil
}
}
func TestServer_RegisterRoute(t *testing.T) {
conf := loadConfig()
s := raiden.NewServer(conf)
routes := []*raiden.Route{
{
Methods: []string{"GET"}, Path: "/",
},
}
s.RegisterRoute(routes)
assert.NotNil(t, s.Router)
}
func TestServer_Use(t *testing.T) {
conf := loadConfig()
s := raiden.NewServer(conf)
middleware := MockMiddlewareFn()
s.Use(middleware)
}
func TestServer_StartStop(t *testing.T) {
if os.Getenv("TEST_RUN") == "1" {
conf := loadConfig()
s := raiden.NewServer(conf)
s.Run()
return
}
cmd := exec.Command(os.Args[0], "-test.run=TestServer_StartStop")
cmd.Env = append(os.Environ(), "TEST_RUN=1")
err := cmd.Start()
assert.NoError(t, err)
time.Sleep(1 * time.Second)
err1 := cmd.Process.Signal(syscall.SIGTERM)
assert.NoError(t, err1)
}