-
Notifications
You must be signed in to change notification settings - Fork 4
/
db_util_test.go
152 lines (111 loc) · 2.88 KB
/
db_util_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
145
146
147
148
149
150
151
152
/*
* Copyright (c) 2022 Red Hat, Inc.
* SPDX-License-Identifier: GPL-2.0-or-later
*/
package main
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Psql Tests", func() {
AfterEach(func() {
defer GinkgoRecover()
})
When("notIn", func() {
It("Should return false if a value is not in the slice", func() {
data := []int{
1,
3,
5,
}
res := notIn(data, 2)
Expect(res).To(BeTrue())
})
It("Should return true if a value is in the slice", func() {
data := []int{
1,
3,
5,
}
res := notIn(data, 1)
Expect(res).To(BeFalse())
})
It("Should return true if using an empty slice", func() {
data := []int{}
res := notIn(data, 1)
Expect(res).To(BeTrue())
})
})
When("removeDuplicate", func() {
It("Should return an ordered but unmodified slice", func() {
entries := []entry{
{symId: 3},
{symId: 1},
}
res := removeDuplicate(entries)
Expect(len(res)).To(Equal(2))
Expect(res).To(Equal([]entry{{symId: 1}, {symId: 3}}))
})
It("Should return a new slice with no duplicated values", func() {
entries := []entry{
{symId: 1},
{symId: 3},
{symId: 1},
}
res := removeDuplicate(entries)
Expect(len(res)).To(Equal(2))
Expect(res).To(Equal([]entry{{symId: 1}, {symId: 3}}))
})
It("Should return an empty slice", func() {
entries := []entry{}
res := removeDuplicate(entries)
Expect(len(res)).To(Equal(0))
Expect(res).To(BeNil())
})
})
When("notExcluded", func() {
excluded := []string{"sym1", "sym2"}
It("Should return false if item is in excluded slice", func() {
res := notExcluded("sym1", excluded)
Expect(res).To(BeFalse())
})
It("Should return true if item is not in excluded slice", func() {
res := notExcluded("sym3", excluded)
Expect(res).To(BeTrue())
})
It("Should return true if slice is empty", func() {
res := notExcluded("sym1", []string{})
Expect(res).To(BeTrue())
})
})
When("navigate", func() {
// TODO: `psql.navigate` fn refactor needed
})
Describe("intargets", func() {
targets := []string{"n1", "n2"}
When("There is a target match", func() {
It("Should return true if n1 is a match", func() {
res := intargets(targets, "n1", "n3")
Expect(res).To(BeTrue())
})
It("Should return true if n2 is a match", func() {
res := intargets(targets, "n3", "n2")
Expect(res).To(BeTrue())
})
It("Should return true if both are a match", func() {
res := intargets(targets, "n1", "n2")
Expect(res).To(BeTrue())
})
})
When("There no target match", func() {
It("Should return false if neither is a match", func() {
res := intargets(targets, "n3", "n5")
Expect(res).To(BeFalse())
})
It("Should return false if the target slice is empty", func() {
res := intargets([]string{}, "n1", "n2")
Expect(res).To(BeFalse())
})
})
})
})