improves stepdef test coverage
Этот коммит содержится в:
родитель
7474489b9c
коммит
88d441e5ce
2 изменённых файлов: 113 добавлений и 7 удалений
|
@ -20,19 +20,20 @@ func TestProgressFormatterOutput(t *testing.T) {
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
w := colors.Uncolored(&buf)
|
w := colors.Uncolored(&buf)
|
||||||
s := &Suite{
|
r := runner{
|
||||||
fmt: progressFunc("progress", w),
|
fmt: progressFunc("progress", w),
|
||||||
features: []*feature{&feature{
|
features: []*feature{&feature{
|
||||||
Path: "any.feature",
|
Path: "any.feature",
|
||||||
Feature: feat,
|
Feature: feat,
|
||||||
Content: []byte(sampleGherkinFeature),
|
Content: []byte(sampleGherkinFeature),
|
||||||
}},
|
}},
|
||||||
|
initializer: func(s *Suite) {
|
||||||
|
s.Step(`^passing$`, func() error { return nil })
|
||||||
|
s.Step(`^failing$`, func() error { return fmt.Errorf("errored") })
|
||||||
|
s.Step(`^pending$`, func() error { return ErrPending })
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Step(`^passing$`, func() error { return nil })
|
|
||||||
s.Step(`^failing$`, func() error { return fmt.Errorf("errored") })
|
|
||||||
s.Step(`^pending$`, func() error { return ErrPending })
|
|
||||||
|
|
||||||
// var zeroDuration time.Duration
|
// var zeroDuration time.Duration
|
||||||
expected := `
|
expected := `
|
||||||
...F-.P-.UU.....F..P..U 23
|
...F-.P-.UU.....F..P..U 23
|
||||||
|
@ -72,8 +73,7 @@ func FeatureContext(s *godog.Suite) {
|
||||||
expected = fmt.Sprintf(expected, zeroDuration.String(), os.Getenv("GODOG_SEED"))
|
expected = fmt.Sprintf(expected, zeroDuration.String(), os.Getenv("GODOG_SEED"))
|
||||||
expected = trimAllLines(expected)
|
expected = trimAllLines(expected)
|
||||||
|
|
||||||
s.run()
|
r.run()
|
||||||
s.fmt.Summary()
|
|
||||||
|
|
||||||
actual := trimAllLines(buf.String())
|
actual := trimAllLines(buf.String())
|
||||||
if actual != expected {
|
if actual != expected {
|
||||||
|
|
106
stepdef_test.go
Обычный файл
106
stepdef_test.go
Обычный файл
|
@ -0,0 +1,106 @@
|
||||||
|
package godog
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/DATA-DOG/godog/gherkin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestShouldSupportIntTypes(t *testing.T) {
|
||||||
|
fn := func(a int64, b int32, c int16, d int8) error { return nil }
|
||||||
|
|
||||||
|
def := &StepDef{
|
||||||
|
Handler: fn,
|
||||||
|
hv: reflect.ValueOf(fn),
|
||||||
|
}
|
||||||
|
|
||||||
|
def.args = []interface{}{"1", "1", "1", "1"}
|
||||||
|
if err := def.run(); err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
def.args = []interface{}{"1", "1", "1", strings.Repeat("1", 9)}
|
||||||
|
if err := def.run(); err == nil {
|
||||||
|
t.Fatalf("expected convertion fail for int8, but got none")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestShouldSupportFloatTypes(t *testing.T) {
|
||||||
|
fn := func(a float64, b float32) error { return nil }
|
||||||
|
|
||||||
|
def := &StepDef{
|
||||||
|
Handler: fn,
|
||||||
|
hv: reflect.ValueOf(fn),
|
||||||
|
}
|
||||||
|
|
||||||
|
def.args = []interface{}{"1.1", "1.09"}
|
||||||
|
if err := def.run(); err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
def.args = []interface{}{"1.08", strings.Repeat("1", 65) + ".67"}
|
||||||
|
if err := def.run(); err == nil {
|
||||||
|
t.Fatalf("expected convertion fail for float32, but got none")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestShouldNotSupportOtherPointerTypesThanGherkin(t *testing.T) {
|
||||||
|
fn1 := func(a *int) error { return nil }
|
||||||
|
fn2 := func(a *gherkin.DocString) error { return nil }
|
||||||
|
fn3 := func(a *gherkin.DataTable) error { return nil }
|
||||||
|
|
||||||
|
def1 := &StepDef{Handler: fn1, hv: reflect.ValueOf(fn1), args: []interface{}{(*int)(nil)}}
|
||||||
|
def2 := &StepDef{Handler: fn2, hv: reflect.ValueOf(fn2), args: []interface{}{(*gherkin.DocString)(nil)}}
|
||||||
|
def3 := &StepDef{Handler: fn3, hv: reflect.ValueOf(fn3), args: []interface{}{(*gherkin.DataTable)(nil)}}
|
||||||
|
|
||||||
|
if err := def1.run(); err == nil {
|
||||||
|
t.Fatalf("expected conversion error, but got none")
|
||||||
|
}
|
||||||
|
if err := def2.run(); err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
if err := def3.run(); err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestShouldSupportOnlyByteSlice(t *testing.T) {
|
||||||
|
fn1 := func(a []byte) error { return nil }
|
||||||
|
fn2 := func(a []string) error { return nil }
|
||||||
|
|
||||||
|
def1 := &StepDef{Handler: fn1, hv: reflect.ValueOf(fn1), args: []interface{}{"str"}}
|
||||||
|
def2 := &StepDef{Handler: fn2, hv: reflect.ValueOf(fn2), args: []interface{}{[]string{}}}
|
||||||
|
|
||||||
|
if err := def1.run(); err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
if err := def2.run(); err == nil {
|
||||||
|
t.Fatalf("expected conversion error, but got none")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUnexpectedArguments(t *testing.T) {
|
||||||
|
fn := func(a, b int) error { return nil }
|
||||||
|
def := &StepDef{Handler: fn, hv: reflect.ValueOf(fn)}
|
||||||
|
|
||||||
|
def.args = []interface{}{"1"}
|
||||||
|
if err := def.run(); err == nil {
|
||||||
|
t.Fatalf("expected an error due to wrong number of arguments, but got none")
|
||||||
|
}
|
||||||
|
|
||||||
|
def.args = []interface{}{"one", "two"}
|
||||||
|
if err := def.run(); err == nil {
|
||||||
|
t.Fatalf("expected conversion error, but got none")
|
||||||
|
}
|
||||||
|
|
||||||
|
// @TODO maybe we should support duration
|
||||||
|
// fn2 := func(err time.Duration) error { return nil }
|
||||||
|
// def = &StepDef{Handler: fn2, hv: reflect.ValueOf(fn2)}
|
||||||
|
|
||||||
|
// def.args = []interface{}{"1"}
|
||||||
|
// if err := def.run(); err == nil {
|
||||||
|
// t.Fatalf("expected an error due to wrong argument type, but got none")
|
||||||
|
// }
|
||||||
|
}
|
Загрузка…
Создание таблицы
Сослаться в новой задаче