Skip to content

Commit 993cf24

Browse files
committed
add unit tests to the ginkgohandler package
1 parent df26329 commit 993cf24

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

ginkgohandler/handler_test.go

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,120 @@ func TestGetGinkgoHandler_no_ginkgo(t *testing.T) {
110110
t.Fatalf("should return nil")
111111
}
112112
}
113+
114+
func TestDotHandler_GetFocusContainerName_happy(t *testing.T) {
115+
exp := &ast.CallExpr{
116+
Fun: ast.NewIdent("FIt"),
117+
}
118+
119+
h := dotHandler{}
120+
121+
isFocus, name := h.GetFocusContainerName(exp)
122+
123+
if !isFocus {
124+
t.Error("h.GetFocusContainerName(exp) should return true")
125+
}
126+
127+
if name == nil {
128+
t.Error("should return valid ast.Ident object")
129+
} else if name.Name != "FIt" {
130+
t.Error("function name should be 'FIt'")
131+
}
132+
}
133+
134+
func TestDotHandler_GetFocusContainerName_no_focus(t *testing.T) {
135+
exp := &ast.CallExpr{
136+
Fun: ast.NewIdent("It"),
137+
}
138+
139+
h := dotHandler{}
140+
isFocus, name := h.GetFocusContainerName(exp)
141+
if isFocus {
142+
t.Error("h.GetFocusContainerName(exp) should return false")
143+
}
144+
145+
if name == nil {
146+
t.Error("should return valid ast.Ident object")
147+
} else if name.Name != "It" {
148+
t.Error("function name should be 'It'")
149+
}
150+
}
151+
152+
func TestDotHandler_GetFocusContainerName_selector(t *testing.T) {
153+
exp := &ast.CallExpr{
154+
Fun: &ast.SelectorExpr{
155+
Sel: ast.NewIdent("ginkgo"),
156+
X: &ast.CallExpr{
157+
Fun: ast.NewIdent("FIt"),
158+
},
159+
},
160+
}
161+
162+
h := dotHandler{}
163+
isFocus, name := h.GetFocusContainerName(exp)
164+
if isFocus {
165+
t.Error("h.GetFocusContainerName(exp) should return false")
166+
}
167+
168+
if name != nil {
169+
t.Error("should return nil")
170+
}
171+
}
172+
173+
func TestNameHandler_GetFocusContainerName_happy(t *testing.T) {
174+
exp := &ast.CallExpr{
175+
Fun: &ast.SelectorExpr{
176+
Sel: ast.NewIdent("FIt"),
177+
X: ast.NewIdent("ginkgo"),
178+
},
179+
}
180+
181+
h := nameHandler("ginkgo")
182+
isFocus, name := h.GetFocusContainerName(exp)
183+
if !isFocus {
184+
t.Error("h.GetFocusContainerName(exp) should return true")
185+
}
186+
187+
if name == nil {
188+
t.Error("should return a valid ast.Ident object")
189+
} else if name.Name != "FIt" {
190+
t.Error("function name should be 'FIt'")
191+
}
192+
}
193+
194+
func TestNameHandler_GetFocusContainerName_no_focus(t *testing.T) {
195+
exp := &ast.CallExpr{
196+
Fun: &ast.SelectorExpr{
197+
Sel: ast.NewIdent("It"),
198+
X: ast.NewIdent("ginkgo"),
199+
},
200+
}
201+
202+
h := nameHandler("ginkgo")
203+
isFocus, name := h.GetFocusContainerName(exp)
204+
if isFocus {
205+
t.Error("h.GetFocusContainerName(exp) should return false")
206+
}
207+
208+
if name == nil {
209+
t.Error("should return a valid ast.Ident object")
210+
} else if name.Name != "It" {
211+
t.Error("function name should be 'FIt'")
212+
}
213+
}
214+
215+
func TestNameHandler_GetFocusContainerName_ident(t *testing.T) {
216+
exp := &ast.CallExpr{
217+
Fun: ast.NewIdent("FIt"),
218+
}
219+
220+
h := nameHandler("ginkgo")
221+
isFocus, name := h.GetFocusContainerName(exp)
222+
if isFocus {
223+
t.Error("h.GetFocusContainerName(exp) should return false")
224+
}
225+
226+
if name != nil {
227+
t.Error("should return nil")
228+
}
229+
}

0 commit comments

Comments
 (0)