This folder contains automated tests for this Module. All of the tests are written in Go.
There are three tiers of tests for helm:
Template tests: These are tests designed to test the logic of the templates. These tests should run helm template
with various input values and parse the yaml to validate any logic embedded in the templates (e.g by reading them in
using client-go). Since templates are not statically typed, the goal of these tests is to promote fast cycle time
while catching some of the common bugs from typos or logic errors before getting to the slower integration tests.
Integration tests: These are tests that are designed to deploy the infrastructure and validate that it actually
works as expected. If you consider the template tests to be syntactic tests, these are semantic tests that validate
the behavior of the deployed resources.
Production tests (helm tests): These are tests that are run with the helm chart after it is deployed to validate the
chart installed and deployed correctly. These should be smoke tests with minimal validation to ensure that the common
operator errors during deployment are captured as early as possible. Note that because these tests run even on a
production system, they should be passive and not destructive.
This folder contains the "template tests" and "integration tests". Both types of tests use a helper library called
Terratest. While "template tests" do not need any infrastructure, the
"integration tests" deploy the charts to a Kubernetes cluster.
WARNING WARNING WARNING
Note #1: Many of these tests create real resources in a Kubernetes cluster and then try to clean those resources up at
the end of a test run. That means these tests may potentially pollute your Kubernetes cluster with unnecessary
resources! When adding tests, please be considerate of the resources you create and take extra care to clean everything
up when you're done!
Note #2: Never forcefully shut the tests down (e.g. by hitting CTRL + C) or the cleanup tasks won't run!
Note #3: We set -timeout 60m on all tests not because they necessarily take that long, but because Go has a
default test timeout of 10 minutes, after which it forcefully kills the tests with a SIGQUIT, preventing the cleanup
tasks from running. Therefore, we set an overlying long timeout to make sure all tests have enough time to finish and
clean up.
We use build tags to categorize the tests. The tags are:
all: Run all the tests
tpl: Run the template tests
integration: Run the integration tests
You can run all the tests by passing the all build tag:
cd test
go test -v -tagsall -timeout 60m
Run a specific test
To run a specific test called TestFoo:
cdtest
go test -v -timeout 60m -tags all -run TestFoo
Run just the template tests
Since the integration tests require infrastructure, they can be considerably slower than the unit tests. As such, to
promote fast test cycles, you may want to test just the template tests. To do so, you can pass the tpl build tag:
cdtest
go test -v -tags tpl
Questions? Ask away.
We're here to talk about our services, answer any questions, give advice, or just to chat.
{"treedata":{"name":"root","toggled":true,"children":[{"name":".circleci","children":[{"name":"config.yml","path":".circleci/config.yml","sha":"a0f85dbf4f51145592e9e242064611a2eb4694c2"}]},{"name":".gitignore","path":".gitignore","sha":"aa63ddea7b3def45c223772ac5f5a0b7c00c2c0c"},{"name":".pre-commit-config.yaml","path":".pre-commit-config.yaml","sha":"51b31c7d36c1be61adaa498f28edba3f5957ae80"},{"name":"CODEOWNERS","path":"CODEOWNERS","sha":"89db2c0afb6268a0fa92d8e841018cef4bc653cb"},{"name":"CONTRIBUTING.md","path":"CONTRIBUTING.md","sha":"89dc64290dc533f94420014acaf166a167b1d6a2"},{"name":"GRUNTWORK_PHILOSOPHY.md","path":"GRUNTWORK_PHILOSOPHY.md","sha":"205b95f262d882b7385b67e2b997b9faf1bf3c37"},{"name":"LICENSE","path":"LICENSE","sha":"276620ad6ffbc9954fd6633d167b0501155441d4"},{"name":"NOTICE","path":"NOTICE","sha":"01df697d1747e433ef21621ddcf3c574290a0de3"},{"name":"README.adoc","path":"README.adoc","sha":"f5229103914933786ab64b823e773ad3634f6bc4"},{"name":"_docs","children":[{"name":"k8s-service-architecture.png","path":"_docs/k8s-service-architecture.png","sha":"08712e67b1fc16d05877b23f1badad470c325db5"},{"name":"kubernetes-service.png","path":"_docs/kubernetes-service.png","sha":"609cc2795de0c1926bfe1875c8818659ffa770fc"}]},{"name":"charts","children":[{"name":"k8s-service","children":[{"name":".helmignore","path":"charts/k8s-service/.helmignore","sha":"f0c13194444163d1cba5c67d9e79231a62bc8f44"},{"name":"Chart.yaml","path":"charts/k8s-service/Chart.yaml","sha":"b7df355e4db5b10d7c2b532a3c1b4c25d681f0f0"},{"name":"README.md","path":"charts/k8s-service/README.md","sha":"e2e39e041ed4807786835e0635c68ec7e2db8846"},{"name":"linter_values.yaml","path":"charts/k8s-service/linter_values.yaml","sha":"f800b2d7b11aed8585d1fc607b44749df72cf209"},{"name":"templates","children":[{"name":"NOTES.txt","path":"charts/k8s-service/templates/NOTES.txt","sha":"dc7a36461c8eb2542f8d5aed472edda0b99d941c"},{"name":"_helpers.tpl","path":"charts/k8s-service/templates/_helpers.tpl","sha":"9d8f094e9937c75c6786a74e84e26b517259df54"},{"name":"canarydeployment.yaml","path":"charts/k8s-service/templates/canarydeployment.yaml","sha":"287f38512fa67e1475824a2e43e318538f8656bb"},{"name":"deployment.yaml","path":"charts/k8s-service/templates/deployment.yaml","sha":"5a5aec6d65f6f2986ef50fc5bcf0361fed2e0351"},{"name":"gmc.yaml","path":"charts/k8s-service/templates/gmc.yaml","sha":"1553d50f9c2ead4ffefebb7bdfd48f0ad3863146"},{"name":"horizontalpodautoscaler.yaml","path":"charts/k8s-service/templates/horizontalpodautoscaler.yaml","sha":"5b24660e86603a0a05f53bc66fd1e55bdf63e38a"},{"name":"ingress.yaml","path":"charts/k8s-service/templates/ingress.yaml","sha":"aa7d30f20edd838fa59209dd3e26b58b77ed6ec8"},{"name":"pdb.yaml","path":"charts/k8s-service/templates/pdb.yaml","sha":"7e8ce566adb00278e068d04aa9d185764de9aaf3"},{"name":"service.yaml","path":"charts/k8s-service/templates/service.yaml","sha":"45eb73e86193e62361e76529dec3ffd4a4c9214b"},{"name":"serviceaccount.yaml","path":"charts/k8s-service/templates/serviceaccount.yaml","sha":"e45827d044c92d0b9a0734952b41188b90f8b7fe"},{"name":"servicemonitor.yaml","path":"charts/k8s-service/templates/servicemonitor.yaml","sha":"380a0a6b73e96f8d949268267364cea2ccec8b68"}]},{"name":"values.yaml","path":"charts/k8s-service/values.yaml","sha":"6bfdba4102f936ec0c2a8438dd72062164225c1f"}]}]},{"name":"core-concepts.md","path":"core-concepts.md","sha":"a4c097870cba4887e45bd16e9ca463cf687ef562"},{"name":"examples","children":[{"name":"README.md","path":"examples/README.md","sha":"c6e785756d22d0762a9a23b241bdec54e29cb461"},{"name":"k8s-service-config-injection","children":[{"name":"README.md","path":"examples/k8s-service-config-injection/README.md","sha":"a24e3149a05cff06c879a764d6797ba22818a6d9"},{"name":"docker","children":[{"name":"Dockerfile","path":"examples/k8s-service-config-injection/docker/Dockerfile","sha":"329a2a784505504577de52d9b8d49b2d8efacaa3"},{"name":"app.rb","path":"examples/k8s-service-config-injection/docker/app.rb","sha":"14d99ac134c1774e7f10c933fbeb5db159b0bc1d"}]},{"name":"extensions","children":[{"name":"config_map_values.yaml","path":"examples/k8s-service-config-injection/extensions/config_map_values.yaml","sha":"33f21198dc33e4291a714e9bbaf2a1aa4879b897"},{"name":"secret_values.yaml","path":"examples/k8s-service-config-injection/extensions/secret_values.yaml","sha":"b0c149bad555489a8b916bef0ca5990ccef493e8"}]},{"name":"kubernetes","children":[{"name":"config-map.yaml","path":"examples/k8s-service-config-injection/kubernetes/config-map.yaml","sha":"371128a6b94f06c31176d4943ae2739f29f83e0a"}]},{"name":"values.yaml","path":"examples/k8s-service-config-injection/values.yaml","sha":"ce11682902d91b2c7ed04443768440439ad8fc1f"}]},{"name":"k8s-service-nginx","children":[{"name":"README.md","path":"examples/k8s-service-nginx/README.md","sha":"9d48bcf8dd2d34443bf99f78f2cdf584eab37f9c"},{"name":"values.yaml","path":"examples/k8s-service-nginx/values.yaml","sha":"d10277564784070a54e33ca2b41cc24d36e181d1"}]}]},{"name":"test","children":[{"name":"README.md","path":"test/README.md","sha":"0c440abc72116795eb23151244469df68ae8ebcb","toggled":true},{"name":"fixtures","children":[{"name":"canary_and_main_deployment_values.yaml","path":"test/fixtures/canary_and_main_deployment_values.yaml","sha":"8c1c625f696ce24e6cb803c16b2a6dce1016d163"},{"name":"canary_deployment_values.yaml","path":"test/fixtures/canary_deployment_values.yaml","sha":"4b1cc942457eb880470782b3b953e65622d4c67a"},{"name":"service_monitor_values.yaml","path":"test/fixtures/service_monitor_values.yaml","sha":"821486dc5a9c1c995bc6127e846526a1c7232cde"}]},{"name":"go.mod","path":"test/go.mod","sha":"acfe6e037ea3f5b4a57b215d224be0f49a1206e2"},{"name":"go.sum","path":"test/go.sum","sha":"e011aba4ada3c431d3a1829fd5cd143e57c3660e"},{"name":"k8s_service_canary_deployment_template_test.go","path":"test/k8s_service_canary_deployment_template_test.go","sha":"2df73a28baa3e6383526724d35a5d1ee0052571e"},{"name":"k8s_service_canary_deployment_test.go","path":"test/k8s_service_canary_deployment_test.go","sha":"883fdc3f6887607641efb18aa07ad9d680497e69"},{"name":"k8s_service_config_injection_example_test.go","path":"test/k8s_service_config_injection_example_test.go","sha":"fbc2defc7d4623035cfce134b8213b49487a02a0"},{"name":"k8s_service_config_injection_template_test.go","path":"test/k8s_service_config_injection_template_test.go","sha":"1c956087ba5b5e3546be9dc8c2fd42f81e6cb857"},{"name":"k8s_service_example_test_helpers.go","path":"test/k8s_service_example_test_helpers.go","sha":"3d7ef7d97328772619a1dc655e6bcfbb6de8a3d6"},{"name":"k8s_service_horizontal_pod_autoscaler_template_test.go","path":"test/k8s_service_horizontal_pod_autoscaler_template_test.go","sha":"f17c9ec0f2a6340edd10fa0eb70a078ad6e18597"},{"name":"k8s_service_nginx_example_test.go","path":"test/k8s_service_nginx_example_test.go","sha":"b77d7dd26c07801928108a52be61b186691c56f4"},{"name":"k8s_service_service_account_template_test.go","path":"test/k8s_service_service_account_template_test.go","sha":"8f04b134832358cb5f84e557ac9fb5b87202c3ba"},{"name":"k8s_service_service_monitor_template_test.go","path":"test/k8s_service_service_monitor_template_test.go","sha":"6ce25d576369224737ef4f563fdebfc8a946e0f1"},{"name":"k8s_service_template_render_helpers_for_test.go","path":"test/k8s_service_template_render_helpers_for_test.go","sha":"0036587e3ea9dacbe7e3254935b83a9387a93b65"},{"name":"k8s_service_template_test.go","path":"test/k8s_service_template_test.go","sha":"51378bb6fd830db4b9ec44b398b01caa0bb5b892"},{"name":"sample_app_test_helpers.go","path":"test/sample_app_test_helpers.go","sha":"5e2e44b4c0dcf5f836e7f81249aada38847792ac"}],"toggled":true}]},"detailsContent":"<h1 class=\"preview__body--title\" id=\"tests\">Tests</h1><div class=\"preview__body--border\"></div><p>This folder contains automated tests for this Module. All of the tests are written in <a href=\"https://golang.org/\" class=\"preview__body--description--blue\" target=\"_blank\">Go</a>.</p>\n<p>There are three tiers of tests for helm:</p>\n<ul>\n<li>Template tests: These are tests designed to test the logic of the templates. These tests should run <code>helm template</code>\nwith various input values and parse the yaml to validate any logic embedded in the templates (e.g by reading them in\nusing client-go). Since templates are not statically typed, the goal of these tests is to promote fast cycle time\nwhile catching some of the common bugs from typos or logic errors before getting to the slower integration tests.</li>\n<li>Integration tests: These are tests that are designed to deploy the infrastructure and validate that it actually\nworks as expected. If you consider the template tests to be syntactic tests, these are semantic tests that validate\nthe behavior of the deployed resources.</li>\n<li>Production tests (helm tests): These are tests that are run with the helm chart after it is deployed to validate the\nchart installed and deployed correctly. These should be smoke tests with minimal validation to ensure that the common\noperator errors during deployment are captured as early as possible. Note that because these tests run even on a\nproduction system, they should be passive and not destructive.</li>\n</ul>\n<p>This folder contains the "template tests" and "integration tests". Both types of tests use a helper library called\n<a href=\"/repos/terratest\" class=\"preview__body--description--blue\">Terratest</a>. While "template tests" do not need any infrastructure, the\n"integration tests" deploy the charts to a Kubernetes cluster.</p>\n<h2 class=\"preview__body--subtitle\" id=\"warning-warning-warning\">WARNING WARNING WARNING</h2>\n<p><strong>Note #1</strong>: Many of these tests create real resources in a Kubernetes cluster and then try to clean those resources up at\nthe end of a test run. That means these tests may potentially pollute your Kubernetes cluster with unnecessary\nresources! When adding tests, please be considerate of the resources you create and take extra care to clean everything\nup when you're done!</p>\n<p><strong>Note #2</strong>: Never forcefully shut the tests down (e.g. by hitting <code>CTRL + C</code>) or the cleanup tasks won't run!</p>\n<p><strong>Note #3</strong>: We set <code>-timeout 60m</code> on all tests not because they necessarily take that long, but because Go has a\ndefault test timeout of 10 minutes, after which it forcefully kills the tests with a <code>SIGQUIT</code>, preventing the cleanup\ntasks from running. Therefore, we set an overlying long timeout to make sure all tests have enough time to finish and\nclean up.</p>\n<h2 class=\"preview__body--subtitle\" id=\"running-the-tests\">Running the tests</h2>\n<h3 class=\"preview__body--subtitle\" id=\"prerequisites\">Prerequisites</h3>\n<ul>\n<li>Install the latest version of <a href=\"https://golang.org/\" class=\"preview__body--description--blue\" target=\"_blank\">Go</a>.</li>\n<li>Install <a href=\"https://github.com/golang/dep\" class=\"preview__body--description--blue\" target=\"_blank\">dep</a> for Go dependency management.</li>\n<li>Setup a Kubernetes cluster. We recommend using a local version for fast iteration:\n<ul>\n<li>Linux: <a href=\"https://github.com/kubernetes/minikube\" class=\"preview__body--description--blue\" target=\"_blank\">minikube</a></li>\n<li>Mac OSX: <a href=\"https://docs.docker.com/docker-for-mac/kubernetes/\" class=\"preview__body--description--blue\" target=\"_blank\">Kubernetes on Docker For Mac</a></li>\n<li>Windows: <a href=\"https://docs.docker.com/docker-for-windows/kubernetes/\" class=\"preview__body--description--blue\" target=\"_blank\">Kubernetes on Docker For Windows</a></li>\n</ul>\n</li>\n<li>Install and setup <a href=\"https://docs.helm.sh/using_helm/#installing-helm\" class=\"preview__body--description--blue\" target=\"_blank\">helm</a></li>\n</ul>\n<h3 class=\"preview__body--subtitle\" id=\"one-time-setup\">One-time setup</h3>\n<p>Download Go dependencies using dep:</p>\n<pre><span class=\"hljs-built_in\">cd</span> <span class=\"hljs-built_in\">test</span>\ndep ensure\n</pre>\n<h3 class=\"preview__body--subtitle\" id=\"run-all-the-tests\">Run all the tests</h3>\n<p>We use build tags to categorize the tests. The tags are:</p>\n<ul>\n<li><code>all</code>: Run all the tests</li>\n<li><code>tpl</code>: Run the template tests</li>\n<li><code>integration</code>: Run the integration tests</li>\n</ul>\n<p>You can run all the tests by passing the <code>all</code> build tag:</p>\n<pre><span class=\"hljs-keyword\">cd</span> test\n<span class=\"hljs-keyword\">go</span> test -v -<span class=\"hljs-keyword\">tags</span> <span class=\"hljs-keyword\">all</span> -timeout <span class=\"hljs-number\">60</span><span class=\"hljs-keyword\">m</span>\n</pre>\n<h3 class=\"preview__body--subtitle\" id=\"run-a-specific-test\">Run a specific test</h3>\n<p>To run a specific test called <code>TestFoo</code>:</p>\n<pre><span class=\"hljs-keyword\">cd</span> <span class=\"hljs-keyword\">test</span>\ngo <span class=\"hljs-keyword\">test</span> -v -timeout 60m -tags all -<span class=\"hljs-keyword\">run</span> TestFoo\n</pre>\n<h3 class=\"preview__body--subtitle\" id=\"run-just-the-template-tests\">Run just the template tests</h3>\n<p>Since the integration tests require infrastructure, they can be considerably slower than the unit tests. As such, to\npromote fast test cycles, you may want to test just the template tests. To do so, you can pass the <code>tpl</code> build tag:</p>\n<pre><span class=\"hljs-built_in\">cd</span> <span class=\"hljs-built_in\">test</span>\ngo <span class=\"hljs-built_in\">test</span> -v -tags tpl\n</pre>\n","repoName":"helm-kubernetes-services","repoRef":"v0.1.0","serviceDescriptor":{"serviceName":"Kubernetes Service","serviceRepoName":"helm-kubernetes-services","serviceRepoOrg":"gruntwork-io","cloudProviders":["aws","gcp"],"description":"Deploy a Kubernetes service with zero-downtime, rolling deployment, RBAC, auto scaling, secrets management, and more.","imageUrl":"kubernetes.png","licenseType":"open-source","technologies":["Terraform","Bash","Helm"],"compliance":[],"tags":[""]},"serviceCategoryName":"Docker services","fileName":"README.md","filePath":"/test","title":"Repo Browser: Kubernetes Service","description":"Browse the repos in the Gruntwork Infrastructure as Code Library."}