godog_and_gomega/godog_and_gomega_helpers.go
2025-07-21 14:05:04 +03:00

62 строки
1,1 КиБ
Go

package godog_and_gomega
import (
"errors"
"fmt"
"strconv"
"time"
. "github.com/onsi/gomega"
)
var Be = Equal
func NoErr(err error) {
ExpectWithOffset(1, err).NotTo(HaveOccurred())
}
var Ok = NoErr
func Err(err error) {
ExpectWithOffset(1, err).To(HaveOccurred())
}
func ErrIs(err, target error) {
ExpectWithOffset(1, err).To(HaveOccurred())
v := errors.Is(err, target)
s := fmt.Sprintf("ErrIs: '%v' != '%v'", err, target)
ExpectWithOffset(1, v).To(BeTrue(), s)
}
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, 64)
Ok(err)
return res
}
func Истина(in string) bool {
switch in {
case "+", "да", "Да", "ДА", "t", "true", "True", "TRUE":
return true
}
return false
}
func SetTestDeadlockProtection(seconds int) {
go checkTestTimeout(time.Duration(seconds) * time.Second)
}
func checkTestTimeout(t time.Duration) {
<-time.After(t)
panic("Test Suite Timeout")
}