forked from SemanticallyNull/golandreporter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgolandreporter_suite_test.go
160 lines (139 loc) · 6.63 KB
/
golandreporter_suite_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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package golandreporter
import (
"fmt"
"github.com/onsi/ginkgo/types"
"os"
"testing"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func TestGolandReporter(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithCustomReporters(t, "Golandreporter Suite", []Reporter{NewGolandReporter()})
}
var _ = Describe("GolandReporter", func(){
var root *node
BeforeEach(func(){
root = &node{nil, "[Top Level]", nil, 0, "", []*node{}}
})
Context("insertNode", func(){
It("inserts describe node", func(){
insertNode(root, []string{"DescribeBlock"})
Expect(len(root.children)).To(Equal(1))
Expect(root.children[0].description).To(Equal("DescribeBlock"))
})
It("does not inserts duplicate elements", func(){
insertNode(root, []string{"DescribeBlock"})
insertNode(root, []string{"DescribeBlock"})
Expect(len(root.children)).To(Equal(1))
})
It("inserts context blocks elements", func(){
insertNode(root, []string{"DescribeBlock", "ContextBlock"})
Expect(len(root.children)).To(Equal(1))
Expect(root.children[0].description).To(Equal("DescribeBlock"))
Expect(len(root.children[0].children)).To(Equal(1))
Expect(root.children[0].children[0].description).To(Equal("ContextBlock"))
})
It("inserts multiple context blocks elements", func(){
insertNode(root, []string{"DescribeBlock", "ContextBlock1"})
insertNode(root, []string{"DescribeBlock", "ContextBlock2"})
Expect(len(root.children)).To(Equal(1))
Expect(root.children[0].description).To(Equal("DescribeBlock"))
Expect(len(root.children[0].children)).To(Equal(2))
Expect(root.children[0].children[0].description).To(Equal("ContextBlock1"))
Expect(root.children[0].children[1].description).To(Equal("ContextBlock2"))
})
})
Context("getSpecName", func(){
It("returns a full spec name given a node", func(){
insertNode(root, []string{"DescribeBlock", "ContextBlock", "SpecBlock"})
describeBlock := *root.children[0]
contextBlock := *root.children[0].children[0]
specBlock := *root.children[0].children[0].children[0]
Expect(getSpecName(describeBlock)).To(Equal("DescribeBlock"))
Expect(getSpecName(contextBlock)).To(Equal("DescribeBlock/ContextBlock"))
Expect(getSpecName(specBlock)).To(Equal("DescribeBlock/ContextBlock/SpecBlock"))
})
})
Context("findNode", func(){
It("returns true and node if found", func(){
insertNode(root, []string{"DescribeBlock", "ContextBlock", "SpecBlock"})
node, ok := findNode(root, []string{"DescribeBlock", "ContextBlock", "SpecBlock"})
Expect(ok).To(BeTrue())
Expect(node.description).To(Equal("SpecBlock"))
})
It("returns false and nil spec node is not found", func(){
insertNode(root, []string{"DescribeBlock", "ContextBlock", "SpecBlock"})
node, ok := findNode(root, []string{"DescribeBlock", "ContextBlock", "MissingSpecBlock"})
Expect(ok).To(BeFalse())
Expect(node).To(BeNil())
})
It("returns false and nil context node is not found", func(){
insertNode(root, []string{"DescribeBlock", "ContextBlock", "SpecBlock"})
node, ok := findNode(root, []string{"DescribeBlock", "MissingContextBlock", "SpecBlock"})
Expect(ok).To(BeFalse())
Expect(node).To(BeNil())
})
})
Context("updateResult", func(){
It("inserts PASS at all levels", func(){
insertNode(root, []string{"DescribeBlock", "ContextBlock", "SpecBlock"})
summary := &types.SpecSummary{ComponentTexts:[]string{"[Top_Level]", "DescribeBlock", "ContextBlock", "SpecBlock"}, RunTime:1}
updateResult(root, summary, "PASS")
Expect(root.children[0].testResult).To(Equal("PASS"))
Expect(root.children[0].children[0].testResult).To(Equal("PASS"))
Expect(root.children[0].children[0].children[0].testResult).To(Equal("PASS"))
})
It("inserts FAIL at all levels", func(){
insertNode(root, []string{"DescribeBlock", "ContextBlock", "SpecBlock"})
summary := &types.SpecSummary{ComponentTexts:[]string{"[Top_Level]", "DescribeBlock", "ContextBlock", "SpecBlock"}, RunTime:1}
updateResult(root, summary, "FAIL")
Expect(root.children[0].testResult).To(Equal("FAIL"))
Expect(root.children[0].children[0].testResult).To(Equal("FAIL"))
Expect(root.children[0].children[0].children[0].testResult).To(Equal("FAIL"))
})
It("doesn't update parent nodes after failed child", func(){
insertNode(root, []string{"DescribeBlock", "ContextBlock", "SpecBlock1"})
insertNode(root, []string{"DescribeBlock", "ContextBlock", "SpecBlock2"})
testSummary1 := &types.SpecSummary{ComponentTexts:[]string{"[Top_Level]", "DescribeBlock", "ContextBlock", "SpecBlock1"}, RunTime:1}
updateResult(root, testSummary1, "FAIL")
testSummary2 := &types.SpecSummary{ComponentTexts:[]string{"[Top_Level]", "DescribeBlock", "ContextBlock", "SpecBlock2"}, RunTime:1}
updateResult(root, testSummary2, "PASS")
Expect(root.children[0].testResult).To(Equal("FAIL"))
Expect(root.children[0].children[0].testResult).To(Equal("FAIL"))
Expect(root.children[0].children[0].children[0].testResult).To(Equal("FAIL"))
Expect(root.children[0].children[0].children[1].testResult).To(Equal("PASS"))
})
It("calculates correct runtime", func(){
insertNode(root, []string{"DescribeBlock", "ContextBlock", "SpecBlock1"})
insertNode(root, []string{"DescribeBlock", "ContextBlock", "SpecBlock2"})
testSummary1 := &types.SpecSummary{ComponentTexts:[]string{"[Top_Level]", "DescribeBlock", "ContextBlock", "SpecBlock1"}, RunTime:1}
updateResult(root, testSummary1, "PASS")
testSummary2 := &types.SpecSummary{ComponentTexts:[]string{"[Top_Level]", "DescribeBlock", "ContextBlock", "SpecBlock2"}, RunTime:1}
updateResult(root, testSummary2, "PASS")
Expect(root.children[0].time).To(Equal(time.Duration(2)))
Expect(root.children[0].children[0].time).To(Equal(time.Duration(2)))
Expect(root.children[0].children[0].children[0].time).To(Equal(time.Duration(1)))
Expect(root.children[0].children[0].children[1].time).To(Equal(time.Duration(1)))
})
})
Context("NewAutoGolandReporter", func(){
It("Returns a goland reporter if OLDPWD contains goland", func(){
os.Setenv("OLDPWD", "gOlAnD")
reporter := NewAutoGolandReporter()
Expect(fmt.Sprintf("%T", reporter)).To(Equal("golandreporter.GolandReporter"))
})
It("Returns default reporter if OLDPWD or SNAP_NAME does not contain goland", func(){
os.Setenv("OLDPWD", "vscode")
os.Setenv("SNAP_NAME", "vscode")
reporter := NewAutoGolandReporter()
Expect(fmt.Sprintf("%T", reporter)).To(Equal("*reporters.DefaultReporter"))
})
It("Returns a goland reporter if SNAP_NAME contains goland", func(){
os.Setenv("SNAP_NAME", "gOlAnD")
reporter := NewAutoGolandReporter()
Expect(fmt.Sprintf("%T", reporter)).To(Equal("golandreporter.GolandReporter"))
})
})
})