Skip to content

Commit

Permalink
Removed Test for impossible Scenario
Browse files Browse the repository at this point in the history
The DecisionLabel is no longer a Field of the DecisionOptions Struct because the field will always be nil. It is now generated directly within the Decision() Function where it can be populated. Due to this, the scenario being tested is impossible. For coverage, the scenario being tested by TestDecisionLoggingWithDecisionLabel is formally covered by the tests which confirm the proper function of the DecisionLabelAdd Builtin Function.

Signed-off-by: Thomas Sidebottom <thomas.sidebottom@va.gov>
  • Loading branch information
tsidebottom committed Apr 17, 2024
1 parent 27a308a commit b837581
Showing 1 changed file with 0 additions and 65 deletions.
65 changes: 0 additions & 65 deletions sdk/opa_test.go
Expand Up @@ -1684,71 +1684,6 @@ main = time.now_ns()

}

func TestDecisionLoggingWithDecisionLabel(t *testing.T) {

ctx := context.Background()

server := sdktest.MustNewServer(
sdktest.MockBundle("/bundles/bundle.tar.gz", map[string]string{
"main.rego": `
package system
main = time.now_ns()
`,
}),
)

defer server.Stop()

config := fmt.Sprintf(`{
"services": {
"test": {
"url": %q
}
},
"bundles": {
"test": {
"resource": "/bundles/bundle.tar.gz"
}
},
"decision_logs": {
"console": true
}
}`, server.URL())

testLogger := loggingtest.New()
opa, err := sdk.New(ctx, sdk.Options{
Config: strings.NewReader(config),
ConsoleLogger: testLogger,
})
if err != nil {
t.Fatal(err)
}

defer opa.Stop(ctx)

// testing here
decisionLabel := builtins.DecisionLabel{}
decisionLabel.Add("foo", "bar")

if _, err := opa.Decision(ctx, sdk.DecisionOptions{
Now: time.Unix(0, 1619868194450288000).UTC(),
}); err != nil {
t.Fatal(err)
}

entries := testLogger.Entries()

if dl, ok := entries[0].Fields["decision_label"]; ok {
if _, ok := dl.(map[string]interface{})["foo"]; !ok {
t.Fatal("DecisionLabel was not preserved during evaluation.")
}
} else {
t.Fatal("DecisionLabel was missing.")
}

}

func TestQueryCaching(t *testing.T) {

ctx := context.Background()
Expand Down

0 comments on commit b837581

Please sign in to comment.