github.com/best4tires/kit@v1.0.5/reflex/query_test.go (about) 1 package reflex 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/best4tires/kit/srv" 8 "github.com/best4tires/kit/testutil" 9 ) 10 11 func TestQuery(t *testing.T) { 12 type testType struct { 13 StringValue string `json:"string-value"` 14 IntValue int `json:"int-value"` 15 BoolValue bool `json:"bool-value"` 16 FloatValue float64 `json:"float-value"` 17 } 18 mk := func(s string, n int, b bool, f float64) testType { 19 return testType{s, n, b, f} 20 } 21 22 tests := []struct { 23 in []testType 24 meta srv.Meta 25 exp []testType 26 }{ 27 { 28 in: []testType{ 29 mk("s4", 1, true, 4.0), 30 mk("s3", 2, false, 3.0), 31 mk("s2", 3, false, 2.0), 32 mk("s1", 4, true, 1.0), 33 mk("seb4", 1, true, 4.0), 34 mk("se3", 2, false, 3.0), 35 mk("sb22", 3, false, 2.0), 36 mk("sebe1", 4, true, 1.0), 37 }, 38 meta: srv.Meta{ 39 Sorts: srv.SortComponents{ 40 {Name: "int-value", Order: srv.SortASC}, 41 }, 42 Filters: []srv.Filter{ 43 {Name: "float-value", Comparator: srv.FilterComparatorGreater, Value: "1.9"}, 44 }, 45 Skip: 2, 46 Limit: 2, 47 }, 48 exp: []testType{ 49 mk("s3", 2, false, 3.0), 50 mk("se3", 2, false, 3.0), 51 }, 52 }, 53 } 54 55 for i, test := range tests { 56 t.Run(fmt.Sprintf("test_%02d", i), func(t *testing.T) { 57 res := Query(test.in, test.meta) 58 testutil.AssertEqual(t, test.exp, res) 59 }) 60 } 61 }