-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprobe_test.go
More file actions
executable file
·68 lines (55 loc) · 1.07 KB
/
probe_test.go
File metadata and controls
executable file
·68 lines (55 loc) · 1.07 KB
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
package rubik
import (
"reflect"
"testing"
)
var probe *TestProbe
type Enn struct {
Entity
Name string
}
func (enn Enn) CoreEntity() interface{} {
return enn
}
func (enn Enn) ComposedEntity() Entity {
return enn.Entity
}
func (enn Enn) Path() string {
return enn.Entity.PointTo
}
func init() {
probe = NewProbe(initTestRouter())
}
var ir = Route{
Method: "GET",
Path: "/",
Entity: Enn{},
Controller: testIndexCtl,
}
func initTestRouter() Router {
indexRouter := Create("/")
indexRouter.Add(ir)
return indexRouter
}
func testIndexCtl(req *Request) {
req.Respond("Woohoo!", Type.Text)
}
func TestGetTestClient(t *testing.T) {
if reflect.TypeOf(probe) != reflect.TypeOf(&TestProbe{}) {
t.Error("Probe did not return a value of type rubik.TestProbe")
}
}
func TestIndexRoute(t *testing.T) {
entity := Enn{
Name: "ashish",
}
entity.PointTo = "/"
rr := probe.Test(entity)
if rr.Result().StatusCode == 200 {
defer rr.Result().Body.Close()
resp := rr.Body.String()
if resp != "Woohoo!" {
t.Errorf("Resp: %s is not wohoo", resp)
}
}
}