Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize tests #13

Open
serboctor opened this issue May 3, 2023 · 2 comments
Open

Standardize tests #13

serboctor opened this issue May 3, 2023 · 2 comments
Assignees

Comments

@serboctor
Copy link
Contributor

serboctor commented May 3, 2023

We currently have a mix of old yaml tests that are executed by a go script and rego tests that are executed by opa. We want to remove all the yaml tests and add rego tests for all policies. The test should be called policy_test.rego under tests dir and should contain all test scenarios unless the test scenarios are too many, in this case, it's ok to split them over several files and have multiple files.

Some policies have both types of tests, we want to delete the yaml one if there's an equivalent rego one.

Here you can find a list of policies that need to be refactored.

@serboctor
Copy link
Contributor Author

Changes can be found on this branch.

@serboctor
Copy link
Contributor Author

serboctor commented May 29, 2023

test template

package <packagename>

import data.<packagename>.violation

test_policy_compliance {
  testcase = {
   "parameters":{
      "exclude_namespaces":[

      ],
      "exclude_label_key":"",
      "exclude_label_value":""
   },
   "review":{
      "object":{}
   }
}
  count(violation) == 0 with input as testcase
}

test_policy_violation {
  testcase = {
   "parameters":{
      "exclude_namespaces":[

      ],
      "exclude_label_key":"",
      "exclude_label_value":""
   },
   "review":{
      "object":{}
   }
}
  count(violation) == 1 with input as testcase
}

test_exclude_namespace {
  testcase = {
   "parameters":{
      "exclude_namespaces":[
        "default"
      ],
      "exclude_label_key":"",
      "exclude_label_value":""
   },
   "review":{
      "object":{}
   }

}
  count(violation) == 0 with input as testcase
}

test_exclude_label {
  testcase = {
   "parameters":{
      "exclude_namespaces":[
      ],
      "exclude_label_key": "allow-violation",
      "exclude_label_value": "true",
   },
   "review":{
      "object":{}
   }
}
  count(violation) == 0 with input as testcase
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants