Created
February 2, 2018 15:00
-
-
Save claudiobastos/bd85f6192f100c6de90ac72c660647e7 to your computer and use it in GitHub Desktop.
lint tests for kubetest helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #// vim: set ft=python: | |
| #assert_equal | |
| #assert_contains | |
| #assert_not_contains | |
| #assert_not_equal | |
| #assert_nil | |
| #assert_not_nil | |
| #fail | |
| #fail_now | |
| #assert_empty | |
| #assert_not_empty | |
| #assert_true | |
| #assert_false | |
| def test_for_standard_labels(): | |
| if spec["kind"] == "Deployment": | |
| validateDeployment(spec) | |
| if spec["kind"] == "Service": | |
| validateService(spec) | |
| def validateDeployment(spec): | |
| name = spec["metadata"]["name"] | |
| assert_not_empty(name, "Deployment don't have a name") | |
| print("Validating deployment: ", name ) | |
| assert_contains(spec["spec"]["template"]["metadata"], "name", "Deployment Template MUST have a name for it's pods") | |
| labels = spec["spec"]["template"]["metadata"]["labels"] | |
| assert_contains(labels, "app", "should indicate which team owns the deployment") | |
| assert_contains(labels, "tier", "should indicate which tier ") | |
| isTierValid(labels["tier"]) | |
| #print(labels) | |
| assert_contains(labels, "env", "should indicate which environment it would work") | |
| isEnvValid(labels["env"]) | |
| pass | |
| def validateService(spec): | |
| name = spec["metadata"]["name"] | |
| assert_not_empty(name, "Service don't have a name") | |
| print("Validating service: ", name ) | |
| #print(spec) | |
| assert_equal( str(name)[0:3], "svc", "Name should start with 'svc' " ) | |
| seletores = spec["spec"]["selector"] | |
| assert_contains(seletores, "app", "should indicate which team owns the deployment") | |
| assert_not_contains(seletores, "namespace", "should not use this in that part") | |
| assert_contains(seletores, "tier", "should indicate which team owns the deployment") | |
| isTierValid(labels["tier"]) | |
| def isReleaseValid(value): | |
| valid = ["canary", "beta", "stable" ] | |
| assert_contains(valid, value, "Value is outside company standards") | |
| def isTierValid(value): | |
| valid = ["backend", "frontend", "database", "cache" ] | |
| assert_contains(valid, value, "Value is outside company standards") | |
| def isEnvValid(value): | |
| valid = ["production", "development", "staging", "qa", "tests"] | |
| assert_contains(valid, value, "Value is outside company standards") | |
| test_for_standard_labels() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment