-
Notifications
You must be signed in to change notification settings - Fork 0
/
smile_test.go
90 lines (76 loc) · 1.78 KB
/
smile_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
package smile
import (
"net/http/httptest"
"os"
"testing"
)
type smileController struct{}
func (t *smileController) PostFunc(c *Context) error {
c.WriteString("hello post")
return nil
}
func (t *smileController) GetFunc(c *Context) error {
c.WriteString("hello get")
return nil
}
func (t *smileController) WsFunc(c *Context) error {
c.WriteString("hello ws")
return nil
}
var sfc = &smileController{}
func TestSmile(t *testing.T) {
var startChan = make(chan int)
e := NewEngine("./examples/websocket/")
go func() {
go e.Run(":9999")
go e.RunTLS(":443", "cert.crt", "key.key")
startChan <- 1
}()
<-startChan
e.GzipOff()
e.GzipOn()
e.SetLoger(&Logger{os.Stdout, true})
e.SetRouteGroup(&RouteGroup{
GET: map[string]HandlerFunc{"func": sfc.GetFunc},
POST: map[string]HandlerFunc{"func": sfc.PostFunc},
WS: map[string]HandlerFunc{"func": sfc.WsFunc},
})
resp := httptest.NewRecorder()
req := httptest.NewRequest("GET", "http://localhost:9999/func", nil)
e.ServeHTTP(resp, req)
req = httptest.NewRequest("POST", "http://localhost:9999/func", nil)
e.ServeHTTP(resp, req)
LogOFF()
t.Log("------log Off -----")
req = httptest.NewRequest("WS", "http://localhost:9999/func", nil)
e.ServeHTTP(resp, req)
LogON()
t.Log("------log On -----")
req = httptest.NewRequest("PUT", "http://localhost:9999/test", nil)
e.ServeHTTP(resp, req)
t.Log("------ errors -----")
t.Log(e.GetErrors())
}
func TestMode(t *testing.T) {
LogON()
if logSwitch != true {
t.Error("logOn failed")
}
LogOFF()
if logSwitch != false {
t.Error("logOff failed")
}
SetTESTING()
if mode != ModeTESTING {
t.Error("SetTESTING failed")
}
SetDEBUG()
if mode != ModeDEBUG {
t.Error("SetDEBUG failed")
}
SetPRODUCTION()
if mode != ModePRO {
t.Error("SetPRODUCTION failed")
}
t.Log(Mode())
}