Files
releases/v1/topdown/time_test.go
T
Ville Vesilehto f77322b3fb build: bump Go version requirement to 1.24 (#7839)
Go 1.23 is no longer supported as per Go release policy.

Changes:

- Use Go v1.24.6 as the project SDK requirement
- Apply lint fixes for Go 1.24
- Fix "non-constant format string in call" issues as seen in CI.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2025-08-24 09:02:09 +02:00

46 lines
824 B
Go

// Copyright 2020 The OPA Authors. All rights reserved.
// Use of this source code is governed by an Apache2
// license that can be found in the LICENSE file.
package topdown
import (
"fmt"
"testing"
"time"
"github.com/open-policy-agent/opa/v1/ast"
)
func TestTimeSeeding(t *testing.T) {
t.Parallel()
query := `time.now_ns(x)`
clock := time.Now()
q := NewQuery(ast.MustParseBody(query)).WithTime(clock).WithCompiler(ast.NewCompiler())
ctx := t.Context()
qrs, err := q.Run(ctx)
if err != nil {
t.Fatal(err)
} else if len(qrs) != 1 {
t.Fatal("expected exactly one result but got:", qrs)
}
exp := ast.MustParseTerm(fmt.Sprintf(`
{
{
x: %v
}
}
`, clock.UnixNano()))
result := queryResultSetToTerm(qrs)
if !result.Equal(exp) {
t.Fatalf("expected %v but got %v", exp, result)
}
}