-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlc_test.go
More file actions
68 lines (56 loc) · 1.56 KB
/
sqlc_test.go
File metadata and controls
68 lines (56 loc) · 1.56 KB
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
68
package sqlc_test
import (
"fmt"
"testing"
"github.com/mhiro2/seedling"
example "github.com/mhiro2/seedling/examples/sqlc"
)
func setup(t *testing.T) *seedling.Registry {
t.Helper()
reg := seedling.NewRegistry()
example.RegisterBlueprints(reg)
return reg
}
func TestInsertOne_Member(t *testing.T) {
reg := setup(t)
// seedling auto-creates the parent Organization.
member := seedling.NewSession[example.Member](reg).InsertOne(t, nil)
if member.Root().ID == 0 {
t.Fatal("expected member ID to be set")
}
if member.Root().OrganizationID == 0 {
t.Fatal("expected OrganizationID to be auto-populated")
}
if member.Root().Name != "test-member" {
t.Fatalf("expected Name = %q, got %q", "test-member", member.Root().Name)
}
}
func TestInsertOne_Organization(t *testing.T) {
reg := setup(t)
org := seedling.NewSession[example.Organization](reg).InsertOne(t, nil,
seedling.Set("Name", "Acme Corp"),
)
if org.Root().ID == 0 {
t.Fatal("expected org ID to be set")
}
if org.Root().Name != "Acme Corp" {
t.Fatalf("expected Name = %q, got %q", "Acme Corp", org.Root().Name)
}
}
func TestInsertMany_Members(t *testing.T) {
reg := setup(t)
members := seedling.NewSession[example.Member](reg).InsertMany(t, nil, 3,
seedling.Seq("Name", func(i int) string {
return fmt.Sprintf("member-%d", i)
}),
)
if len(members) != 3 {
t.Fatalf("expected 3 members, got %d", len(members))
}
for i, m := range members {
expected := fmt.Sprintf("member-%d", i)
if m.Name != expected {
t.Fatalf("members[%d].Name = %q, want %q", i, m.Name, expected)
}
}
}