From 08196fe81993e4f43ecd5f7deefd1c3707f9b69e Mon Sep 17 00:00:00 2001 From: Vsevolod Fedorov Date: Tue, 27 Dec 2022 11:24:46 +0300 Subject: [PATCH] Tests: Add tests for missing and default parameters Change-Id: Iaca0cd39576e99829b20373bf7203ec205a1088c --- tests/conftest.py | 13 +++++++++- tests/enum_scenarios.py | 3 ++- .../missing_param_jinja2_macro_direct.error | 1 + .../missing_param_jinja2_macro_direct.yaml | 16 ++++++++++++ .../missing_param_jinja2_macro_indirect.error | 1 + .../missing_param_jinja2_macro_indirect.yaml | 21 ++++++++++++++++ ...missing_param_jinja2_template_direct.error | 1 + .../missing_param_jinja2_template_direct.yaml | 10 ++++++++ ...ssing_param_jinja2_template_indirect.error | 1 + ...issing_param_jinja2_template_indirect.yaml | 13 ++++++++++ .../missing_param_simple_macro_direct.error | 4 +++ .../missing_param_simple_macro_direct.yaml | 16 ++++++++++++ .../missing_param_simple_macro_indirect.error | 7 ++++++ .../missing_param_simple_macro_indirect.yaml | 21 ++++++++++++++++ ...missing_param_simple_template_direct.error | 7 ++++++ .../missing_param_simple_template_direct.yaml | 10 ++++++++ ...ssing_param_simple_template_indirect.error | 7 ++++++ ...issing_param_simple_template_indirect.yaml | 13 ++++++++++ .../default_param_jinja2_macro_direct.xml | 19 ++++++++++++++ .../default_param_jinja2_macro_direct.yaml | 16 ++++++++++++ .../default_param_jinja2_macro_indirect.xml | 19 ++++++++++++++ .../default_param_jinja2_macro_indirect.yaml | 20 +++++++++++++++ .../default_param_jinja2_template_direct.xml | 19 ++++++++++++++ .../default_param_jinja2_template_direct.yaml | 10 ++++++++ ...default_param_jinja2_template_indirect.xml | 19 ++++++++++++++ ...efault_param_jinja2_template_indirect.yaml | 13 ++++++++++ .../default_param_simple_macro_direct.xml | 20 +++++++++++++++ .../default_param_simple_macro_direct.yaml | 16 ++++++++++++ .../default_param_simple_macro_indirect.xml | 20 +++++++++++++++ .../default_param_simple_macro_indirect.yaml | 20 +++++++++++++++ .../default_param_simple_template_direct.xml | 20 +++++++++++++++ .../default_param_simple_template_direct.yaml | 10 ++++++++ ...default_param_simple_template_indirect.xml | 20 +++++++++++++++ ...efault_param_simple_template_indirect.yaml | 13 ++++++++++ tests/yamlparser/test_errors.py | 25 +++++++++++++++++++ 35 files changed, 462 insertions(+), 2 deletions(-) create mode 100644 tests/yamlparser/error_fixtures/missing_param_jinja2_macro_direct.error create mode 100644 tests/yamlparser/error_fixtures/missing_param_jinja2_macro_direct.yaml create mode 100644 tests/yamlparser/error_fixtures/missing_param_jinja2_macro_indirect.error create mode 100644 tests/yamlparser/error_fixtures/missing_param_jinja2_macro_indirect.yaml create mode 100644 tests/yamlparser/error_fixtures/missing_param_jinja2_template_direct.error create mode 100644 tests/yamlparser/error_fixtures/missing_param_jinja2_template_direct.yaml create mode 100644 tests/yamlparser/error_fixtures/missing_param_jinja2_template_indirect.error create mode 100644 tests/yamlparser/error_fixtures/missing_param_jinja2_template_indirect.yaml create mode 100644 tests/yamlparser/error_fixtures/missing_param_simple_macro_direct.error create mode 100644 tests/yamlparser/error_fixtures/missing_param_simple_macro_direct.yaml create mode 100644 tests/yamlparser/error_fixtures/missing_param_simple_macro_indirect.error create mode 100644 tests/yamlparser/error_fixtures/missing_param_simple_macro_indirect.yaml create mode 100644 tests/yamlparser/error_fixtures/missing_param_simple_template_direct.error create mode 100644 tests/yamlparser/error_fixtures/missing_param_simple_template_direct.yaml create mode 100644 tests/yamlparser/error_fixtures/missing_param_simple_template_indirect.error create mode 100644 tests/yamlparser/error_fixtures/missing_param_simple_template_indirect.yaml create mode 100644 tests/yamlparser/job_fixtures/default_param_jinja2_macro_direct.xml create mode 100644 tests/yamlparser/job_fixtures/default_param_jinja2_macro_direct.yaml create mode 100644 tests/yamlparser/job_fixtures/default_param_jinja2_macro_indirect.xml create mode 100644 tests/yamlparser/job_fixtures/default_param_jinja2_macro_indirect.yaml create mode 100644 tests/yamlparser/job_fixtures/default_param_jinja2_template_direct.xml create mode 100644 tests/yamlparser/job_fixtures/default_param_jinja2_template_direct.yaml create mode 100644 tests/yamlparser/job_fixtures/default_param_jinja2_template_indirect.xml create mode 100644 tests/yamlparser/job_fixtures/default_param_jinja2_template_indirect.yaml create mode 100644 tests/yamlparser/job_fixtures/default_param_simple_macro_direct.xml create mode 100644 tests/yamlparser/job_fixtures/default_param_simple_macro_direct.yaml create mode 100644 tests/yamlparser/job_fixtures/default_param_simple_macro_indirect.xml create mode 100644 tests/yamlparser/job_fixtures/default_param_simple_macro_indirect.yaml create mode 100644 tests/yamlparser/job_fixtures/default_param_simple_template_direct.xml create mode 100644 tests/yamlparser/job_fixtures/default_param_simple_template_direct.yaml create mode 100644 tests/yamlparser/job_fixtures/default_param_simple_template_indirect.xml create mode 100644 tests/yamlparser/job_fixtures/default_param_simple_template_indirect.yaml diff --git a/tests/conftest.py b/tests/conftest.py index 161f0a392..974f68d57 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -106,6 +106,14 @@ def expected_output(scenario): return "".join(path.read_text() for path in sorted(scenario.out_paths)) +@pytest.fixture +def expected_error(scenario): + if scenario.error_path.exists(): + return scenario.error_path.read_text().rstrip() + else: + return None + + def check_folder(scenario, jjb_config, input): if "name" not in input: return @@ -142,7 +150,10 @@ def check_parser(jjb_config, registry): def check(in_path): parser.parse(str(in_path)) - _ = parser.expandYaml(registry) + registry.set_parser_data(parser.data) + job_data_list, job_view_list = parser.expandYaml(registry) + generator = XmlJobGenerator(registry) + _ = generator.generateXML(job_data_list) return check diff --git a/tests/enum_scenarios.py b/tests/enum_scenarios.py index 58387db9f..560d7d1d6 100644 --- a/tests/enum_scenarios.py +++ b/tests/enum_scenarios.py @@ -21,7 +21,7 @@ from collections import namedtuple Scenario = namedtuple( - "Scnenario", "name in_path out_paths config_path plugins_info_path" + "Scnenario", "name in_path out_paths error_path config_path plugins_info_path" ) @@ -35,6 +35,7 @@ def scenario_list(fixtures_dir, in_ext=".yaml", out_ext=".xml"): name=path.stem, in_path=path, out_paths=out_path_list, + error_path=path.with_suffix(".error"), # When config file is missing it will still be passed and not None, # so JJBConfig will prefer it over system and user configs. config_path=path.with_suffix(".conf"), diff --git a/tests/yamlparser/error_fixtures/missing_param_jinja2_macro_direct.error b/tests/yamlparser/error_fixtures/missing_param_jinja2_macro_direct.error new file mode 100644 index 000000000..48e7bd080 --- /dev/null +++ b/tests/yamlparser/error_fixtures/missing_param_jinja2_macro_direct.error @@ -0,0 +1 @@ +'missing_param' is undefined diff --git a/tests/yamlparser/error_fixtures/missing_param_jinja2_macro_direct.yaml b/tests/yamlparser/error_fixtures/missing_param_jinja2_macro_direct.yaml new file mode 100644 index 000000000..b635bcc2f --- /dev/null +++ b/tests/yamlparser/error_fixtures/missing_param_jinja2_macro_direct.yaml @@ -0,0 +1,16 @@ +- project: + name: sample-project + jobs: + - sample-job + +- builder: + name: sample-builder + builders: + - shell: !j2: | + echo {{ missing_param }} {{ other_param }} + +- job-template: + name: sample-job + builders: + - sample-builder: + other_param: abc diff --git a/tests/yamlparser/error_fixtures/missing_param_jinja2_macro_indirect.error b/tests/yamlparser/error_fixtures/missing_param_jinja2_macro_indirect.error new file mode 100644 index 000000000..48e7bd080 --- /dev/null +++ b/tests/yamlparser/error_fixtures/missing_param_jinja2_macro_indirect.error @@ -0,0 +1 @@ +'missing_param' is undefined diff --git a/tests/yamlparser/error_fixtures/missing_param_jinja2_macro_indirect.yaml b/tests/yamlparser/error_fixtures/missing_param_jinja2_macro_indirect.yaml new file mode 100644 index 000000000..2e704c678 --- /dev/null +++ b/tests/yamlparser/error_fixtures/missing_param_jinja2_macro_indirect.yaml @@ -0,0 +1,21 @@ +- project: + name: sample-project + param_1: !j2: '{{ missing_param }}' + param_2: '{param_1}' + jobs: + - sample-job + +- builder: + name: sample-builder + builders: + - shell: !j2: | + # This param_2 usage does not actually trigger underined error. + # Error is triggered before macro substitution. + echo {{ param_3 }} {{ other_param }} + +- job-template: + name: sample-job + param_3: '{param_2}-plus' + builders: + - sample-builder: + other_param: abc diff --git a/tests/yamlparser/error_fixtures/missing_param_jinja2_template_direct.error b/tests/yamlparser/error_fixtures/missing_param_jinja2_template_direct.error new file mode 100644 index 000000000..48e7bd080 --- /dev/null +++ b/tests/yamlparser/error_fixtures/missing_param_jinja2_template_direct.error @@ -0,0 +1 @@ +'missing_param' is undefined diff --git a/tests/yamlparser/error_fixtures/missing_param_jinja2_template_direct.yaml b/tests/yamlparser/error_fixtures/missing_param_jinja2_template_direct.yaml new file mode 100644 index 000000000..253a701d0 --- /dev/null +++ b/tests/yamlparser/error_fixtures/missing_param_jinja2_template_direct.yaml @@ -0,0 +1,10 @@ +- project: + name: sample-project + jobs: + - sample-job + +- job-template: + name: sample-job + builders: + - shell: !j2: | + echo {{ missing_param }} diff --git a/tests/yamlparser/error_fixtures/missing_param_jinja2_template_indirect.error b/tests/yamlparser/error_fixtures/missing_param_jinja2_template_indirect.error new file mode 100644 index 000000000..48e7bd080 --- /dev/null +++ b/tests/yamlparser/error_fixtures/missing_param_jinja2_template_indirect.error @@ -0,0 +1 @@ +'missing_param' is undefined diff --git a/tests/yamlparser/error_fixtures/missing_param_jinja2_template_indirect.yaml b/tests/yamlparser/error_fixtures/missing_param_jinja2_template_indirect.yaml new file mode 100644 index 000000000..f6644b30b --- /dev/null +++ b/tests/yamlparser/error_fixtures/missing_param_jinja2_template_indirect.yaml @@ -0,0 +1,13 @@ +- project: + name: sample-project + param_1: !j2: '{{ missing_param }}' + param_2: '{param_1}' + jobs: + - sample-job + +- job-template: + name: sample-job + param_3: '{param_2}-plus' + builders: + - shell: !j2: | + echo {{ param_3 }} diff --git a/tests/yamlparser/error_fixtures/missing_param_simple_macro_direct.error b/tests/yamlparser/error_fixtures/missing_param_simple_macro_direct.error new file mode 100644 index 000000000..416e1ec2d --- /dev/null +++ b/tests/yamlparser/error_fixtures/missing_param_simple_macro_direct.error @@ -0,0 +1,4 @@ +missing_param parameter missing to format echo {missing_param} {other_param} + +Given: +{'other_param': 'abc'} diff --git a/tests/yamlparser/error_fixtures/missing_param_simple_macro_direct.yaml b/tests/yamlparser/error_fixtures/missing_param_simple_macro_direct.yaml new file mode 100644 index 000000000..ec55b995e --- /dev/null +++ b/tests/yamlparser/error_fixtures/missing_param_simple_macro_direct.yaml @@ -0,0 +1,16 @@ +- project: + name: sample-project + jobs: + - sample-job + +- builder: + name: sample-builder + builders: + - shell: | + echo {missing_param} {other_param} + +- job-template: + name: sample-job + builders: + - sample-builder: + other_param: abc diff --git a/tests/yamlparser/error_fixtures/missing_param_simple_macro_indirect.error b/tests/yamlparser/error_fixtures/missing_param_simple_macro_indirect.error new file mode 100644 index 000000000..290df4e25 --- /dev/null +++ b/tests/yamlparser/error_fixtures/missing_param_simple_macro_indirect.error @@ -0,0 +1,7 @@ +missing_param parameter missing to format {missing_param} +Given: +{'': '', + 'name': 'sample-project', + 'param_1': '{missing_param}', + 'param_2': '{param_1}', + 'template-name': 'sample-job'} diff --git a/tests/yamlparser/error_fixtures/missing_param_simple_macro_indirect.yaml b/tests/yamlparser/error_fixtures/missing_param_simple_macro_indirect.yaml new file mode 100644 index 000000000..60e6af9a1 --- /dev/null +++ b/tests/yamlparser/error_fixtures/missing_param_simple_macro_indirect.yaml @@ -0,0 +1,21 @@ +- project: + name: sample-project + param_1: '{missing_param}' + param_2: '{param_1}' + jobs: + - sample-job + +- builder: + name: sample-builder + builders: + - shell: | + # This param_2 usage does not actually trigger underined error. + # Error is triggered before macro substitution. + echo {param_3} {other_param} + +- job-template: + name: sample-job + param_3: '{param_2}-plus' + builders: + - sample-builder: + other_param: abc diff --git a/tests/yamlparser/error_fixtures/missing_param_simple_template_direct.error b/tests/yamlparser/error_fixtures/missing_param_simple_template_direct.error new file mode 100644 index 000000000..2106a8b04 --- /dev/null +++ b/tests/yamlparser/error_fixtures/missing_param_simple_template_direct.error @@ -0,0 +1,7 @@ +missing_param parameter missing to format echo {missing_param} + +Given: +{'': '', + 'builders': [OrderedDict([('shell', 'echo {missing_param}\n')])], + 'name': 'sample-project', + 'template-name': 'sample-job'} diff --git a/tests/yamlparser/error_fixtures/missing_param_simple_template_direct.yaml b/tests/yamlparser/error_fixtures/missing_param_simple_template_direct.yaml new file mode 100644 index 000000000..b95805fcc --- /dev/null +++ b/tests/yamlparser/error_fixtures/missing_param_simple_template_direct.yaml @@ -0,0 +1,10 @@ +- project: + name: sample-project + jobs: + - sample-job + +- job-template: + name: sample-job + builders: + - shell: | + echo {missing_param} diff --git a/tests/yamlparser/error_fixtures/missing_param_simple_template_indirect.error b/tests/yamlparser/error_fixtures/missing_param_simple_template_indirect.error new file mode 100644 index 000000000..290df4e25 --- /dev/null +++ b/tests/yamlparser/error_fixtures/missing_param_simple_template_indirect.error @@ -0,0 +1,7 @@ +missing_param parameter missing to format {missing_param} +Given: +{'': '', + 'name': 'sample-project', + 'param_1': '{missing_param}', + 'param_2': '{param_1}', + 'template-name': 'sample-job'} diff --git a/tests/yamlparser/error_fixtures/missing_param_simple_template_indirect.yaml b/tests/yamlparser/error_fixtures/missing_param_simple_template_indirect.yaml new file mode 100644 index 000000000..564a71403 --- /dev/null +++ b/tests/yamlparser/error_fixtures/missing_param_simple_template_indirect.yaml @@ -0,0 +1,13 @@ +- project: + name: sample-project + param_1: '{missing_param}' + param_2: '{param_1}' + jobs: + - sample-job + +- job-template: + name: sample-job + param_3: '{param_1}-plus' + builders: + - shell: | + echo {param_3} diff --git a/tests/yamlparser/job_fixtures/default_param_jinja2_macro_direct.xml b/tests/yamlparser/job_fixtures/default_param_jinja2_macro_direct.xml new file mode 100644 index 000000000..0002b8d3a --- /dev/null +++ b/tests/yamlparser/job_fixtures/default_param_jinja2_macro_direct.xml @@ -0,0 +1,19 @@ + + + + <!-- Managed by Jenkins Job Builder --> + false + false + false + false + true + + + + + echo default_value abc + + + + + diff --git a/tests/yamlparser/job_fixtures/default_param_jinja2_macro_direct.yaml b/tests/yamlparser/job_fixtures/default_param_jinja2_macro_direct.yaml new file mode 100644 index 000000000..022e9ccb9 --- /dev/null +++ b/tests/yamlparser/job_fixtures/default_param_jinja2_macro_direct.yaml @@ -0,0 +1,16 @@ +- project: + name: sample-project + jobs: + - sample-job + +- builder: + name: sample-builder + builders: + - shell: !j2: | + echo {{ missing_param | default('default_value') }} {{ other_param }} + +- job-template: + name: sample-job + builders: + - sample-builder: + other_param: abc diff --git a/tests/yamlparser/job_fixtures/default_param_jinja2_macro_indirect.xml b/tests/yamlparser/job_fixtures/default_param_jinja2_macro_indirect.xml new file mode 100644 index 000000000..d9b0ec700 --- /dev/null +++ b/tests/yamlparser/job_fixtures/default_param_jinja2_macro_indirect.xml @@ -0,0 +1,19 @@ + + + + <!-- Managed by Jenkins Job Builder --> + false + false + false + false + true + + + + + echo {param_2}-plus abc + + + + + diff --git a/tests/yamlparser/job_fixtures/default_param_jinja2_macro_indirect.yaml b/tests/yamlparser/job_fixtures/default_param_jinja2_macro_indirect.yaml new file mode 100644 index 000000000..71cd0b7ba --- /dev/null +++ b/tests/yamlparser/job_fixtures/default_param_jinja2_macro_indirect.yaml @@ -0,0 +1,20 @@ +- project: + name: sample-project + param_1: !j2: '{{ missing_param | default("default_value") }}' + param_2: '{param_1}' + jobs: + - sample-job + +- builder: + name: sample-builder + builders: + - shell: !j2: | + echo {{ param_3 }} {{ other_param }} + +- job-template: + name: sample-job + param_3: '{param_2}-plus' + builders: + - sample-builder: + param_3: '{param_3}' + other_param: abc diff --git a/tests/yamlparser/job_fixtures/default_param_jinja2_template_direct.xml b/tests/yamlparser/job_fixtures/default_param_jinja2_template_direct.xml new file mode 100644 index 000000000..16db330ee --- /dev/null +++ b/tests/yamlparser/job_fixtures/default_param_jinja2_template_direct.xml @@ -0,0 +1,19 @@ + + + + <!-- Managed by Jenkins Job Builder --> + false + false + false + false + true + + + + + echo default_value + + + + + diff --git a/tests/yamlparser/job_fixtures/default_param_jinja2_template_direct.yaml b/tests/yamlparser/job_fixtures/default_param_jinja2_template_direct.yaml new file mode 100644 index 000000000..b1cd30ca1 --- /dev/null +++ b/tests/yamlparser/job_fixtures/default_param_jinja2_template_direct.yaml @@ -0,0 +1,10 @@ +- project: + name: sample-project + jobs: + - sample-job + +- job-template: + name: sample-job + builders: + - shell: !j2: | + echo {{ missing_param | default('default_value') }} diff --git a/tests/yamlparser/job_fixtures/default_param_jinja2_template_indirect.xml b/tests/yamlparser/job_fixtures/default_param_jinja2_template_indirect.xml new file mode 100644 index 000000000..57a1f28ef --- /dev/null +++ b/tests/yamlparser/job_fixtures/default_param_jinja2_template_indirect.xml @@ -0,0 +1,19 @@ + + + + <!-- Managed by Jenkins Job Builder --> + false + false + false + false + true + + + + + echo {param_2}-plus + + + + + diff --git a/tests/yamlparser/job_fixtures/default_param_jinja2_template_indirect.yaml b/tests/yamlparser/job_fixtures/default_param_jinja2_template_indirect.yaml new file mode 100644 index 000000000..f3c0bd437 --- /dev/null +++ b/tests/yamlparser/job_fixtures/default_param_jinja2_template_indirect.yaml @@ -0,0 +1,13 @@ +- project: + name: sample-project + param_1: !j2: '{{ missing_param | default("default_value") }}' + param_2: '{param_1}' + jobs: + - sample-job + +- job-template: + name: sample-job + param_3: '{param_2}-plus' + builders: + - shell: !j2: | + echo {{ param_3 }} diff --git a/tests/yamlparser/job_fixtures/default_param_simple_macro_direct.xml b/tests/yamlparser/job_fixtures/default_param_simple_macro_direct.xml new file mode 100644 index 000000000..7a31835a5 --- /dev/null +++ b/tests/yamlparser/job_fixtures/default_param_simple_macro_direct.xml @@ -0,0 +1,20 @@ + + + + <!-- Managed by Jenkins Job Builder --> + false + false + false + false + true + + + + + echo default_value abc + + + + + + diff --git a/tests/yamlparser/job_fixtures/default_param_simple_macro_direct.yaml b/tests/yamlparser/job_fixtures/default_param_simple_macro_direct.yaml new file mode 100644 index 000000000..fb772ea44 --- /dev/null +++ b/tests/yamlparser/job_fixtures/default_param_simple_macro_direct.yaml @@ -0,0 +1,16 @@ +- project: + name: sample-project + jobs: + - sample-job + +- builder: + name: sample-builder + builders: + - shell: | + echo {missing_param|default_value} {other_param} + +- job-template: + name: sample-job + builders: + - sample-builder: + other_param: abc diff --git a/tests/yamlparser/job_fixtures/default_param_simple_macro_indirect.xml b/tests/yamlparser/job_fixtures/default_param_simple_macro_indirect.xml new file mode 100644 index 000000000..726973f93 --- /dev/null +++ b/tests/yamlparser/job_fixtures/default_param_simple_macro_indirect.xml @@ -0,0 +1,20 @@ + + + + <!-- Managed by Jenkins Job Builder --> + false + false + false + false + true + + + + + echo {param_2}-plus abc + + + + + + diff --git a/tests/yamlparser/job_fixtures/default_param_simple_macro_indirect.yaml b/tests/yamlparser/job_fixtures/default_param_simple_macro_indirect.yaml new file mode 100644 index 000000000..49b8752de --- /dev/null +++ b/tests/yamlparser/job_fixtures/default_param_simple_macro_indirect.yaml @@ -0,0 +1,20 @@ +- project: + name: sample-project + param_1: '{missing_param|default_value}' + param_2: '{param_1}' + jobs: + - sample-job + +- builder: + name: sample-builder + builders: + - shell: | + echo {param_3} {other_param} + +- job-template: + name: sample-job + param_3: '{param_2}-plus' + builders: + - sample-builder: + param_3: '{param_3}' + other_param: abc diff --git a/tests/yamlparser/job_fixtures/default_param_simple_template_direct.xml b/tests/yamlparser/job_fixtures/default_param_simple_template_direct.xml new file mode 100644 index 000000000..953382b7d --- /dev/null +++ b/tests/yamlparser/job_fixtures/default_param_simple_template_direct.xml @@ -0,0 +1,20 @@ + + + + <!-- Managed by Jenkins Job Builder --> + false + false + false + false + true + + + + + echo default_value + + + + + + diff --git a/tests/yamlparser/job_fixtures/default_param_simple_template_direct.yaml b/tests/yamlparser/job_fixtures/default_param_simple_template_direct.yaml new file mode 100644 index 000000000..b6b41cb68 --- /dev/null +++ b/tests/yamlparser/job_fixtures/default_param_simple_template_direct.yaml @@ -0,0 +1,10 @@ +- project: + name: sample-project + jobs: + - sample-job + +- job-template: + name: sample-job + builders: + - shell: | + echo {missing_param|default_value} diff --git a/tests/yamlparser/job_fixtures/default_param_simple_template_indirect.xml b/tests/yamlparser/job_fixtures/default_param_simple_template_indirect.xml new file mode 100644 index 000000000..1ae619a25 --- /dev/null +++ b/tests/yamlparser/job_fixtures/default_param_simple_template_indirect.xml @@ -0,0 +1,20 @@ + + + + <!-- Managed by Jenkins Job Builder --> + false + false + false + false + true + + + + + echo {param_2}-plus + + + + + + diff --git a/tests/yamlparser/job_fixtures/default_param_simple_template_indirect.yaml b/tests/yamlparser/job_fixtures/default_param_simple_template_indirect.yaml new file mode 100644 index 000000000..b77f57d50 --- /dev/null +++ b/tests/yamlparser/job_fixtures/default_param_simple_template_indirect.yaml @@ -0,0 +1,13 @@ +- project: + name: sample-project + param_1: '{missing_param|default_value}' + param_2: '{param_1}' + jobs: + - sample-job + +- job-template: + name: sample-job + param_3: '{param_2}-plus' + builders: + - shell: | + echo {param_3} diff --git a/tests/yamlparser/test_errors.py b/tests/yamlparser/test_errors.py index 4bccb9910..cda1add6a 100644 --- a/tests/yamlparser/test_errors.py +++ b/tests/yamlparser/test_errors.py @@ -16,14 +16,33 @@ # under the License. import os +from operator import attrgetter from pathlib import Path import pytest +from tests.enum_scenarios import scenario_list fixtures_dir = Path(__file__).parent / "error_fixtures" +@pytest.fixture( + params=[ + s + for s in scenario_list(fixtures_dir) + if s.in_path.name + not in { + "incorrect_template_dimensions.yaml", + "failure_formatting_template.yaml", + "failure_formatting_params.yaml", + } + ], + ids=attrgetter("name"), +) +def scenario(request): + return request.param + + # Override to avoid scenarios usage. @pytest.fixture def config_path(): @@ -51,3 +70,9 @@ def test_failure_formatting(caplog, check_parser, name): check_parser(in_path) assert f"Failure formatting {name}" in caplog.text assert "Problem formatting with args" in caplog.text + + +def test_error(check_parser, scenario, expected_error): + with pytest.raises(Exception) as excinfo: + check_parser(scenario.in_path) + assert str(excinfo.value) == expected_error