Skip to content

Commit

Permalink
Merge pull request #83 from ClarkSource/cli_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AFriemann authored Nov 3, 2020
2 parents 646ac4d + 2b44b68 commit 7df236b
Show file tree
Hide file tree
Showing 47 changed files with 612 additions and 0 deletions.
369 changes: 369 additions & 0 deletions tests/cli.py

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions tests/examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# ISC License
#
# Copyright 2019 FL Fintech E GmbH
#
# Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

import os

from click.testing import CliRunner

from k8t.cli import root


def test_single_cluster():
runner = CliRunner()

result = runner.invoke(root, ['get', 'clusters', 'examples/single-cluster'])

assert result.exit_code == 0
assert result.output == ''

result = runner.invoke(root, ['get', 'environments', 'examples/single-cluster'])

assert result.exit_code == 0
assert 'production' in result.output

result = runner.invoke(root, ['validate', 'examples/single-cluster'])

assert result.exit_code == 0
assert 'hello-world-deployment.yaml.j2: ✔' in result.output
assert 'hello-world-secret.yaml.j2: ✔' in result.output
assert 'hello-world-service.yaml.j2: ✔' in result.output
Empty file added tests/resources/bad/.k8t
Empty file.
Empty file added tests/resources/bad/config.yaml
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
foo: 1
bar: 2
buz: 3
---
foo: 1
bar: {
buz: 3
---
foo: {
bar: 2
buz: 3
10 changes: 10 additions & 0 deletions tests/resources/bad/templates/composite-template.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
one: 1
two: 2
three: {{ 2 + 1 }}
four: {{ four }}
---
one: 1
two: 2
three: {{ 2 + 1 }}
four: {{ four }}
4 changes: 4 additions & 0 deletions tests/resources/bad/templates/filter-template.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
one: 1
{# two: {{ 2 | not_existing_filter }} #}
three: {{ three | default(3) }}
four: {{ test.four | default(4) }}
3 changes: 3 additions & 0 deletions tests/resources/bad/templates/invalid-yaml-template.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
foo: 1
bar: {
buz: 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
one: 1
two: {{ test.one + 1 }}
three: 3
four: {{2 + 2}}
4 changes: 4 additions & 0 deletions tests/resources/bad/templates/nested-value-template.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
one: 1
two: {{ test.two }}
three: 3
four: {{2 + 2}}
4 changes: 4 additions & 0 deletions tests/resources/bad/templates/secret-template.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
one: "{{ get_secret('/one', 24) | b64encode }}"
two: 2
three: {{ 2 + 1 }}
four: {{ four }}
4 changes: 4 additions & 0 deletions tests/resources/bad/templates/several-template.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
one: {{ one }}
two: {{ two }}
three: {{three }}
four: {{ four }}
4 changes: 4 additions & 0 deletions tests/resources/bad/templates/value-template.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
one: 1
two: 2
three: {{ 2 + 1 }}
four: {{ four }}
2 changes: 2 additions & 0 deletions tests/resources/bad/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
foo: bar
Empty file added tests/resources/good/.k8t
Empty file.
4 changes: 4 additions & 0 deletions tests/resources/good/clusters/cluster-1/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
secrets:
provider: ssm
region: 'eu-central-1'
prefix: '/cluster-1'
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
env: "{{env}}"
cluster: "{{cls}}"
foo: "{{foo}}"
bar: "{{bar}}"
buz: "{{buz | default('buz_default')}}"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
env: cluster-1-env
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
env: "{{env}}"
cluster: "{{cls}}"
foo: "{{foo}}"
bar: "{{bar}}"
buz: "{{buz | default('buz_default')}}"
overwritten-in-env: true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
env: cluster-1-common-env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
env: "{{env}}"
cluster: "{{cls}}"
foo: "{{foo}}"
bar: "{{bar}}"
buz: "{{buz | default('buz_default')}}"
secret: "{{get_secret('/test', 12) | b64encode}}"
1 change: 1 addition & 0 deletions tests/resources/good/clusters/cluster-1/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cls: cluster-1
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
template: 1
env: "{{env}}"
cluster: "{{cls}}"
---
template: 2
env: "{{env}}"
cluster: "{{cls}}"
2 changes: 2 additions & 0 deletions tests/resources/good/clusters/cluster-2/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cls: cluster-2
buz: 'buz'
2 changes: 2 additions & 0 deletions tests/resources/good/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
secrets:
provider: random
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
env: "{{env}}"
cluster: "{{cls}}"
foo: "{{foo}}"
bar: "{{bar}}"
buz: "{{buz | default('buz_default')}}"
1 change: 1 addition & 0 deletions tests/resources/good/environments/common-env/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
env: common-env
Empty file.
1 change: 1 addition & 0 deletions tests/resources/good/environments/some-env/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
env: some-env
5 changes: 5 additions & 0 deletions tests/resources/good/templates/common-template.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
env: "{{env}}"
cluster: "{{cls}}"
foo: "{{foo}}"
bar: "{{bar}}"
buz: "{{buz | default('buz_default')}}"
4 changes: 4 additions & 0 deletions tests/resources/good/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cls: none
env: none
foo: 1
bar: test
Empty file.
Empty file.
2 changes: 2 additions & 0 deletions tests/resources/missing_values/templates/template.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test: "{{test}}"
buz: "{{buz | default('buz_default')}}"
1 change: 1 addition & 0 deletions tests/resources/missing_values/value-file.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test: something
Empty file.
22 changes: 22 additions & 0 deletions tests/resources/results/cluster-1-cluster-specific-env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
# Source: cluster-1-env-template.yaml.j2
env: "cluster-1-env"
cluster: "cluster-1"
foo: "1"
bar: "test"
buz: "buz_default"
---
# Source: cluster-1-template.yaml.j2
env: "cluster-1-env"
cluster: "cluster-1"
foo: "1"
bar: "test"
buz: "buz_default"
secret: "c3RyaW5nX3ZhbHVl"
---
# Source: common-template.yaml.j2
env: "cluster-1-env"
cluster: "cluster-1"
foo: "1"
bar: "test"
buz: "buz_default"
22 changes: 22 additions & 0 deletions tests/resources/results/cluster-1-common-env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
# Source: cluster-1-template.yaml.j2
env: "cluster-1-common-env"
cluster: "cluster-1"
foo: "1"
bar: "test"
buz: "buz_default"
overwritten-in-env: true
---
# Source: common-env-template.yaml.j2
env: "cluster-1-common-env"
cluster: "cluster-1"
foo: "1"
bar: "test"
buz: "buz_default"
---
# Source: common-template.yaml.j2
env: "cluster-1-common-env"
cluster: "cluster-1"
foo: "1"
bar: "test"
buz: "buz_default"
15 changes: 15 additions & 0 deletions tests/resources/results/cluster-1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
# Source: cluster-1-template.yaml.j2
env: "none"
cluster: "cluster-1"
foo: "1"
bar: "test"
buz: "buz_default"
secret: "c3RyaW5nX3ZhbHVl"
---
# Source: common-template.yaml.j2
env: "none"
cluster: "cluster-1"
foo: "1"
bar: "test"
buz: "buz_default"
17 changes: 17 additions & 0 deletions tests/resources/results/cluster-2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
# Source: common-template.yaml.j2
env: "none"
cluster: "cluster-2"
foo: "1"
bar: "test"
buz: "buz"
---
# Source: composite-template.yaml.j2
---
template: 1
env: "none"
cluster: "cluster-2"
---
template: 2
env: "none"
cluster: "cluster-2"
14 changes: 14 additions & 0 deletions tests/resources/results/common-env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
# Source: common-env-template.yaml.j2
env: "common-env"
cluster: "none"
foo: "1"
bar: "test"
buz: "buz_default"
---
# Source: common-template.yaml.j2
env: "common-env"
cluster: "none"
foo: "1"
bar: "test"
buz: "buz_default"
7 changes: 7 additions & 0 deletions tests/resources/results/default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
# Source: common-template.yaml.j2
env: "none"
cluster: "none"
foo: "1"
bar: "test"
buz: "buz_default"
7 changes: 7 additions & 0 deletions tests/resources/results/some-env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
# Source: common-template.yaml.j2
env: "some-env"
cluster: "none"
foo: "1"
bar: "test"
buz: "buz_default"

0 comments on commit 7df236b

Please sign in to comment.