-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy patherrors_test.go
More file actions
41 lines (36 loc) · 831 Bytes
/
errors_test.go
File metadata and controls
41 lines (36 loc) · 831 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
package formam
import (
"encoding/json"
"fmt"
"testing"
)
func TestError(t *testing.T) {
tests := []struct {
in error
wantString string
wantJSON string
}{
{newError(0, "", "", "oh noes"),
"formam: oh noes",
`"formam: oh noes"`},
{newError(0, "foo", "foo.bar", "oh noes"),
"formam: field=foo; path=foo.bar: oh noes",
`"formam: field=foo; path=foo.bar: oh noes"`},
}
for i, tt := range tests {
t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
outString := tt.in.Error()
if outString != tt.wantString {
t.Errorf("\nout: %#v\nwant: %#v\n", outString, tt.wantString)
}
j, err := json.Marshal(tt.in)
if err != nil {
t.Fatal(err)
}
outJSON := string(j)
if outJSON != tt.wantJSON {
t.Errorf("\nout: %#v\nwant: %#v\n", outJSON, tt.wantJSON)
}
})
}
}