test: check for @-modifier without using engine internals

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
Bryan Boreham 2024-05-04 14:22:28 +01:00
parent 2b0c87b1b6
commit a6e427660a

View file

@ -676,8 +676,7 @@ func atModifierTestCases(exprStr string, evalTime time.Time) ([]atModifierTestCa
// If there is a subquery, then the selectors inside it don't get the @ timestamp. // If there is a subquery, then the selectors inside it don't get the @ timestamp.
// If any selector already has the @ timestamp set, then it is untouched. // If any selector already has the @ timestamp set, then it is untouched.
parser.Inspect(expr, func(node parser.Node, path []parser.Node) error { parser.Inspect(expr, func(node parser.Node, path []parser.Node) error {
_, _, subqTs := subqueryTimes(path) if hasAtModifier(path) {
if subqTs != nil {
// There is a subquery with timestamp in the path, // There is a subquery with timestamp in the path,
// hence don't change any timestamps further. // hence don't change any timestamps further.
return nil return nil
@ -727,6 +726,17 @@ func atModifierTestCases(exprStr string, evalTime time.Time) ([]atModifierTestCa
return testCases, nil return testCases, nil
} }
func hasAtModifier(path []parser.Node) bool {
for _, node := range path {
if n, ok := node.(*parser.SubqueryExpr); ok {
if n.Timestamp != nil {
return true
}
}
}
return false
}
// exec processes a single step of the test. // exec processes a single step of the test.
func (t *test) exec(tc testCommand, engine QueryEngine) error { func (t *test) exec(tc testCommand, engine QueryEngine) error {
switch cmd := tc.(type) { switch cmd := tc.(type) {