CtrlK
BlogDocsLog inGet started
Tessl Logo

nicholasjackson/golang-opa-rego-language

Rego is the declarative policy language used by Open Policy Agent (OPA) for writing and enforcing policies across cloud-native stacks, featuring data-driven rules, comprehensions, and 200+ built-in functions for infrastructure, security, and compliance automation.

Overall
score

97%

Overview
Eval results
Files

task.mdevals/scenario-1/

Task: Basic Policy with Test-Driven Development

Create a simple content moderation policy using Rego, following a strict test-driven development workflow.

Requirements

Step 1: Write tests first

Create policy_test.rego before implementing the policy. The test package must be package policy_test.

Include the following tests:

  • test_allow_approved_content — input with category set to "news" should be allowed
  • test_deny_flagged_content — input with category set to "spam" should be denied
  • test_deny_missing_category — input with no category field should be denied

Use the with input as { ... } keyword to provide mock input in each test.

Step 2: Implement the policy

Create policy.rego with package policy and import rego.v1.

The policy must:

  • Default to deny (i.e., default allow := false)
  • Define an allow rule that permits content when input.category is one of: "news", "sports", "technology"
  • Use a set literal or set comprehension to express the approved categories

Step 3: Run the tests

Run opa test . -v and confirm all tests pass.

Install with Tessl CLI

npx tessl i nicholasjackson/golang-opa-rego-language@1.15.0

README.md

tile.json