standardise arango tests
This commit is contained in:
+52
-8
@@ -12,6 +12,7 @@ func TestQueryAppend(t *testing.T) {
|
||||
}
|
||||
|
||||
testCases := []TestCase{
|
||||
// Append with parameters
|
||||
{
|
||||
Input: NewQuery().
|
||||
Append("FOR doc IN @@collection", "recipes").
|
||||
@@ -19,6 +20,51 @@ func TestQueryAppend(t *testing.T) {
|
||||
Append("RETURN doc"),
|
||||
ExpectedStr: `FOR doc IN @@collection
|
||||
FILTER doc.title == @title
|
||||
RETURN doc`,
|
||||
ExpectedParams: map[string]any{
|
||||
"collection": "recipes",
|
||||
"title": "Spaghetti",
|
||||
},
|
||||
},
|
||||
// Append with too many parameters
|
||||
{
|
||||
Input: NewQuery().
|
||||
Append("FOR doc IN @@collection", "recipes", "ignored").
|
||||
Append("FILTER doc.title == @title", "Spaghetti", "also ignored").
|
||||
Append("RETURN doc"),
|
||||
ExpectedStr: `FOR doc IN @@collection
|
||||
FILTER doc.title == @title
|
||||
RETURN doc`,
|
||||
ExpectedParams: map[string]any{
|
||||
"collection": "recipes",
|
||||
"title": "Spaghetti",
|
||||
},
|
||||
},
|
||||
// Append and bind
|
||||
{
|
||||
Input: NewQuery().
|
||||
Append("FOR doc IN @@collection").
|
||||
Append("FILTER doc.title == @title").
|
||||
Append("RETURN doc").
|
||||
Bind("collection", "recipes").
|
||||
Bind("title", "Spaghetti"),
|
||||
ExpectedStr: `FOR doc IN @@collection
|
||||
FILTER doc.title == @title
|
||||
RETURN doc`,
|
||||
ExpectedParams: map[string]any{
|
||||
"collection": "recipes",
|
||||
"title": "Spaghetti",
|
||||
},
|
||||
},
|
||||
// Append and bind map
|
||||
{
|
||||
Input: NewQuery().
|
||||
Append("FOR doc IN @@collection").
|
||||
Append("FILTER doc.title == @title").
|
||||
Append("RETURN doc").
|
||||
BindMap(map[string]any{"collection": "recipes", "title": "Spaghetti"}),
|
||||
ExpectedStr: `FOR doc IN @@collection
|
||||
FILTER doc.title == @title
|
||||
RETURN doc`,
|
||||
ExpectedParams: map[string]any{
|
||||
"collection": "recipes",
|
||||
@@ -28,23 +74,21 @@ RETURN doc`,
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Logf("Testing %+v", tc.Input)
|
||||
|
||||
actualStr := tc.Input.String()
|
||||
|
||||
if actualStr != tc.ExpectedStr {
|
||||
t.Logf("Expected: %q", tc.ExpectedStr)
|
||||
t.Logf("Actual: %q", actualStr)
|
||||
t.Fail()
|
||||
t.Errorf("Expected %q, got %q", tc.ExpectedStr, actualStr)
|
||||
}
|
||||
|
||||
if len(tc.Input.Params) != len(tc.ExpectedParams) {
|
||||
t.Errorf("Expected %d parameters; got %d", len(tc.ExpectedParams), len(tc.Input.Params))
|
||||
t.Errorf("Expected %d parameters, got %d", len(tc.ExpectedParams), len(tc.Input.Params))
|
||||
}
|
||||
|
||||
for name, value := range tc.ExpectedParams {
|
||||
if tc.Input.Params[name] == nil {
|
||||
t.Errorf("Expected parameter %q to be %q; got nil", name, value)
|
||||
} else if tc.Input.Params[name] != value {
|
||||
t.Errorf("Expected parameter %q to be %q; got %q", name, value, tc.Input.Params[name])
|
||||
if tc.Input.Params[name] != value {
|
||||
t.Errorf("Expected parameter %q to be %v; got %v", name, value, tc.Input.Params[name])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user