From bfd6bd619566e8d7c9053b1f8834b80f14c18bb1 Mon Sep 17 00:00:00 2001 From: Felix Moessbauer Date: Sun, 11 Dec 2022 08:30:28 +0100 Subject: [PATCH] add test of dump plugin This patch adds a basic test of the dump plugin. We check if the configuration is flattened and external references are included. In addition, we check if no other files are referenced anymore. Signed-off-by: Felix Moessbauer Signed-off-by: Jan Kiszka --- tests/test_commands.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_commands.py b/tests/test_commands.py index d045e3f..f557508 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -23,6 +23,8 @@ import glob import os import shutil +import json +import yaml from kas import kas @@ -66,3 +68,22 @@ def test_repo_includes(changedir, tmpdir): shutil.copytree('tests/test_repo_includes', tdir) os.chdir(tdir) kas.kas(['checkout', 'test.yml']) + + +def test_dump(changedir, tmpdir, capsys): + tdir = str(tmpdir.mkdir('test_commands')) + shutil.rmtree(tdir, ignore_errors=True) + shutil.copytree('tests/test_repo_includes', tdir) + os.chdir(tdir) + + formats = ['json', 'yaml'] + for f in formats: + outfile = 'test_flat.%s' % f + kas.kas(('dump --format %s test.yml' % f).split()) + with open(outfile, 'w') as f: + f.write(capsys.readouterr().out) + + with open(outfile, 'r') as cf: + flatconf = json.load(cf) if f == 'json' else yaml.safe_load(cf) + assert flatconf['repos']['kas3']['refspec'] == 'master' + assert 'includes' not in flatconf['header']