aboutsummaryrefslogtreecommitdiff
path: root/dbstore
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2022-03-18 22:11:13 -0400
committerPaul Duncan <pabs@pablotron.org>2022-03-18 22:11:13 -0400
commit4cc13f2fde11241919d3699574c30b2590060833 (patch)
treed538d5c426fa4e2b79013e46545813fe20716860 /dbstore
parent316dfad84db33b1df26734a9ddab1f01a1532b89 (diff)
downloadcvez-4cc13f2fde11241919d3699574c30b2590060833.tar.bz2
cvez-4cc13f2fde11241919d3699574c30b2590060833.zip
add dbstore/cisasearchrow_test.go
Diffstat (limited to 'dbstore')
-rw-r--r--dbstore/cisasearchrow_test.go79
1 files changed, 79 insertions, 0 deletions
diff --git a/dbstore/cisasearchrow_test.go b/dbstore/cisasearchrow_test.go
new file mode 100644
index 0000000..ce03aab
--- /dev/null
+++ b/dbstore/cisasearchrow_test.go
@@ -0,0 +1,79 @@
+package dbstore
+
+import (
+ "fmt"
+ "reflect"
+ "testing"
+)
+
+func TestByRankLen(t *testing.T) {
+ tests := []struct {
+ val []CisaSearchRow
+ exp int
+ } {{
+ val: []CisaSearchRow {},
+ exp: 0,
+ }, {
+ val: []CisaSearchRow { {}, {}, {}, {} },
+ exp: 4,
+ }}
+
+ for _, test := range(tests) {
+ t.Run(fmt.Sprintf("%d", test.exp), func(t *testing.T) {
+ got := byRank(test.val).Len()
+ if got != test.exp {
+ t.Errorf("got %d, exp %d", got, test.exp)
+ }
+ })
+ }
+}
+
+func TestByRankLess(t *testing.T) {
+ tests := []struct {
+ key string
+ val []CisaSearchRow
+ exp bool
+ } {{
+ key: "lt",
+ val: []CisaSearchRow { { Rank: 0 }, { Rank: 1 } },
+ exp: true,
+ }, {
+ key: "eq",
+ val: []CisaSearchRow { { Rank: 1 }, { Rank: 1 } },
+ exp: false,
+ }, {
+ key: "gt",
+ val: []CisaSearchRow { { Rank: 1 }, { Rank: 0 } },
+ exp: false,
+ }}
+
+ for _, test := range(tests) {
+ t.Run(test.key, func(t *testing.T) {
+ got := byRank(test.val).Less(0, 1)
+ if got != test.exp {
+ t.Errorf("got %v, exp %v", got, test.exp)
+ }
+ })
+ }
+}
+
+func TestByRankSwap(t *testing.T) {
+ tests := []struct {
+ key string
+ val []CisaSearchRow
+ exp []CisaSearchRow
+ } {{
+ key: "yup",
+ val: []CisaSearchRow { { Rank: 0 }, { Rank: 1 } },
+ exp: []CisaSearchRow { { Rank: 1 }, { Rank: 0 } },
+ }}
+
+ for _, test := range(tests) {
+ t.Run(test.key, func(t *testing.T) {
+ byRank(test.val).Swap(0, 1)
+ if !reflect.DeepEqual(test.val, test.exp) {
+ t.Errorf("got %#v, exp %#v", test.val, test.exp)
+ }
+ })
+ }
+}