-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcontext_test.go
More file actions
51 lines (40 loc) · 865 Bytes
/
Copy pathcontext_test.go
File metadata and controls
51 lines (40 loc) · 865 Bytes
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
package spider
import (
"net/http"
"testing"
)
func TestContextStore(t *testing.T) {
ctx := NewContext()
req := &http.Request{}
ctx.Set("req", req)
val := ctx.Get("req")
switch val.(type) {
case *http.Request:
default:
t.Error("Not of type string")
}
if val != req {
t.Error("Not equal")
}
}
func TestParentAndChildren(t *testing.T) {
parent := NewContext()
child1 := NewContext()
child2 := NewContext()
child3 := NewContext()
child1.SetParent(parent)
child2.SetParent(parent)
child3.SetParent(child2)
if child1.Parent != parent {
t.Error("child1 should be a child of parent")
}
if len(parent.Children) != 2 {
t.Error("parent should have two children")
}
if child3.Parent != child2 {
t.Error("child3 should be a child of child2")
}
if len(child2.Children) != 1 {
t.Error("child2 should have exactly one child")
}
}