Skip to content

Commit

Permalink
Add acceptance tests for multi-source input
Browse files Browse the repository at this point in the history
Signed-off-by: Luiz Carvalho <[email protected]>
  • Loading branch information
lcarva committed Aug 13, 2024
1 parent d65401a commit 44ca681
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 1 deletion.
18 changes: 18 additions & 0 deletions acceptance/examples/ham.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ham

import rego.v1

# METADATA
# title: Ham
# description: Ham ham ham
# custom:
# short_name: delicious
#
deny contains result if {
value := object.get(input, "ham", "yucky")
value != "delicious"
result := {
"msg": "ham is not delicious",
"code": "ham.delicious",
}
}
6 changes: 6 additions & 0 deletions acceptance/examples/multiple_sources_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
sources:
- policy:
- "git::https://${GITHOST}/git/ham-policy"
- policy:
- "git::https://${GITHOST}/git/spam-policy"
18 changes: 18 additions & 0 deletions acceptance/examples/spam.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package spam

import rego.v1

# METADATA
# title: Spam
# description: Spam spam spam
# custom:
# short_name: valid
#
deny contains result if {
value := object.get(input, "spam", false)
not value
result := {
"msg": "spam is not true",
"code": "spam.valid",
}
}
50 changes: 50 additions & 0 deletions features/__snapshots__/validate_input.snap
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,54 @@ Error: 1 error occurred:



---

[policy with multiple sources:stdout - 1]
{
"success": false,
"filepaths": [
{
"filepath": "input.yaml",
"violations": [
{
"msg": "ham is not delicious",
"metadata": {
"code": "ham.delicious"
}
},
{
"msg": "spam is not true",
"metadata": {
"code": "spam.valid"
}
}
],
"warnings": [],
"successes": null,
"success": false,
"success-count": 0
}
],
"policy": {
"sources": [
{
"policy": [
"git::https://${GITHOST}/git/ham-policy"
]
},
{
"policy": [
"git::https://${GITHOST}/git/spam-policy"
]
}
]
},
"ec-version": "${EC_VERSION}",
"effective-time": "${TIMESTAMP}"
}
---

[policy with multiple sources:stderr - 1]
Error: success criteria not met

---
19 changes: 18 additions & 1 deletion features/validate_input.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Feature: validate input
The ec command line should be able to inspect input files

Background:
Given stub git daemon running

Expand Down Expand Up @@ -49,3 +49,20 @@ Feature: validate input
When ec command is run with "validate input --file pipeline_definition.yaml --policy git::https://${GITHOST}/git/sad-day-config.git"
Then the exit status should be 1
Then the output should match the snapshot

Scenario: policy with multiple sources
Given a git repository named "multiple-sources-config" with
| policy.yaml | examples/multiple_sources_config.yaml |
Given a git repository named "spam-policy" with
| main.rego | examples/spam.rego |
Given a git repository named "ham-policy" with
| main.rego | examples/ham.rego |
Given a pipeline definition file named "input.yaml" containing
"""
---
spam: false
ham: rotten
"""
When ec command is run with "validate input --file input.yaml --policy git::https://${GITHOST}/git/multiple-sources-config.git"
Then the exit status should be 1
Then the output should match the snapshot

0 comments on commit 44ca681

Please sign in to comment.