From dad69b866004aa3ca80591b62d50da72fd040ce8 Mon Sep 17 00:00:00 2001 From: Francisco Rodrigues Date: Thu, 11 Apr 2024 07:13:33 -0300 Subject: [PATCH] sdk: refactor test The bug in activating bundles in the SDK is not necessarily related to optimized bundles, but specifically for v1 bundles. So the test was renamed to `TestActivateV1Bundles` and the test structure simplified to better describe the scenario. Signed-off-by: Francisco Rodrigues --- sdk/opa_test.go | 12 ++++----- sdk/testdata/Makefile | 6 ++--- sdk/testdata/policy1.tar.gz | Bin 434 -> 0 bytes sdk/testdata/policy1/.manifest | 3 --- sdk/testdata/policy1/policy.rego | 24 ------------------ sdk/testdata/policy2.tar.gz | Bin 262 -> 0 bytes sdk/testdata/policy2/.manifest | 3 --- sdk/testdata/v1bundle.tar.gz | Bin 0 -> 281 bytes sdk/testdata/v1bundle/.manifest | 3 +++ .../{policy2 => v1bundle}/policy.rego | 4 +-- 10 files changed, 11 insertions(+), 44 deletions(-) delete mode 100644 sdk/testdata/policy1.tar.gz delete mode 100644 sdk/testdata/policy1/.manifest delete mode 100644 sdk/testdata/policy1/policy.rego delete mode 100644 sdk/testdata/policy2.tar.gz delete mode 100644 sdk/testdata/policy2/.manifest create mode 100644 sdk/testdata/v1bundle.tar.gz create mode 100644 sdk/testdata/v1bundle/.manifest rename sdk/testdata/{policy2 => v1bundle}/policy.rego (74%) diff --git a/sdk/opa_test.go b/sdk/opa_test.go index 74ba4edd163..0fa1ccc8bf2 100644 --- a/sdk/opa_test.go +++ b/sdk/opa_test.go @@ -2845,7 +2845,7 @@ func toMetricMap(metrics []*promdto.MetricFamily) map[string]bool { return metricMap } -func TestActivateOptimizedV1Bundles(t *testing.T) { +func TestActivateV1Bundles(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*100) defer cancel() @@ -2860,11 +2860,8 @@ func TestActivateOptimizedV1Bundles(t *testing.T) { } }, "bundles": { - "policy1": { - "resource": "/policy1.tar.gz" - }, - "policy2": { - "resource": "/policy2.tar.gz" + "v1bundle": { + "resource": "/v1bundle.tar.gz" } } }`, server.URL) @@ -2872,6 +2869,7 @@ func TestActivateOptimizedV1Bundles(t *testing.T) { opa, err := sdk.New(ctx, sdk.Options{ ID: "sdk-id-0", Config: strings.NewReader(config), + Logger: logging.New(), V1Compatible: true, }) @@ -2882,7 +2880,7 @@ func TestActivateOptimizedV1Bundles(t *testing.T) { } d, err := opa.Decision(context.Background(), sdk.DecisionOptions{ - Path: "policy2/authz", + Path: "v1bundle/authz", Input: map[string]interface{}{ "role": "admin", }, diff --git a/sdk/testdata/Makefile b/sdk/testdata/Makefile index a29403de90d..1268401628e 100644 --- a/sdk/testdata/Makefile +++ b/sdk/testdata/Makefile @@ -2,8 +2,6 @@ disco.tar.gz: bundle/data.json opa build bundle mv bundle.tar.gz disco.tar.gz -policy1.tar.gz: - opa build --partial-namespace policy1_partial --optimize=1 --v1-compatible -o policy1.tar.gz -b policy1/ +v1bundle.tar.gz: v1bundle/.manifest v1bundle/policy.rego + opa build --v1-compatible -o v1bundle.tar.gz -b v1bundle/ -policy2.tar.gz: - opa build --partial-namespace policy2_partial --optimize=1 --v1-compatible -o policy2.tar.gz -b policy2/ diff --git a/sdk/testdata/policy1.tar.gz b/sdk/testdata/policy1.tar.gz deleted file mode 100644 index 0357fcd4c29366dce14884238d6bcbda7f26f3aa..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 434 zcmV;j0ZslNiwFP!00000|Lm4gZ<{a>fb&}a3d_$GIYY>#X!#}6bh?4ldNnpOrdu23 zzfU93F;XoLYZ4*(d+|lK?;Nb}U|CY2*tO2?aPDcR9MlmcvO33Ac!{v_j zhqeji7x3S;rhjfG><{eLM~K{zrK^Lk^s6eDwKKYSk%?Ci?n7&w^FL2l6aTYZev1BI zgPMvbdQiN-e8$Ka_k-&l-?KaG0`J}r{VdkxgC>(8S{G6T%n;duu~O}*HGxwb9$)!p z%XefN#n|!pG1)j#a;&oD7?iJ2B1m>Oj{jX*qQrctY+w2U+SYAIyfcb#x%g&W@uW)e zdy&zV4yYUSii$^7_8Sn5E64!iif{RGd(nEYYjUTfPgm=S|9P6NqW{-m;{R~@jEzNm&)`nHLEwBOa2Fr?1bvTqFTshFL$VAZ z9g=nNyo{O`%cLT!cd7}Ot8w=Ge?9eI!a9%sUxU5y>RC71S+Nn~UU=t1BQ{?|uc^2f clhz=#p+7@b>Mt40`AOwZ^&pD|L62|8=d_Iscd7Y5PJu zEf0?`M5lWiO_DUGr@d@9vL_R@5MSTi%Sqg@^XC)%WeuQ%Fn(9&*yNEX$VfBLD#Z M|AVy#O#l!80KE2olmGw# diff --git a/sdk/testdata/policy2/.manifest b/sdk/testdata/policy2/.manifest deleted file mode 100644 index 41f21d76b4b..00000000000 --- a/sdk/testdata/policy2/.manifest +++ /dev/null @@ -1,3 +0,0 @@ -{ - "roots": ["policy2"] -} \ No newline at end of file diff --git a/sdk/testdata/v1bundle.tar.gz b/sdk/testdata/v1bundle.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..9d7cce5ef2e707437eaeb9bb99c76520a6c98358 GIT binary patch literal 281 zcmV+!0p|W6iwFP!00000|LoPVPQx$|2H>ptDNgQ+k~3{OM9L5eMz(Hx#cIW_U0r^`lL!`S%`R|HWlFXliv)O165$A~S6%Q*SPQN^3hC*N|GQjah z`V<36pW(NA?SI@KF}$*KkC2>Eu@Mi^wni1bGkUqry;`{+?r|*tqMYsJe=1V`PotO1 zXSq_a`wbXtRVSk%kdYo=psJyhCMd=xaC@_8uA4=}CZH_&ZSSwWxLjvv$SY_qat5Rt2-5FydFpI|ExT?|MRPq|5F&aR~sF)v%KQ`l6&VU f@am5576QLd!A+7R`G?*D00960>5&Kr01yBG11^We literal 0 HcmV?d00001 diff --git a/sdk/testdata/v1bundle/.manifest b/sdk/testdata/v1bundle/.manifest new file mode 100644 index 00000000000..aa0f6db355f --- /dev/null +++ b/sdk/testdata/v1bundle/.manifest @@ -0,0 +1,3 @@ +{ + "roots": ["v1bundle"] +} \ No newline at end of file diff --git a/sdk/testdata/policy2/policy.rego b/sdk/testdata/v1bundle/policy.rego similarity index 74% rename from sdk/testdata/policy2/policy.rego rename to sdk/testdata/v1bundle/policy.rego index 5a5debfe818..fce2a458888 100644 --- a/sdk/testdata/policy2/policy.rego +++ b/sdk/testdata/v1bundle/policy.rego @@ -1,6 +1,4 @@ -package policy2 - -import rego.v1 +package v1bundle default authz := false