/
t.go
47 lines (40 loc) · 1.07 KB
/
t.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
39
40
41
42
43
44
45
46
47
// Unless explicitly stated otherwise all files in this repository are licensed
// under the MIT License.
// This product includes software developed at Guance Cloud (https://www.guance.com/).
// Copyright 2021-present Guance, Inc.
// Package testutil wraps basic tools when building goalng test cases.
package testutil
import (
"reflect"
)
type TB interface {
Helper()
Fatalf(string, ...interface{})
}
func Assert(tb TB, condition bool, fmt string, a ...interface{}) {
tb.Helper()
if !condition {
tb.Fatalf("\033[31m"+fmt+"\033[39m\n", a...)
}
}
func Ok(tb TB, err error) {
tb.Helper()
if err != nil {
tb.Fatalf("\033[31munexpected error: %v\033[39m\n", err)
}
}
func NotOk(tb TB, err error, fmt string, a ...interface{}) {
tb.Helper()
if err == nil {
if len(a) != 0 {
tb.Fatalf("\033[31m"+fmt+": expected error, got none\033[39m", a...)
}
tb.Fatalf("\033[31mexpected error, got none\033[39m")
}
}
func Equals(tb TB, exp, act interface{}) {
tb.Helper()
if !reflect.DeepEqual(exp, act) {
tb.Fatalf("\033[31m\nexp: %#v\n\ngot: %#v\033[39m\n", exp, act)
}
}