Skip to content
Snippets Groups Projects
Commit 5d3f9343 authored by Yordan Kinkov's avatar Yordan Kinkov
Browse files

Merge branch '34-static-data-during-evaluation-tests' into 'main'

Add tests for evaluation with static json data

Closes #34

See merge request !39
parents 990fc782 c3595045
No related branches found
No related tags found
1 merge request!39Add tests for evaluation with static json data
Pipeline #53361 passed with stages
in 1 minute and 47 seconds
......@@ -29,6 +29,9 @@ func TestService_Evaluate(t *testing.T) {
// value of a blank variable assignment
testPolicyBlankAssignment := `package testgroup.example _ = {"hello":"world"}`
// prepare test policy using static json data during evaluation
testPolicyWithStaticData := `package testgroup.example default allow = false allow { data.msg == "hello world" }`
// prepare test query that can be retrieved from rego queryCache
testQuery, err := rego.New(
rego.Module("example.rego", testPolicy),
......@@ -214,6 +217,36 @@ func TestService_Evaluate(t *testing.T) {
Result: map[string]interface{}{"hello": "world"},
},
},
{
name: "policy using static json data is evaluated successfully",
req: testReq(),
regocache: &policyfakes.FakeRegoCache{
GetStub: func(key string) (*rego.PreparedEvalQuery, bool) {
return nil, false
},
},
storage: &policyfakes.FakeStorage{
PolicyStub: func(ctx context.Context, s string, s2 string, s3 string) (*storage.Policy, error) {
return &storage.Policy{
Name: "example",
Group: "testgroup",
Version: "1.0",
Rego: testPolicyWithStaticData,
Data: `{"msg": "hello world"}`,
Locked: false,
LastUpdate: time.Now(),
}, nil
},
},
cache: &policyfakes.FakeCache{
SetStub: func(ctx context.Context, s string, s2 string, s3 string, bytes []byte) error {
return nil
},
},
res: &goapolicy.EvaluateResult{
Result: map[string]interface{}{"allow": true},
},
},
}
for _, test := range tests {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment