From 6415ef17f36b59cbe3db978309bbba321faf2f91 Mon Sep 17 00:00:00 2001 From: Dmitry Frenkel Date: Mon, 3 Nov 2025 21:26:53 -0800 Subject: [PATCH] Add test cases for consistent cache behavior Using `rand.intn` test cases as template, we create similar tests that verify consistent values returned by `uuid.rfc4122` and `time.now_ns` builtins when invoked during the same evaluation/query. These tests can also aid compliance regression testing for other OPA implementations, such as Swift. Signed-off-by: Dmitry Frenkel --- v1/test/cases/testdata/v1/time/test-time-0972.yaml | 13 +++++++++++++ .../cases/testdata/v1/uuid/test-uuid-rfc4122.yaml | 13 +++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 v1/test/cases/testdata/v1/time/test-time-0972.yaml create mode 100644 v1/test/cases/testdata/v1/uuid/test-uuid-rfc4122.yaml diff --git a/v1/test/cases/testdata/v1/time/test-time-0972.yaml b/v1/test/cases/testdata/v1/time/test-time-0972.yaml new file mode 100644 index 0000000000..3aed69b39b --- /dev/null +++ b/v1/test/cases/testdata/v1/time/test-time-0972.yaml @@ -0,0 +1,13 @@ +--- +cases: + - note: time.now_ns/consistent value for same evaluation + query: data.test.p = x + modules: + - | + package test + + p := count(times) if { + times := {time.now_ns() | numbers.range(1, 100)[_]} + } + want_result: + - x: 1 diff --git a/v1/test/cases/testdata/v1/uuid/test-uuid-rfc4122.yaml b/v1/test/cases/testdata/v1/uuid/test-uuid-rfc4122.yaml new file mode 100644 index 0000000000..8979981153 --- /dev/null +++ b/v1/test/cases/testdata/v1/uuid/test-uuid-rfc4122.yaml @@ -0,0 +1,13 @@ +--- +cases: + - note: uuid.rfc4122/consistent values for same arguments + query: data.test.p = x + modules: + - | + package test + + p := count(uuids) if { + uuids := {uuid.rfc4122("key") | numbers.range(1, 100)[_]} + } + want_result: + - x: 1