-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcommon_test.go
47 lines (41 loc) · 934 Bytes
/
common_test.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
package env
import (
"os"
"reflect"
"strings"
"testing"
)
// Assert fails the test if the condition is false.
func Assert(tb testing.TB, condition bool) {
tb.Helper()
if !condition {
tb.Fatal("assertion failed")
}
}
// ErrorNil fails the test if an err is not nil.
func ErrorNil(tb testing.TB, err error) {
tb.Helper()
if err != nil {
tb.Fatalf("unexpected error: %s", err.Error())
}
}
// ErrorNotNil fails the test if an err is not nil.
func ErrorNotNil(tb testing.TB, err error) {
tb.Helper()
if err == nil {
tb.Fatalf("\nexpected error but got none")
}
}
// Equals fails the test if expected is not equal to actual.
func Equals(tb testing.TB, exp, act interface{}) {
tb.Helper()
if !reflect.DeepEqual(exp, act) {
tb.Fatalf("\nexp:\t%[1]v (%[1]T)\ngot:\t%[2]v (%[2]T)", exp, act)
}
}
func unsetEnvironment() {
for _, e := range os.Environ() {
kvp := strings.Split(e, "=")
os.Unsetenv(kvp[0])
}
}