Files
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

87 lines
1.9 KiB
Go

// Copyright 2018 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 (
"testing"
"github.com/open-policy-agent/opa/v1/ast"
)
func TestOPARuntime(t *testing.T) {
t.Parallel()
ctx := t.Context()
q := NewQuery(ast.MustParseBody("opa.runtime(x)")) // no runtime info
rs, err := q.Run(ctx)
if err != nil {
t.Fatal(err)
} else if len(rs) != 1 {
t.Fatal("Expected result set to contain exactly one result")
}
term := rs[0][ast.Var("x")]
exp := ast.ObjectTerm()
if ast.Compare(term, exp) != 0 {
t.Fatalf("Expected %v but got %v", exp, term)
}
q = NewQuery(ast.MustParseBody("opa.runtime(x)")).WithRuntime(ast.MustParseTerm(`{"config": {"a": 1}}`))
rs, err = q.Run(ctx)
if err != nil {
t.Fatal(err)
} else if len(rs) != 1 {
t.Fatal("Expected result set to contain exactly one result")
}
term = rs[0][ast.Var("x")]
exp = ast.MustParseTerm(`{"config": {"a": 1}}`)
if ast.Compare(term, exp) != 0 {
t.Fatalf("Expected %v but got %v", exp, term)
}
}
func TestOPARuntimeConfigMasking(t *testing.T) {
t.Parallel()
ctx := t.Context()
q := NewQuery(ast.MustParseBody("opa.runtime(x)")).WithRuntime(ast.MustParseTerm(`{"config": {
"labels": {"foo": "bar"},
"services": {
"foo": {
"url": "https://remote.example.com",
"credentials": {
"oauth2": {
"client_id": "opa_client",
"client_secret": "sup3rs3cr3t"
}
}
}
}
}}`))
rs, err := q.Run(ctx)
if err != nil {
t.Fatal(err)
} else if len(rs) != 1 {
t.Fatal("Expected result set to contain exactly one result")
}
term := rs[0][ast.Var("x")]
exp := ast.MustParseTerm(`{"config": {
"labels": {"foo": "bar"},
"services": {
"foo": {
"url": "https://remote.example.com"
}
}
}}`)
if ast.Compare(term, exp) != 0 {
t.Fatalf("Expected %v but got %v", exp, term)
}
}