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.2 KiB
Go

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 _, tc := range testCases {
actualStr := tc.Input.String()
if actualStr != tc.ExpectedStr {
t.Logf("Expected: %q", tc.ExpectedStr)
t.Logf("Actual: %q", actualStr)
t.Fail()
}
if len(tc.Input.Params) != len(tc.ExpectedParams) {
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])
}
}
}
}