60 строки
1,2 КиБ
Go
60 строки
1,2 КиБ
Go
package testlib
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/cucumber/godog"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var Be = Equal
|
|
|
|
func NoErr(err error) {
|
|
ExpectWithOffset(1, err).NotTo(HaveOccurred())
|
|
}
|
|
|
|
var Ok = NoErr
|
|
|
|
func Yes(b bool) {
|
|
ExpectWithOffset(1, b).To(BeTrue())
|
|
}
|
|
func YesText(b bool, text string) {
|
|
ExpectWithOffset(1, b).To(BeTrue(), text)
|
|
}
|
|
|
|
func Atoi(in string) int {
|
|
res, err := strconv.Atoi(in)
|
|
Ok(err)
|
|
return res
|
|
}
|
|
func Atof(in string) float64 {
|
|
res, err := strconv.ParseFloat(in, 32)
|
|
Ok(err)
|
|
return res
|
|
}
|
|
|
|
var TestResult error
|
|
|
|
func InitializeGomegaForGodog(ctx *godog.ScenarioContext) {
|
|
ctx.StepContext().Before(func(ctx context.Context, st *godog.Step) (context.Context, error) {
|
|
TestResult = nil
|
|
return ctx, nil
|
|
})
|
|
ctx.StepContext().After(func(ctx context.Context, st *godog.Step, status godog.StepResultStatus, err error) (context.Context, error) {
|
|
return ctx, TestResult
|
|
})
|
|
RegisterFailHandler(func(message string, callerSkip ...int) {
|
|
// remember only the expectation failed first
|
|
// anything thereafter is not to be believed
|
|
if TestResult == nil {
|
|
TestResult = fmt.Errorf(message)
|
|
}
|
|
})
|
|
}
|
|
|
|
func Sleep(m time.Duration) {
|
|
time.Sleep(m * time.Millisecond)
|
|
}
|