mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
f77322b3fb
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>
46 lines
911 B
Go
46 lines
911 B
Go
package topdown
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/open-policy-agent/opa/v1/ast"
|
|
"github.com/open-policy-agent/opa/v1/storage"
|
|
inmem "github.com/open-policy-agent/opa/v1/storage/inmem/test"
|
|
)
|
|
|
|
func TestNetCIDRExpandCancellation(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
ctx := t.Context()
|
|
|
|
compiler := compileModules([]string{
|
|
`
|
|
package test
|
|
|
|
p if { net.cidr_expand("1.0.0.0/1") } # generating 2**31 hosts will take a while...
|
|
`,
|
|
})
|
|
|
|
store := inmem.New()
|
|
txn := storage.NewTransactionOrDie(ctx, store)
|
|
cancel := NewCancel()
|
|
|
|
query := NewQuery(ast.MustParseBody("data.test.p")).
|
|
WithCompiler(compiler).
|
|
WithStore(store).
|
|
WithTransaction(txn).
|
|
WithCancel(cancel)
|
|
|
|
go func() {
|
|
time.Sleep(time.Millisecond * 50)
|
|
cancel.Cancel()
|
|
}()
|
|
|
|
qrs, err := query.Run(ctx)
|
|
|
|
if err == nil || err.(*Error).Code != CancelErr {
|
|
t.Fatalf("Expected cancel error but got: %v (err: %v)", qrs, err)
|
|
}
|
|
}
|