forked from go-bdd/gobdd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
steps_test.go
38 lines (32 loc) · 1.05 KB
/
steps_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
package gobdd
import (
"testing"
)
func TestValidateStepFunc(t *testing.T) {
testCases := map[string]interface{}{
"function without arguments": func() {},
"function with 1 argument": func(StepTest) {},
"function with invalid first argument": func(int, Context) {},
}
for name, testCase := range testCases {
t.Run(name, func(t *testing.T) {
if err := validateStepFunc(testCase); err == nil {
t.Errorf("the test should fail for the function")
}
})
}
}
func TestValidateStepFunc_ValidFunction(t *testing.T) {
if err := validateStepFunc(func(StepTest, Context) {}); err != nil {
t.Errorf("the test should NOT fail for the function: %s", err)
}
}
func TestValidateStepFunc_ReturnContext(t *testing.T) {
if err := validateStepFunc(func(StepTest, Context) Context { return Context{} }); err != nil {
t.Errorf("step function returning a context should NOT fail validation: %s", err)
}
}
// Used for context package backwards compatibility tests.
func ValidateStepFunc(f interface{}) error {
return validateStepFunc(f)
}