-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrace_test.go
64 lines (50 loc) · 1.59 KB
/
trace_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
package katana_test
import (
"github.com/drborges/katana"
"github.com/smartystreets/assertions/should"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestTrace(t *testing.T) {
Convey("Given I have an instance of katana.Trace", t, func() {
trace := katana.NewTrace()
Convey("Then I can push items into it", func() {
trace.Push("1")
So(trace.String(), should.Equal, "[1]")
trace.Push("2")
trace.Push("3")
So(trace.String(), should.Equal, "[1 -> 2 -> 3]")
Convey("When I add an type that is already in the trace", func() {
err := trace.Push("2")
Convey("Then it returns a cyclic dependency error", func() {
So(err.Error(), should.Resemble, katana.ErrCyclicDependency{&katana.Trace{
Types: []string{"1", "2", "3", "2"},
}}.Error())
})
})
Convey("And I can check whether an item is already in the trace", func() {
So(trace.Contains("1"), should.BeTrue)
So(trace.Contains("2"), should.BeTrue)
So(trace.Contains("3"), should.BeTrue)
Convey("And I can pop items from it", func() {
item := trace.Pop()
So(item, should.Equal, "3")
So(trace.String(), should.Equal, "[1 -> 2]")
item = trace.Pop()
So(item, should.Equal, "2")
So(trace.String(), should.Equal, "[1]")
item = trace.Pop()
So(item, should.Equal, "1")
So(trace.Empty(), should.BeTrue)
So(trace.String(), should.Equal, "[]")
})
})
})
Convey("When I pop items from an empty trace", func() {
item := trace.Pop()
Convey("Then it returns an empty item", func() {
So(item, should.BeEmpty)
})
})
})
}