add test for resolve-env option in dump plugin

This patch adds a test for the --resolve-env option in the dump plugin.
Both cases resolve and non-resolve are tested, each for yaml and json
output format.

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Felix Moessbauer 2022-12-11 08:30:34 +01:00 committed by Jan Kiszka
parent 20a69016da
commit 88a2b3d47b
2 changed files with 16 additions and 1 deletions

View File

@ -77,21 +77,33 @@ def test_dump(changedir, tmpdir, capsys):
os.chdir(tdir) os.chdir(tdir)
formats = ['json', 'yaml'] formats = ['json', 'yaml']
resolve = ['', '--resolve-refs'] resolve = ['', '--resolve-refs', '--resolve-env']
# test cross-product of these options (formats x resolve) # test cross-product of these options (formats x resolve)
for f, r in ((f, r) for f in formats for r in resolve): for f, r in ((f, r) for f in formats for r in resolve):
outfile = 'test_flat.%s' % f outfile = 'test_flat.%s' % f
if r == '--resolve-env':
os.environ['TESTVAR_FOO'] = 'KAS'
kas.kas(('dump --format %s %s test.yml' % (f, r)).split()) kas.kas(('dump --format %s %s test.yml' % (f, r)).split())
if r == '--resolve-env':
del os.environ['TESTVAR_FOO']
with open(outfile, 'w') as f: with open(outfile, 'w') as f:
f.write(capsys.readouterr().out) f.write(capsys.readouterr().out)
with open(outfile, 'r') as cf: with open(outfile, 'r') as cf:
flatconf = json.load(cf) if f == 'json' else yaml.safe_load(cf) flatconf = json.load(cf) if f == 'json' else yaml.safe_load(cf)
refspec = flatconf['repos']['kas3']['refspec'] refspec = flatconf['repos']['kas3']['refspec']
envvar = flatconf['env']['TESTVAR_FOO']
if r == '--resolve-refs': if r == '--resolve-refs':
assert refspec != 'master' assert refspec != 'master'
else: else:
assert refspec == 'master' assert refspec == 'master'
if r == '--resolve-env':
assert envvar == 'KAS'
else:
assert envvar == 'BAR'
assert 'includes' not in flatconf['header'] assert 'includes' not in flatconf['header']
# check if kas can read the generated file # check if kas can read the generated file

View File

@ -4,6 +4,9 @@ header:
- repo: subrepo - repo: subrepo
file: test.yml file: test.yml
env:
TESTVAR_FOO: "BAR"
repos: repos:
this: this: