-
Notifications
You must be signed in to change notification settings - Fork 0
/
testutil.go
48 lines (42 loc) · 936 Bytes
/
testutil.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
48
package signup
import (
"encoding/json"
"fmt"
"reflect"
"testing"
"time"
)
func assertEqual(t *testing.T, got, want interface{}) {
t.Helper()
if got != want {
t.Fatalf("Want:\n\n%v\n\nbut got:\n\n%v\n\n", want, got)
}
}
func assertDeepEqual(t *testing.T, got, want interface{}) {
t.Helper()
areEqual := reflect.DeepEqual(got, want)
if !areEqual {
t.Fatalf("Want:\n %s, but got:\n %s", prettyPrint(want), prettyPrint(got))
}
}
func prettyPrint(i interface{}) string {
s, err := json.MarshalIndent(i, "", "\t")
if err != nil {
return fmt.Sprintf("%+v", i)
}
return string(s)
}
func mustMakeTime(t *testing.T, layout, value string) time.Time {
t.Helper()
tiempo, err := time.Parse(layout, value)
if err != nil {
t.Fatal("could not make time.Time", err)
}
return tiempo
}
func assertNilError(t *testing.T, got error) {
t.Helper()
if got != nil {
t.Fatalf("Expected nil error, but got:\n%v", got)
}
}