add qs joins

This commit is contained in:
Aneurin Barker Snook
2023-10-16 17:21:28 +01:00
parent d51c1846ff
commit d94f155714
4 changed files with 175 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
package qs
import "testing"
func TestReadJoins(t *testing.T) {
type TestCase struct {
Input string
Opt *ReadJoinsOptions
Output Joins
Err error
}
testCases := []TestCase{
{Input: ""},
{
Input: "join=ingredient",
Output: Joins{"ingredient": true},
},
{
Input: "join=author&join=ingredient",
Output: Joins{"author": true, "ingredient": true},
},
}
for n, tc := range testCases {
t.Logf("(%d) Testing %q with options %+v", n, tc.Input, tc.Opt)
joins, err := ReadStringJoins(tc.Input, nil)
if err != tc.Err {
t.Errorf("Expected error %v, got %v", tc.Err, err)
}
if tc.Err != nil {
continue
}
if tc.Output == nil && joins != nil {
t.Error("Expected nil")
continue
}
if len(joins) != len(tc.Output) {
t.Errorf("Expected %d joins, got %d", len(tc.Output), len(joins))
}
for name, join := range tc.Output {
if join != joins[name] {
t.Errorf("Expected %t for join %s, got %t", join, name, joins[name])
}
}
}
}