-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel_test.go
52 lines (42 loc) · 942 Bytes
/
model_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
48
49
50
51
52
package krud_test
import (
"strings"
"testing"
"time"
"github.com/vikblom/krud"
)
func TestAuthorValid(t *testing.T) {
tests := []string{
"Foo Bar",
"foo bar",
"foo",
"f",
"Göran",
"Lászlo",
"E. M. Forster",
}
for _, tt := range tests {
a := krud.Author{Name: tt, DateOfBirth: krud.Date(time.Now())}
err := a.Validate()
if err != nil {
t.Errorf("expected valid author '%+v' but got err: '%v'", a, err)
}
}
}
func TestAuthorInvalid(t *testing.T) {
tests := []struct {
Name string
Expect string
}{
{Name: "", Expect: "name empty"},
{Name: "1", Expect: "unexpected rune"},
{Name: "Foo#Bar", Expect: "unexpected rune"},
}
for _, tt := range tests {
a := krud.Author{Name: tt.Name, DateOfBirth: krud.Date(time.Now())}
err := a.Validate()
if err == nil || !strings.Contains(err.Error(), tt.Expect) {
t.Errorf("expected err matching '%s' but got: '%v'", tt.Expect, err)
}
}
}