Commit 2fe8b68a authored by Steven Allen's avatar Steven Allen

test(query): be thurough

parent ae428d8d
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
) )
func testKeyFilter(t *testing.T, f Filter, keys []string, expect []string) { func testKeyFilter(t *testing.T, f Filter, keys []string, expect []string) {
t.Helper()
e := make([]Entry, len(keys)) e := make([]Entry, len(keys))
for i, k := range keys { for i, k := range keys {
e[i] = Entry{Key: k} e[i] = Entry{Key: k}
...@@ -37,6 +38,8 @@ func TestFilterKeyCompare(t *testing.T) { ...@@ -37,6 +38,8 @@ func TestFilterKeyCompare(t *testing.T) {
testKeyFilter(t, FilterKeyCompare{GreaterThan, "/ab"}, sampleKeys, []string{ testKeyFilter(t, FilterKeyCompare{GreaterThan, "/ab"}, sampleKeys, []string{
"/ab/c", "/ab/c",
"/ab/cd", "/ab/cd",
"/ab/ef",
"/ab/fg",
"/abce", "/abce",
"/abcf", "/abcf",
}) })
...@@ -51,6 +54,8 @@ func TestFilterKeyPrefix(t *testing.T) { ...@@ -51,6 +54,8 @@ func TestFilterKeyPrefix(t *testing.T) {
testKeyFilter(t, FilterKeyPrefix{"/a"}, sampleKeys, []string{ testKeyFilter(t, FilterKeyPrefix{"/a"}, sampleKeys, []string{
"/ab/c", "/ab/c",
"/ab/cd", "/ab/cd",
"/ab/ef",
"/ab/fg",
"/a", "/a",
"/abce", "/abce",
"/abcf", "/abcf",
...@@ -59,5 +64,7 @@ func TestFilterKeyPrefix(t *testing.T) { ...@@ -59,5 +64,7 @@ func TestFilterKeyPrefix(t *testing.T) {
testKeyFilter(t, FilterKeyPrefix{"/ab/"}, sampleKeys, []string{ testKeyFilter(t, FilterKeyPrefix{"/ab/"}, sampleKeys, []string{
"/ab/c", "/ab/c",
"/ab/cd", "/ab/cd",
"/ab/ef",
"/ab/fg",
}) })
} }
...@@ -6,6 +6,8 @@ import ( ...@@ -6,6 +6,8 @@ import (
) )
func testKeyOrder(t *testing.T, f Order, keys []string, expect []string) { func testKeyOrder(t *testing.T, f Order, keys []string, expect []string) {
t.Helper()
e := make([]Entry, len(keys)) e := make([]Entry, len(keys))
for i, k := range keys { for i, k := range keys {
e[i] = Entry{Key: k} e[i] = Entry{Key: k}
...@@ -39,12 +41,16 @@ func TestOrderByKey(t *testing.T) { ...@@ -39,12 +41,16 @@ func TestOrderByKey(t *testing.T) {
"/ab", "/ab",
"/ab/c", "/ab/c",
"/ab/cd", "/ab/cd",
"/ab/ef",
"/ab/fg",
"/abce", "/abce",
"/abcf", "/abcf",
}) })
testKeyOrder(t, OrderByKeyDescending{}, sampleKeys, []string{ testKeyOrder(t, OrderByKeyDescending{}, sampleKeys, []string{
"/abcf", "/abcf",
"/abce", "/abce",
"/ab/fg",
"/ab/ef",
"/ab/cd", "/ab/cd",
"/ab/c", "/ab/c",
"/ab", "/ab",
......
...@@ -9,6 +9,8 @@ import ( ...@@ -9,6 +9,8 @@ import (
var sampleKeys = []string{ var sampleKeys = []string{
"/ab/c", "/ab/c",
"/ab/cd", "/ab/cd",
"/ab/ef",
"/ab/fg",
"/a", "/a",
"/abce", "/abce",
"/abcf", "/abcf",
...@@ -60,8 +62,8 @@ func TestNaiveQueryApply(t *testing.T) { ...@@ -60,8 +62,8 @@ func TestNaiveQueryApply(t *testing.T) {
q = Query{Offset: 3, Limit: 2} q = Query{Offset: 3, Limit: 2}
testNaiveQueryApply(t, q, sampleKeys, []string{ testNaiveQueryApply(t, q, sampleKeys, []string{
"/abce", "/ab/fg",
"/abcf", "/a",
}) })
f := &FilterKeyCompare{Op: Equal, Key: "/ab"} f := &FilterKeyCompare{Op: Equal, Key: "/ab"}
...@@ -74,12 +76,16 @@ func TestNaiveQueryApply(t *testing.T) { ...@@ -74,12 +76,16 @@ func TestNaiveQueryApply(t *testing.T) {
testNaiveQueryApply(t, q, sampleKeys, []string{ testNaiveQueryApply(t, q, sampleKeys, []string{
"/ab/c", "/ab/c",
"/ab/cd", "/ab/cd",
"/ab/ef",
"/ab/fg",
}) })
q = Query{Orders: []Order{OrderByKeyDescending{}}} q = Query{Orders: []Order{OrderByKeyDescending{}}}
testNaiveQueryApply(t, q, sampleKeys, []string{ testNaiveQueryApply(t, q, sampleKeys, []string{
"/abcf", "/abcf",
"/abce", "/abce",
"/ab/fg",
"/ab/ef",
"/ab/cd", "/ab/cd",
"/ab/c", "/ab/c",
"/ab", "/ab",
...@@ -87,18 +93,20 @@ func TestNaiveQueryApply(t *testing.T) { ...@@ -87,18 +93,20 @@ func TestNaiveQueryApply(t *testing.T) {
}) })
q = Query{ q = Query{
Limit: 3, Limit: 2,
Offset: 1, Offset: 1,
Prefix: "/ab", Prefix: "/ab",
Orders: []Order{OrderByKey{}}, Orders: []Order{OrderByKey{}},
} }
testNaiveQueryApply(t, q, sampleKeys, []string{ testNaiveQueryApply(t, q, sampleKeys, []string{
"/ab/cd", "/ab/cd",
"/ab/ef",
}) })
} }
func TestLimit(t *testing.T) { func TestLimit(t *testing.T) {
testKeyLimit := func(t *testing.T, limit int, keys []string, expect []string) { testKeyLimit := func(t *testing.T, limit int, keys []string, expect []string) {
t.Helper()
e := make([]Entry, len(keys)) e := make([]Entry, len(keys))
for i, k := range keys { for i, k := range keys {
e[i] = Entry{Key: k} e[i] = Entry{Key: k}
...@@ -112,6 +120,8 @@ func TestLimit(t *testing.T) { ...@@ -112,6 +120,8 @@ func TestLimit(t *testing.T) {
testKeyLimit(t, 0, sampleKeys, []string{ // none testKeyLimit(t, 0, sampleKeys, []string{ // none
"/ab/c", "/ab/c",
"/ab/cd", "/ab/cd",
"/ab/ef",
"/ab/fg",
"/a", "/a",
"/abce", "/abce",
"/abcf", "/abcf",
...@@ -121,6 +131,8 @@ func TestLimit(t *testing.T) { ...@@ -121,6 +131,8 @@ func TestLimit(t *testing.T) {
testKeyLimit(t, 10, sampleKeys, []string{ // large testKeyLimit(t, 10, sampleKeys, []string{ // large
"/ab/c", "/ab/c",
"/ab/cd", "/ab/cd",
"/ab/ef",
"/ab/fg",
"/a", "/a",
"/abce", "/abce",
"/abcf", "/abcf",
...@@ -136,6 +148,7 @@ func TestLimit(t *testing.T) { ...@@ -136,6 +148,7 @@ func TestLimit(t *testing.T) {
func TestOffset(t *testing.T) { func TestOffset(t *testing.T) {
testOffset := func(t *testing.T, offset int, keys []string, expect []string) { testOffset := func(t *testing.T, offset int, keys []string, expect []string) {
t.Helper()
e := make([]Entry, len(keys)) e := make([]Entry, len(keys))
for i, k := range keys { for i, k := range keys {
e[i] = Entry{Key: k} e[i] = Entry{Key: k}
...@@ -149,6 +162,8 @@ func TestOffset(t *testing.T) { ...@@ -149,6 +162,8 @@ func TestOffset(t *testing.T) {
testOffset(t, 0, sampleKeys, []string{ // none testOffset(t, 0, sampleKeys, []string{ // none
"/ab/c", "/ab/c",
"/ab/cd", "/ab/cd",
"/ab/ef",
"/ab/fg",
"/a", "/a",
"/abce", "/abce",
"/abcf", "/abcf",
...@@ -159,6 +174,8 @@ func TestOffset(t *testing.T) { ...@@ -159,6 +174,8 @@ func TestOffset(t *testing.T) {
}) })
testOffset(t, 2, sampleKeys, []string{ testOffset(t, 2, sampleKeys, []string{
"/ab/ef",
"/ab/fg",
"/a", "/a",
"/abce", "/abce",
"/abcf", "/abcf",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment