{"id":13676371,"url":"https://github.com/xchapter7x/hcunit","last_synced_at":"2026-01-26T21:26:54.391Z","repository":{"id":35446609,"uuid":"213598801","full_name":"xchapter7x/hcunit","owner":"xchapter7x","description":"Helm Chart Unit: helps to unit test rendering of your templates using policies","archived":false,"fork":false,"pushed_at":"2023-03-07T02:45:07.000Z","size":184,"stargazers_count":36,"open_issues_count":16,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-29T07:37:39.655Z","etag":null,"topics":["helm","helm-plugin","helm-plugins","opa","open-policy-agent","rego","unit-test","unit-testing","unittest","unittesting","unittests"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xchapter7x.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-10-08T09:15:59.000Z","updated_at":"2024-12-28T18:31:17.000Z","dependencies_parsed_at":"2024-01-14T14:31:14.320Z","dependency_job_id":"aaa6318f-5753-4518-a669-05c78ba2966c","html_url":"https://github.com/xchapter7x/hcunit","commit_stats":null,"previous_names":[],"tags_count":91,"template":false,"template_full_name":null,"purl":"pkg:github/xchapter7x/hcunit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xchapter7x%2Fhcunit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xchapter7x%2Fhcunit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xchapter7x%2Fhcunit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xchapter7x%2Fhcunit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xchapter7x","download_url":"https://codeload.github.com/xchapter7x/hcunit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xchapter7x%2Fhcunit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28788370,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T21:13:08.818Z","status":"ssl_error","status_checked_at":"2026-01-26T21:13:08.448Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["helm","helm-plugin","helm-plugins","opa","open-policy-agent","rego","unit-test","unit-testing","unittest","unittesting","unittests"],"created_at":"2024-08-02T13:00:24.094Z","updated_at":"2026-01-26T21:26:54.373Z","avatar_url":"https://github.com/xchapter7x.png","language":"Go","readme":"# hcunit\n[![CircleCI](https://circleci.com/gh/xchapter7x/hcunit.svg?style=svg)](https://circleci.com/gh/xchapter7x/hcunit)\n\n\nHelm Chart Unit: helps to unit test rendering of your templates using policies\n\n## Usage as a Helm Plugin:\n\n```bash\n$\u003e echo \"install the latest version of the plugin\"\n$\u003e helm plugin install https://github.com/xchapter7x/hcunit/releases/latest/download/hcunit_plugin.tgz\nInstalled plugin: unit\n\n$\u003e echo \"you might have have to make the plugin binaries executable\"\n$\u003e helm env | grep \"HELM_PLUGIN\" | awk -F\"=\" '{print $2}' | awk -F\\\" '{print \"chmod +x \"$2\"/hcunit_plugin/hcunit*\"}' |sh\n\n$\u003e echo \"lets run some tests of our templates' logic\"\n$\u003e helm unit -t templates -c policy/values_toggle_on.yaml -p policy/testing_toggle_on.rego\nPASS: data.main.expect[\"another passing case 123\"]\nPASS: data.main.expect[\"force passing\"]\nPASS: data.main.expect[\"another passing case\"]\nPASS: data.main.expect[\"force passing abc\"]\n[SUCCESS] Your Helm Chart complies with all policies!\n\n$\u003e echo \"lets explore the available flags for the plugin call\"\n$\u003e helm unit --help\nUsage:\n  hcunit_osx [OPTIONS] eval [eval-OPTIONS]\n\ngiven a OPA/Rego Policy one can evaluate if the rendered templates of a chart using a given values file meet the defined rules of the policy or not\n\nHelp Options:\n  -h, --help           Show this help message\n\n[eval command options]\n      -t, --template=  path to yaml template you would like to render\n      -c, --values=    path to values file you would like to use for rendering\n      -p, --policy=    path to rego policies to evaluate against rendered templates\n      -n, --namespace= policy namespace to query for rules\n      -v, --verbose    prints tracing output to stdout\n      \n```\n\n\n\n## Usage as a Standalone CLI... Download Binaries\nhttps://github.com/xchapter7x/hcunit/releases/latest\n\n\n\n## Notes on Syntax and Rego\n\nRego is a Policy Language for the Open Policy Agent eco system. We use rego here as our testing DSL. Any rego rule which is an `assert` or `expect` will get executed and must evaluated to true. The gist is that everything between the `{}` is a `rule`. Everything between `{}` should evaluate to `true`. Assignments yield true, and if any statement in the `{}` block is `false` then the entire rule will return `false` and therfore fail our test case.\n\nFor more information you can try: https://www.openpolicyagent.org/docs/latest/#rego\n\nOr \n\nfor a Online playground: https://play.openpolicyagent.org/\n\n\n\n\n\n## Options\n```bash\n-\u003e % hcunit --help\nUsage:\n  hcunit [OPTIONS] \u003ceval | render | version\u003e\n\nHelp Options:\n  -h, --help  Show this help message\n\nAvailable commands:\n  eval     evaluate a policy on a chart + values\n  render   Render a template yaml\n  version  display version info\n```\n\n\n\n## Sample usage\n```bash\n000@000-000 [00:00:00] [helm-charts/concourse] [master *]\n-\u003e % cat policy/testing.rego\n───────┬───────────────────────────────────────────────────────────────\n       │ File: policy/testing.rego\n───────┼───────────────────────────────────────────────────────────────\n   1   │ package main\n   2   │\n   3   │ assert [\"this should always be true b/c its true\"] {\n   4   │   true\n   5   │ }\n   6   │\n   7   │ assert [\"when web is enabled then namespace is toggled on\"] {\n   8   |     \"true\" == input[\"values\"].web.enabled\n   9   │     \"Namespace\" == input[\"namespace.yaml\"].kind\n   10  │ }\n───────┴───────────────────────────────────────────────────────────────\n\n000@000-000 [00:00:00] [helm-charts/concourse] [master *]\n-\u003e % hcunit eval -t templates/ -c values.yaml -p policy/testing.rego\nPASS: data.main.assert[\"this should always be true b/c its true\"]\nPASS: data.main.assert[\"when web is enabled then namespace is toggled on\"]\n[SUCCESS] Your Helm Chart complies with all policies!\n\n000@000-000 [00:00:00] [helm-charts/concourse] [master *]\n-\u003e % cat policy/testing_fail.rego\n───────┬───────────────────────────────────────────────────────────────\n       │ File: policy/testing_fail.rego\n───────┼───────────────────────────────────────────────────────────────\n   1   │ package main\n   2   │\n   3   │ assert [\"this should always be true b/c its true\"] {\n   4   │   false\n   5   │ }\n   6   │\n   7   │ assert [\"when web is enabled then namespace is toggled on\"] {\n   8   |     \"true\" == input[\"values\"].web.enabled\n   9   │     \"NamespaceWrongKind\" == input[\"namespace.yaml\"].kind\n   10  │ }\n───────┴───────────────────────────────────────────────────────────────\n\n000@000-000 [00:00:00] [helm-charts/concourse] [master *]\n-\u003e % hcunit eval -t templates/ -c values.yaml -p policy/testing_fail.rego\nFAIL: data.main.assert[\"this should always be true b/c its true\"]\nFAIL: data.main.assert[\"when web is enabled then namespace is toggled on\"]\n[FAILURE] Policy violations found on the Helm Chart!\n```\n\n\n## About hcunit\n- Uses [OPA and Rego](https://www.openpolicyagent.org/) to evaluate the yaml to see if it meets your expectations\n- By convention hcunit will run any rules in your given rego file or recursively in a given directory as long as that rule takes the form `assert [\"some behavior\"] { ... } ` or `expect [\"some other behavior\"] { ... } `.\n- using variables or duplicate values in the hash for your tests is prohibited by hcunit. Reason being duplicate hashes opens up the potential for inconsistent/confusing results. \n- Your policy rules will have access to a input object. This object will be a hashmap of your rendered templates, with the hash being the filename, and the value being an object representation of the rendered yaml. It will also contain a hash for the NOTES file, which will be a string. \n- uses helm's packages to render the templates so, it should yield identical output as the `helm template` command\n- supports multiple values.yml file inputs, does not yet support values set as flags in the cli call.\n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxchapter7x%2Fhcunit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxchapter7x%2Fhcunit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxchapter7x%2Fhcunit/lists"}