-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq_collection_ref_test.go
113 lines (107 loc) · 3.03 KB
/
q_collection_ref_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
package dal
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestNewCollectionRef(t *testing.T) {
t.Run("panics_on_empty_name", func(t *testing.T) {
assert.Panics(t, func() {
NewCollectionRef("", "e", nil)
})
})
someParentKey := NewKeyWithID("some_parent", "some_id")
type args struct {
name string
alias string
parent *Key
}
tests := []struct {
name string
args args
want CollectionRef
}{
{name: "only_name", args: args{name: "some_target", alias: "", parent: nil}, want: CollectionRef{name: "some_target", alias: "", parent: nil}},
{name: "name_and_alias", args: args{name: "some_target", alias: "st", parent: nil}, want: CollectionRef{name: "some_target", alias: "st", parent: nil}},
{name: "same_name_and_alias", args: args{name: "some_target", alias: "some_target", parent: nil}, want: CollectionRef{name: "some_target", alias: "", parent: nil}},
{name: "name_with_parent", args: args{name: "some_target", alias: "", parent: someParentKey}, want: CollectionRef{name: "some_target", alias: "", parent: someParentKey}},
{name: "name_and_alias_with_parent", args: args{name: "some_target", alias: "st", parent: someParentKey}, want: CollectionRef{name: "some_target", alias: "st", parent: someParentKey}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, NewCollectionRef(tt.args.name, tt.args.alias, tt.args.parent), "NewCollectionRef(%v, %v, %v)", tt.args.name, tt.args.alias, tt.args.parent)
})
}
}
func TestCollectionRef(t *testing.T) {
type expected struct {
string string
path string
}
for _, tt := range []struct {
name string
collectionRef CollectionRef
expected expected
}{
{
name: "empty",
collectionRef: CollectionRef{},
expected: expected{
string: "",
path: "",
},
},
{
name: "name_only",
collectionRef: CollectionRef{
name: "collection1",
},
expected: expected{
string: "collection1",
path: "collection1",
},
},
{
name: "no_parent_with_alias",
collectionRef: CollectionRef{
name: "collection1",
alias: "c1",
},
expected: expected{
string: "collection1 AS c1",
path: "collection1",
},
},
{
name: "single_parent",
collectionRef: CollectionRef{
name: "collection1",
parent: &Key{collection: "collection2", ID: "id2"},
},
expected: expected{
string: "collection2/id2/collection1",
path: "collection2/id2/collection1",
},
},
{
name: "single_parent_with_alias",
collectionRef: CollectionRef{
name: "collection1",
alias: "c1",
parent: &Key{collection: "collection2", ID: "id2"},
},
expected: expected{
string: "collection2/id2/collection1 AS c1",
path: "collection2/id2/collection1",
},
},
} {
t.Run(tt.name, func(t *testing.T) {
t.Run("string", func(t *testing.T) {
assert.Equal(t, tt.expected.string, tt.collectionRef.String())
})
t.Run("path", func(t *testing.T) {
assert.Equal(t, tt.expected.path, tt.collectionRef.Path())
})
})
}
}