-
Notifications
You must be signed in to change notification settings - Fork 1
/
delete_test.go
144 lines (109 loc) · 3 KB
/
delete_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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package makroud_test
import (
"context"
"testing"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
"github.com/ulule/loukoum/v3"
"github.com/ulule/makroud"
)
func TestDelete_DeleteOwl(t *testing.T) {
Setup(t)(func(driver makroud.Driver) {
ctx := context.Background()
is := require.New(t)
owl := &Owl{
Name: "Blake",
FeatherColor: "brown",
FavoriteFood: "Raspberry",
}
err := makroud.Save(ctx, driver, owl)
is.NoError(err)
is.NotEmpty(owl.ID)
id := owl.ID
err = makroud.Delete(ctx, driver, owl)
is.NoError(err)
query := loukoum.Select("COUNT(*)").From("ztp_owl").Where(loukoum.Condition("id").Equal(id))
count, err := makroud.Count(ctx, driver, query)
is.NoError(err)
is.Equal(int64(0), count)
query = loukoum.Select("COUNT(*)").From("ztp_owl").Where(loukoum.Condition("name").Equal("Blake"))
count, err = makroud.Count(ctx, driver, query)
is.NoError(err)
is.NoError(err)
is.Equal(int64(0), count)
})
}
func TestDelete_ArchiveOwl(t *testing.T) {
Setup(t)(func(driver makroud.Driver) {
ctx := context.Background()
is := require.New(t)
owl := &Owl{
Name: "Frosty",
FeatherColor: "beige",
FavoriteFood: "Wasabi",
}
err := makroud.Save(ctx, driver, owl)
is.NoError(err)
is.NotEmpty(owl.ID)
err = makroud.Archive(ctx, driver, owl)
is.Error(err)
is.Equal(makroud.ErrSchemaDeletedKey, errors.Cause(err))
})
}
func TestDelete_DeleteMeow(t *testing.T) {
Setup(t)(func(driver makroud.Driver) {
ctx := context.Background()
is := require.New(t)
cat := &Cat{
Name: "Wolfram",
}
err := makroud.Save(ctx, driver, cat)
is.NoError(err)
is.NotEmpty(cat.ID)
meow := &Meow{
Body: "meow meow meow?",
CatID: cat.ID,
}
err = makroud.Save(ctx, driver, meow)
is.NoError(err)
is.NotEmpty(meow.Hash)
id := meow.Hash
err = makroud.Delete(ctx, driver, meow)
is.NoError(err)
query := loukoum.Select("COUNT(*)").From("ztp_meow").Where(loukoum.Condition("hash").Equal(id))
count, err := makroud.Count(ctx, driver, query)
is.NoError(err)
is.Equal(int64(0), count)
})
}
func TestDelete_ArchiveMeow(t *testing.T) {
Setup(t)(func(driver makroud.Driver) {
ctx := context.Background()
is := require.New(t)
cat := &Cat{
Name: "Wolfram",
}
err := makroud.Save(ctx, driver, cat)
is.NoError(err)
is.NotEmpty(cat.ID)
meow := &Meow{
Body: "meow! meow meow meow ?!",
CatID: cat.ID,
}
err = makroud.Save(ctx, driver, meow)
is.NoError(err)
is.NotEmpty(meow.Hash)
id := meow.Hash
err = makroud.Archive(ctx, driver, meow)
is.NoError(err)
query := loukoum.Select("COUNT(*)").From("ztp_meow").Where(loukoum.Condition("hash").Equal(id))
count, err := makroud.Count(ctx, driver, query)
is.NoError(err)
is.Equal(int64(1), count)
query = loukoum.Select("COUNT(*)").From("ztp_meow").
Where(loukoum.Condition("hash").Equal(id)).And(loukoum.Condition("deleted").IsNull(true))
count, err = makroud.Count(ctx, driver, query)
is.NoError(err)
is.Equal(int64(0), count)
})
}