Skip to content

Commit

Permalink
sdk: refactor test
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
xico42 committed Apr 11, 2024
1 parent 6001606 commit dad69b8
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 44 deletions.
12 changes: 5 additions & 7 deletions sdk/opa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -2860,18 +2860,16 @@ func TestActivateOptimizedV1Bundles(t *testing.T) {
}
},
"bundles": {
"policy1": {
"resource": "/policy1.tar.gz"
},
"policy2": {
"resource": "/policy2.tar.gz"
"v1bundle": {
"resource": "/v1bundle.tar.gz"
}
}
}`, server.URL)

opa, err := sdk.New(ctx, sdk.Options{
ID: "sdk-id-0",
Config: strings.NewReader(config),
Logger: logging.New(),
V1Compatible: true,
})

Expand All @@ -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",
},
Expand Down
6 changes: 2 additions & 4 deletions sdk/testdata/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Binary file removed sdk/testdata/policy1.tar.gz
Binary file not shown.
3 changes: 0 additions & 3 deletions sdk/testdata/policy1/.manifest

This file was deleted.

24 changes: 0 additions & 24 deletions sdk/testdata/policy1/policy.rego

This file was deleted.

Binary file removed sdk/testdata/policy2.tar.gz
Binary file not shown.
3 changes: 0 additions & 3 deletions sdk/testdata/policy2/.manifest

This file was deleted.

Binary file added sdk/testdata/v1bundle.tar.gz
Binary file not shown.
3 changes: 3 additions & 0 deletions sdk/testdata/v1bundle/.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"roots": ["v1bundle"]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package policy2

import rego.v1
package v1bundle

default authz := false

Expand Down

0 comments on commit dad69b8

Please sign in to comment.