Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
policy
Manage
Activity
Members
Labels
Plan
Issues
4
Issue boards
Milestones
Wiki
Code
Merge requests
2
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gaia-X
Trust Services API
policy
Commits
c3595045
Commit
c3595045
authored
2 years ago
by
Yordan Kinkov
Browse files
Options
Downloads
Patches
Plain Diff
#34
add tests for evaluation with static data
parent
990fc782
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!39
Add tests for evaluation with static json data
Pipeline
#53334
passed with stages
in 1 minute and 30 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
internal/service/policy/service_test.go
+33
-0
33 additions, 0 deletions
internal/service/policy/service_test.go
with
33 additions
and
0 deletions
internal/service/policy/service_test.go
+
33
−
0
View file @
c3595045
...
...
@@ -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
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment