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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
package assert
import (
"errors"
"fmt"
"reflect"
"strings"
"testing"
)
// Equal asserts exp == act.
func Equal(t testing.TB, name string, exp, got interface{}) {
t.Helper()
if !reflect.DeepEqual(exp, got) {
t.Fatalf("unexpected %v: expected %#v but got %#v", name, exp, got)
}
}
// Success asserts err == nil.
func Success(t testing.TB, err error) {
t.Helper()
if err != nil {
t.Fatal(err)
}
}
// Error asserts err != nil.
func Error(t testing.TB, err error) {
t.Helper()
if err == nil {
t.Fatal("expected error")
}
}
// Contains asserts the fmt.Sprint(v) contains sub.
func Contains(t testing.TB, v interface{}, sub string) {
t.Helper()
s := fmt.Sprint(v)
if !strings.Contains(s, sub) {
t.Fatalf("expected %q to contain %q", s, sub)
}
}
// ErrorIs asserts errors.Is(got, exp)
func ErrorIs(t testing.TB, exp, got error) {
t.Helper()
if !errors.Is(got, exp) {
t.Fatalf("expected %v but got %v", exp, got)
}
}
|