-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_test.go
More file actions
101 lines (87 loc) · 2.11 KB
/
data_test.go
File metadata and controls
101 lines (87 loc) · 2.11 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
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
package debefix
import (
"testing"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
var (
tableTags = TableName("public.tags")
tablePosts = TableName("public.posts")
tablePostTags = TableName("public.post_tags")
)
func TestData(t *testing.T) {
data := NewData()
data.AddValues(tableTags,
MapValues{
"tag_id": 2,
"_refid": SetValueRefID("all"),
"tag_name": "All",
},
MapValues{
"tag_id": 5,
"_refid": SetValueRefID("half"),
"tag_name": "Half",
},
)
data.AddValues(tablePosts,
MapValues{
"post_id": 1,
"_refid": SetValueRefID("post_1"),
"title": "First post",
},
MapValues{
"post_id": 2,
"_refid": SetValueRefID("post_2"),
"title": "Second post",
},
)
data.AddValues(tablePostTags,
MapValues{
"post_id": ValueRefID(tablePosts, "post_1", "post_id"),
"tag_id": ValueRefID(tableTags, "all", "tag_id"),
},
MapValues{
"post_id": ValueRefID(tablePosts, "post_2", "post_id"),
"tag_id": ValueRefID(tableTags, "half", "tag_id"),
},
)
tagsTable, ok := data.Tables[tableTags.TableID()]
assert.Assert(t, ok, "tags table not found")
postsTable, ok := data.Tables[tablePosts.TableID()]
assert.Assert(t, ok, "posts table not found")
postTagsTable, ok := data.Tables[tablePostTags.TableID()]
assert.Assert(t, ok, "post_tags table not found")
assert.Assert(t, is.Len(tagsTable.Rows, 2))
assert.Assert(t, is.Len(postsTable.Rows, 2))
assert.Assert(t, is.Len(postTagsTable.Rows, 2))
AssertRowValuesDeepEqual(t, []map[string]any{
{
"tag_id": 2,
"tag_name": "All",
},
{
"tag_id": 5,
"tag_name": "Half",
},
}, tagsTable.Rows)
AssertRowValuesDeepEqual(t, []map[string]any{
{
"post_id": 1,
"title": "First post",
},
{
"post_id": 2,
"title": "Second post",
},
}, postsTable.Rows)
AssertRowValuesDeepEqual(t, []map[string]any{
{
"post_id": ValueRefID(tablePosts, "post_1", "post_id"),
"tag_id": ValueRefID(tableTags, "all", "tag_id"),
},
{
"post_id": ValueRefID(tablePosts, "post_2", "post_id"),
"tag_id": ValueRefID(tableTags, "half", "tag_id"),
},
}, postTagsTable.Rows)
}