-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathcreate_test.go
91 lines (70 loc) · 1.49 KB
/
create_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package crud_test
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestCreate(t *testing.T) {
err := DB.ResetTables(UserProfile{})
assert.Nil(t, err)
azer := UserProfile{
Name: "Azer",
Bio: "I like photography",
Email: "[email protected]",
}
err = DB.Create(azer)
assert.Nil(t, err)
DB.DropTables(UserProfile{})
}
func TestCreateAndRead(t *testing.T) {
DB.ResetTables(UserProfile{})
azer := UserProfile{
Name: "Azer",
Bio: "I like photography",
Email: "[email protected]",
}
assert.Equal(t, azer.Id, 0)
err := DB.CreateAndRead(&azer)
assert.Nil(t, err)
assert.Equal(t, azer.Id, 1)
DB.DropTables(UserProfile{})
}
func TestCreateEmpty(t *testing.T) {
DB.ResetTables(UserProfile{})
azer := UserProfile{
Name: "Azer",
}
err := DB.Create(azer)
assert.Nil(t, err)
DB.DropTables(UserProfile{})
}
func TestEmbedding(t *testing.T) {
DB.ResetTables(EmbeddedFoo{})
foo := EmbeddedFoo{
Foo: Foo{
APIKey: "hi",
YOLO: true,
Beast: "span eggs",
},
Span: 123,
Eggs: "yoo",
}
assert.Equal(t, foo.Id, 0)
err := DB.CreateAndRead(&foo)
assert.Nil(t, err)
assert.Equal(t, foo.Id, 1)
assert.Equal(t, foo.APIKey, "hi")
assert.Equal(t, foo.Beast, "span eggs")
DB.DropTables(EmbeddedFoo{})
}
func TestCreatingRenamedTableRow(t *testing.T) {
DB.ResetTables(Post{})
p := Post{
Title: "Foo",
Text: "bar",
}
assert.Equal(t, p.Id, 0)
err := DB.CreateAndRead(&p)
assert.Nil(t, err)
assert.Equal(t, p.Id, 1)
DB.DropTables(Post{})
}