-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect_test.go
67 lines (53 loc) · 1.06 KB
/
select_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package notes
import (
"fmt"
"testing"
)
func Test_Book_Select(t *testing.T) {
t.Parallel()
book := &Book{}
const N = 10
for i := 0; i < N; i++ {
err := book.Insert(&Note{
Body: fmt.Sprintf("Note %d", i+1),
})
if err != nil {
t.Fatal(err)
}
}
if book.Len() != N {
t.Fatalf("expected %d, got %d", 5, book.Len())
}
table := []struct {
name string
book *Book
ids []int
err bool
}{
{name: "all good", book: book, ids: []int{1, 2, 3, 4, 5}},
{name: "empty book", ids: []int{1}, err: true},
{name: "missing id", book: book, ids: []int{1, 2, 42}, err: true},
}
for _, tt := range table {
t.Run(tt.name, func(t *testing.T) {
notes, err := tt.book.Select(tt.ids...)
if tt.err {
if err == nil {
t.Fatal("expected error")
}
return
}
if err != nil {
t.Fatal(err)
}
if len(notes) != len(tt.ids) {
t.Fatalf("expected %d, got %d", len(tt.ids), len(notes))
}
for i, id := range tt.ids {
if notes[i].ID() != id {
t.Fatalf("expected %d, got %d", id, notes[i].ID())
}
}
})
}
}