This repository has been archived on 2026-10-03. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
aql/query_test.go
T

52 lines
1.3 KiB
Go
Raw Normal View History

2023-10-07 10:22:56 +01:00
package arango
import (
"testing"
)
func TestQueryAppend(t *testing.T) {
type TestCase struct {
Input *Query
ExpectedStr string
ExpectedParams map[string]any
}
testCases := []TestCase{
{
Input: NewQuery().
Append("FOR doc IN @@collection", "recipes").
Append("FILTER doc.title == @title", "Spaghetti").
Append("RETURN doc"),
ExpectedStr: `FOR doc IN @@collection
FILTER doc.title == @title
RETURN doc`,
ExpectedParams: map[string]any{
"collection": "recipes",
"title": "Spaghetti",
},
},
}
for _, testCase := range testCases {
actualStr := testCase.Input.String()
if actualStr != testCase.ExpectedStr {
t.Logf("Expected: %q", testCase.ExpectedStr)
t.Logf("Actual: %q", actualStr)
t.Fail()
}
if len(testCase.Input.Params) != len(testCase.ExpectedParams) {
t.Errorf("Expected %d parameters; got %d", len(testCase.ExpectedParams), len(testCase.Input.Params))
}
for name, value := range testCase.ExpectedParams {
if testCase.Input.Params[name] == nil {
t.Errorf("Expected parameter %q to be %q; got nil", name, value)
} else if testCase.Input.Params[name] != value {
t.Errorf("Expected parameter %q to be %q; got %q", name, value, testCase.Input.Params[name])
}
}
}
}