From d7c4286cea77ba477b0cafd26a49c5e7e84d5fd0 Mon Sep 17 00:00:00 2001 From: Simon Westphahl Date: Wed, 29 Jan 2020 21:18:11 +0100 Subject: [PATCH] Add end-to-end smoke tests --- tests/e2e/.konverter-vault-test | 1 + tests/e2e/conftest.py | 30 +++++++++++++++++++ tests/e2e/expect_basic.yaml | 10 +++++++ tests/e2e/expect_contexts.yaml | 12 ++++++++ tests/e2e/expect_dir.yaml | 11 +++++++ tests/e2e/expect_dir_and_file.yaml | 11 +++++++ tests/e2e/expect_encrypted.yaml | 3 ++ tests/e2e/expect_multidoc.yaml | 11 +++++++ tests/e2e/expect_multifile.yaml | 11 +++++++ tests/e2e/templates/basic.yaml | 9 ++++++ tests/e2e/templates/contexts.yaml | 11 +++++++ tests/e2e/templates/dir/one.yaml | 6 ++++ tests/e2e/templates/dir/two.yaml | 3 ++ tests/e2e/templates/dir_and_file/dir/one.yaml | 6 ++++ tests/e2e/templates/dir_and_file/two.yaml | 3 ++ tests/e2e/templates/encrypted.yaml | 2 ++ tests/e2e/templates/multidoc.yaml | 10 +++++++ tests/e2e/templates/multifile/one.yaml | 3 ++ tests/e2e/templates/multifile/two.yaml | 6 ++++ tests/e2e/test_basic.yaml | 5 ++++ tests/e2e/test_contexts.yaml | 6 ++++ tests/e2e/test_dir.yaml | 5 ++++ tests/e2e/test_dir_and_file.yaml | 6 ++++ tests/e2e/test_encrypted.yaml | 9 ++++++ tests/e2e/test_multidoc.yaml | 5 ++++ tests/e2e/test_multifile.yaml | 6 ++++ tests/e2e/vars/_encrypted.yaml | 2 ++ tests/e2e/vars/_generic.yaml | 5 ++++ tests/e2e/vars/contexts.yaml | 5 ++++ 29 files changed, 213 insertions(+) create mode 100644 tests/e2e/.konverter-vault-test create mode 100644 tests/e2e/conftest.py create mode 100644 tests/e2e/expect_basic.yaml create mode 100644 tests/e2e/expect_contexts.yaml create mode 100644 tests/e2e/expect_dir.yaml create mode 100644 tests/e2e/expect_dir_and_file.yaml create mode 100644 tests/e2e/expect_encrypted.yaml create mode 100644 tests/e2e/expect_multidoc.yaml create mode 100644 tests/e2e/expect_multifile.yaml create mode 100644 tests/e2e/templates/basic.yaml create mode 100644 tests/e2e/templates/contexts.yaml create mode 100644 tests/e2e/templates/dir/one.yaml create mode 100644 tests/e2e/templates/dir/two.yaml create mode 100644 tests/e2e/templates/dir_and_file/dir/one.yaml create mode 100644 tests/e2e/templates/dir_and_file/two.yaml create mode 100644 tests/e2e/templates/encrypted.yaml create mode 100644 tests/e2e/templates/multidoc.yaml create mode 100644 tests/e2e/templates/multifile/one.yaml create mode 100644 tests/e2e/templates/multifile/two.yaml create mode 100644 tests/e2e/test_basic.yaml create mode 100644 tests/e2e/test_contexts.yaml create mode 100644 tests/e2e/test_dir.yaml create mode 100644 tests/e2e/test_dir_and_file.yaml create mode 100644 tests/e2e/test_encrypted.yaml create mode 100644 tests/e2e/test_multidoc.yaml create mode 100644 tests/e2e/test_multifile.yaml create mode 100644 tests/e2e/vars/_encrypted.yaml create mode 100644 tests/e2e/vars/_generic.yaml create mode 100644 tests/e2e/vars/contexts.yaml diff --git a/tests/e2e/.konverter-vault-test b/tests/e2e/.konverter-vault-test new file mode 100644 index 0000000..4a0d0a2 --- /dev/null +++ b/tests/e2e/.konverter-vault-test @@ -0,0 +1 @@ +wf74SQKHyZigGSevWnQKPxBtfCP8BdukG0yKPYi9vOs= \ No newline at end of file diff --git a/tests/e2e/conftest.py b/tests/e2e/conftest.py new file mode 100644 index 0000000..5380cd0 --- /dev/null +++ b/tests/e2e/conftest.py @@ -0,0 +1,30 @@ +import pytest + +from click.testing import CliRunner +from ruamel.yaml import YAML + +from konverter.__main__ import cli + + +def pytest_collect_file(parent, path): + if path.ext == ".yaml" and path.basename.startswith("test_"): + return E2ETest(path.basename, path, parent) + + +class E2ETest(pytest.Item): + def __init__(self, name, fspath, parent): + super().__init__(name, parent) + self.fspath = fspath + *_, identifier = str(fspath.basename).partition("_") + self.expect_path = f"{fspath.dirname}/expect_{identifier}" + + def runtest(self): + runner = CliRunner() + result = runner.invoke(cli, [str(self.fspath)]) + assert result.exit_code == 0, result.output + with open(self.expect_path) as expect_file: + assert result.output == expect_file.read() + + @property + def nodeid(self): + return f"e2e::{self.fspath.basename}" diff --git a/tests/e2e/expect_basic.yaml b/tests/e2e/expect_basic.yaml new file mode 100644 index 0000000..926d870 --- /dev/null +++ b/tests/e2e/expect_basic.yaml @@ -0,0 +1,10 @@ +--- +variable: Hello World! +VARIABLE: HELLO WORLD! +b64_variable: SGVsbG8gV29ybGQh +json_variable: '{"number": 42, "other": "FOOBAR"}' + +template: |- + Hello World! + + 42 diff --git a/tests/e2e/expect_contexts.yaml b/tests/e2e/expect_contexts.yaml new file mode 100644 index 0000000..1f36447 --- /dev/null +++ b/tests/e2e/expect_contexts.yaml @@ -0,0 +1,12 @@ +--- +variable: Hello World! +VARIABLE: HELLO WORLD! +b64_variable: SGVsbG8gV29ybGQh +json_variable: '{"number": 43, "other": "BARFOO"}' + +template: |- + Hello World! + + 43 + + Hello context! diff --git a/tests/e2e/expect_dir.yaml b/tests/e2e/expect_dir.yaml new file mode 100644 index 0000000..7942da5 --- /dev/null +++ b/tests/e2e/expect_dir.yaml @@ -0,0 +1,11 @@ +--- +json_variable: '{"number": 42, "other": "FOOBAR"}' + +template: |- + Hello World! + + 42 +--- +variable: Hello World! +VARIABLE: HELLO WORLD! +b64_variable: SGVsbG8gV29ybGQh diff --git a/tests/e2e/expect_dir_and_file.yaml b/tests/e2e/expect_dir_and_file.yaml new file mode 100644 index 0000000..7942da5 --- /dev/null +++ b/tests/e2e/expect_dir_and_file.yaml @@ -0,0 +1,11 @@ +--- +json_variable: '{"number": 42, "other": "FOOBAR"}' + +template: |- + Hello World! + + 42 +--- +variable: Hello World! +VARIABLE: HELLO WORLD! +b64_variable: SGVsbG8gV29ybGQh diff --git a/tests/e2e/expect_encrypted.yaml b/tests/e2e/expect_encrypted.yaml new file mode 100644 index 0000000..77a5d70 --- /dev/null +++ b/tests/e2e/expect_encrypted.yaml @@ -0,0 +1,3 @@ +--- +encrypted_value: Hello Secret! +unencrypted_value: Hello unencryted secret! diff --git a/tests/e2e/expect_multidoc.yaml b/tests/e2e/expect_multidoc.yaml new file mode 100644 index 0000000..3c00f73 --- /dev/null +++ b/tests/e2e/expect_multidoc.yaml @@ -0,0 +1,11 @@ +--- +variable: Hello World! +VARIABLE: HELLO WORLD! +b64_variable: SGVsbG8gV29ybGQh +--- +json_variable: '{"number": 42, "other": "FOOBAR"}' + +template: |- + Hello World! + + 42 diff --git a/tests/e2e/expect_multifile.yaml b/tests/e2e/expect_multifile.yaml new file mode 100644 index 0000000..3c00f73 --- /dev/null +++ b/tests/e2e/expect_multifile.yaml @@ -0,0 +1,11 @@ +--- +variable: Hello World! +VARIABLE: HELLO WORLD! +b64_variable: SGVsbG8gV29ybGQh +--- +json_variable: '{"number": 42, "other": "FOOBAR"}' + +template: |- + Hello World! + + 42 diff --git a/tests/e2e/templates/basic.yaml b/tests/e2e/templates/basic.yaml new file mode 100644 index 0000000..6d67ad4 --- /dev/null +++ b/tests/e2e/templates/basic.yaml @@ -0,0 +1,9 @@ +variable: !k/expr foobar +VARIABLE: !k/expr foobar|upper +b64_variable: !k/expr foobar|b64encode +json_variable: !k/expr object|to_json + +template: !k/template |- + {{ foobar }} + + {{ object.number }} diff --git a/tests/e2e/templates/contexts.yaml b/tests/e2e/templates/contexts.yaml new file mode 100644 index 0000000..7d23ebc --- /dev/null +++ b/tests/e2e/templates/contexts.yaml @@ -0,0 +1,11 @@ +variable: !k/expr foobar +VARIABLE: !k/expr foobar|upper +b64_variable: !k/expr foobar|b64encode +json_variable: !k/expr object|to_json + +template: !k/template |- + {{ foobar }} + + {{ object.number }} + + {{ barfoo }} diff --git a/tests/e2e/templates/dir/one.yaml b/tests/e2e/templates/dir/one.yaml new file mode 100644 index 0000000..4240e7b --- /dev/null +++ b/tests/e2e/templates/dir/one.yaml @@ -0,0 +1,6 @@ +json_variable: !k/expr object|to_json + +template: !k/template |- + {{ foobar }} + + {{ object.number }} diff --git a/tests/e2e/templates/dir/two.yaml b/tests/e2e/templates/dir/two.yaml new file mode 100644 index 0000000..9a82001 --- /dev/null +++ b/tests/e2e/templates/dir/two.yaml @@ -0,0 +1,3 @@ +variable: !k/expr foobar +VARIABLE: !k/expr foobar|upper +b64_variable: !k/expr foobar|b64encode diff --git a/tests/e2e/templates/dir_and_file/dir/one.yaml b/tests/e2e/templates/dir_and_file/dir/one.yaml new file mode 100644 index 0000000..4240e7b --- /dev/null +++ b/tests/e2e/templates/dir_and_file/dir/one.yaml @@ -0,0 +1,6 @@ +json_variable: !k/expr object|to_json + +template: !k/template |- + {{ foobar }} + + {{ object.number }} diff --git a/tests/e2e/templates/dir_and_file/two.yaml b/tests/e2e/templates/dir_and_file/two.yaml new file mode 100644 index 0000000..9a82001 --- /dev/null +++ b/tests/e2e/templates/dir_and_file/two.yaml @@ -0,0 +1,3 @@ +variable: !k/expr foobar +VARIABLE: !k/expr foobar|upper +b64_variable: !k/expr foobar|b64encode diff --git a/tests/e2e/templates/encrypted.yaml b/tests/e2e/templates/encrypted.yaml new file mode 100644 index 0000000..bd05d8e --- /dev/null +++ b/tests/e2e/templates/encrypted.yaml @@ -0,0 +1,2 @@ +encrypted_value: !k/expr encrypted_foobar +unencrypted_value: !k/expr unencrypted_barfoo diff --git a/tests/e2e/templates/multidoc.yaml b/tests/e2e/templates/multidoc.yaml new file mode 100644 index 0000000..be66802 --- /dev/null +++ b/tests/e2e/templates/multidoc.yaml @@ -0,0 +1,10 @@ +variable: !k/expr foobar +VARIABLE: !k/expr foobar|upper +b64_variable: !k/expr foobar|b64encode +--- +json_variable: !k/expr object|to_json + +template: !k/template |- + {{ foobar }} + + {{ object.number }} diff --git a/tests/e2e/templates/multifile/one.yaml b/tests/e2e/templates/multifile/one.yaml new file mode 100644 index 0000000..9a82001 --- /dev/null +++ b/tests/e2e/templates/multifile/one.yaml @@ -0,0 +1,3 @@ +variable: !k/expr foobar +VARIABLE: !k/expr foobar|upper +b64_variable: !k/expr foobar|b64encode diff --git a/tests/e2e/templates/multifile/two.yaml b/tests/e2e/templates/multifile/two.yaml new file mode 100644 index 0000000..4240e7b --- /dev/null +++ b/tests/e2e/templates/multifile/two.yaml @@ -0,0 +1,6 @@ +json_variable: !k/expr object|to_json + +template: !k/template |- + {{ foobar }} + + {{ object.number }} diff --git a/tests/e2e/test_basic.yaml b/tests/e2e/test_basic.yaml new file mode 100644 index 0000000..26c5493 --- /dev/null +++ b/tests/e2e/test_basic.yaml @@ -0,0 +1,5 @@ +templates: + - templates/basic.yaml + +context: + - vars/_generic.yaml diff --git a/tests/e2e/test_contexts.yaml b/tests/e2e/test_contexts.yaml new file mode 100644 index 0000000..557572c --- /dev/null +++ b/tests/e2e/test_contexts.yaml @@ -0,0 +1,6 @@ +templates: + - templates/contexts.yaml + +context: + - vars/contexts.yaml + - vars/_generic.yaml diff --git a/tests/e2e/test_dir.yaml b/tests/e2e/test_dir.yaml new file mode 100644 index 0000000..987538f --- /dev/null +++ b/tests/e2e/test_dir.yaml @@ -0,0 +1,5 @@ +templates: + - templates/dir + +context: + - vars/_generic.yaml diff --git a/tests/e2e/test_dir_and_file.yaml b/tests/e2e/test_dir_and_file.yaml new file mode 100644 index 0000000..8e7d881 --- /dev/null +++ b/tests/e2e/test_dir_and_file.yaml @@ -0,0 +1,6 @@ +templates: + - templates/dir_and_file/dir + - templates/dir_and_file/two.yaml + +context: + - vars/_generic.yaml diff --git a/tests/e2e/test_encrypted.yaml b/tests/e2e/test_encrypted.yaml new file mode 100644 index 0000000..efbfc79 --- /dev/null +++ b/tests/e2e/test_encrypted.yaml @@ -0,0 +1,9 @@ +templates: + - templates/encrypted.yaml + +providers: + default: + key_path: .konverter-vault-test + +context: + - vars/_encrypted.yaml diff --git a/tests/e2e/test_multidoc.yaml b/tests/e2e/test_multidoc.yaml new file mode 100644 index 0000000..6b2b0e9 --- /dev/null +++ b/tests/e2e/test_multidoc.yaml @@ -0,0 +1,5 @@ +templates: + - templates/multidoc.yaml + +context: + - vars/_generic.yaml diff --git a/tests/e2e/test_multifile.yaml b/tests/e2e/test_multifile.yaml new file mode 100644 index 0000000..e5e1bbf --- /dev/null +++ b/tests/e2e/test_multifile.yaml @@ -0,0 +1,6 @@ +templates: + - templates/multifile/one.yaml + - templates/multifile/two.yaml + +context: + - vars/_generic.yaml diff --git a/tests/e2e/vars/_encrypted.yaml b/tests/e2e/vars/_encrypted.yaml new file mode 100644 index 0000000..60a9b64 --- /dev/null +++ b/tests/e2e/vars/_encrypted.yaml @@ -0,0 +1,2 @@ +encrypted_foobar: !k/vault gAAAAABeMdtcuKywSJfQo4b0fFDX0PC3ZGoKWGr3cRgl64bjx8taTlV-jAxlcX9AW3x2E5bx5OkYhQbvW8TRUcnxqtefneNirA== +unencrypted_barfoo: !k/encrypt Hello unencryted secret! diff --git a/tests/e2e/vars/_generic.yaml b/tests/e2e/vars/_generic.yaml new file mode 100644 index 0000000..7750cf1 --- /dev/null +++ b/tests/e2e/vars/_generic.yaml @@ -0,0 +1,5 @@ +foobar: Hello World! + +object: + number: 42 + other: FOOBAR diff --git a/tests/e2e/vars/contexts.yaml b/tests/e2e/vars/contexts.yaml new file mode 100644 index 0000000..45d8a20 --- /dev/null +++ b/tests/e2e/vars/contexts.yaml @@ -0,0 +1,5 @@ +object: + number: 43 + other: BARFOO + +barfoo: Hello context!