-
Notifications
You must be signed in to change notification settings - Fork 31
/
namespace_test.go
113 lines (99 loc) · 2.09 KB
/
namespace_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
package godo
import (
"testing"
"gopkg.in/stretchr/testify.v1/assert"
)
func TestMultiProject(t *testing.T) {
result := ""
otherTasks := func(p *Project) {
p.Task("foo", S{"bar"}, func(c *Context) {
result += "B"
})
p.Task("bar", nil, func(c *Context) {
result += "C"
})
}
tasks := func(p *Project) {
p.Use("other", otherTasks)
p.Task("foo", nil, func(c *Context) {
result += "A"
})
p.Task("bar", S{"foo", "other:foo"}, nil)
}
runTask(tasks, "bar")
if result != "ACB" {
t.Error("should have run dependent project")
}
}
func TestNestedNamespaces(t *testing.T) {
levels := ""
var subsubTasks = func(p *Project) {
p.Task("A", S{"B"}, func(*Context) {
levels += "2:"
})
p.Task("B", nil, func(*Context) {
levels += "2B:"
})
}
var subTasks = func(p *Project) {
p.Use("sub", subsubTasks)
p.Task("A", S{"sub:A"}, func(*Context) {
levels += "1:"
})
}
var tasks = func(p *Project) {
p.Use("sub", subTasks)
p.Task("A", S{"sub:A"}, func(*Context) {
levels += "0:"
})
}
runTask(tasks, "A")
assert.Equal(t, levels, "2B:2:1:0:")
}
func TestNestedNamespaceDependency(t *testing.T) {
levels := ""
var subsubTasks = func(p *Project) {
p.Task("A", S{"B"}, func(*Context) {
levels += "2:"
})
p.Task1("B", func(*Context) {
levels += "2B:"
})
}
var subTasks = func(p *Project) {
p.Use("sub", subsubTasks)
p.Task("A", S{"sub:A"}, func(*Context) {
levels += "1:"
})
}
var tasks = func(p *Project) {
p.Use("sub", subTasks)
p.Task("A", S{"sub:sub:A"}, func(*Context) {
levels += "0:"
})
}
runTask(tasks, "A")
assert.Equal(t, levels, "2B:2:0:")
}
func TestRelativeNamespace(t *testing.T) {
levels := ""
var subsubTasks = func(p *Project) {
p.Task("A", S{"/sub:A"}, func(*Context) {
levels += "2:"
})
}
var subTasks = func(p *Project) {
p.Use("sub", subsubTasks)
p.Task("A", S{"sub:A"}, func(*Context) {
levels += "1:"
})
}
var tasks = func(p *Project) {
p.Use("sub", subTasks)
p.Task("A", S{"sub:sub:A"}, func(*Context) {
levels += "0:"
})
}
runTask(tasks, "A")
assert.Equal(t, "1:2:0:", levels)
}