-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtestutil_test.go
More file actions
42 lines (37 loc) · 789 Bytes
/
testutil_test.go
File metadata and controls
42 lines (37 loc) · 789 Bytes
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
package sup_test
import (
"bytes"
"testing"
"text/template"
)
func mustEqual(t *testing.T, actual, expect interface{}) {
t.Helper()
if actual != expect {
t.Fatalf("%+v != %+v", actual, expect)
}
}
func shouldEqual(t *testing.T, actual, expect interface{}) {
t.Helper()
if actual != expect {
t.Errorf("%+v != %+v", actual, expect)
}
}
func tmplToStr(tmpl string, obj interface{}) string {
var buf bytes.Buffer
if err := template.Must(
template.New("").
Parse(tmpl),
).Execute(&buf, obj); err != nil {
panic(err)
}
return buf.String()
}
func mapToStr(foo interface{}) string {
// easier to implement with template, since that also handles sorting.
return tmplToStr(
`{{range $k, $v := . -}}`+
`{{printf " - %q: %v\n" $k $v}}`+
`{{end}}`,
foo,
)
}