From 06366b02e7851f9dfb5d3818d457bfca19863ce4 Mon Sep 17 00:00:00 2001 From: Vsevolod Fedorov Date: Wed, 24 Jan 2024 11:51:25 +0300 Subject: [PATCH] Add test for macros using defaults Change-Id: I62ac7b8056b5e8151b68675551453c95c7822c6c --- .../macro-uses-custom-defaults.error | 18 +++++++++ .../macro-uses-custom-defaults.yaml | 37 +++++++++++++++++++ .../macro-uses-custom-defaults.yaml.inc | 1 + .../macro-uses-global-defaults.error | 18 +++++++++ .../macro-uses-global-defaults.yaml | 35 ++++++++++++++++++ .../macro-uses-global-defaults.yaml.inc | 1 + 6 files changed, 110 insertions(+) create mode 100644 tests/yamlparser/error_fixtures/macro-uses-custom-defaults.error create mode 100644 tests/yamlparser/error_fixtures/macro-uses-custom-defaults.yaml create mode 100644 tests/yamlparser/error_fixtures/macro-uses-custom-defaults.yaml.inc create mode 100644 tests/yamlparser/error_fixtures/macro-uses-global-defaults.error create mode 100644 tests/yamlparser/error_fixtures/macro-uses-global-defaults.yaml create mode 100644 tests/yamlparser/error_fixtures/macro-uses-global-defaults.yaml.inc diff --git a/tests/yamlparser/error_fixtures/macro-uses-custom-defaults.error b/tests/yamlparser/error_fixtures/macro-uses-custom-defaults.error new file mode 100644 index 000000000..4d13a5177 --- /dev/null +++ b/tests/yamlparser/error_fixtures/macro-uses-custom-defaults.error @@ -0,0 +1,18 @@ +macro-uses-custom-defaults.yaml:34:3: In project 'sample-project' + - project: + ^ +macro-uses-custom-defaults.yaml:37:7: Defined here + - sample-job-template + ^ +macro-uses-custom-defaults.yaml:26:3: In job template 'sample-job-template' + - job-template: + ^ +macro-uses-custom-defaults.yaml:30:7: While expanding builder macro call 'builder-without-params' + - builder-without-params + ^ +macro-uses-custom-defaults.yaml:7:3: While expanding macro 'builder-without-params' + - builder: + ^ +macro-uses-custom-defaults.yaml:12:9: While formatting string 'echo "builder-without-params: Fails when trying to expand: {global_param}"\n...': Missing parameter: 'global_param' + echo "builder-without-params: Fails when tryi ... + ^ diff --git a/tests/yamlparser/error_fixtures/macro-uses-custom-defaults.yaml b/tests/yamlparser/error_fixtures/macro-uses-custom-defaults.yaml new file mode 100644 index 000000000..9b5a5b669 --- /dev/null +++ b/tests/yamlparser/error_fixtures/macro-uses-custom-defaults.yaml @@ -0,0 +1,37 @@ +# Macros do not use custom defaults. + +- defaults: + name: custom + global_param: sample global param value + +- builder: + name: builder-without-params + # defaults: custom + builders: + - shell: | + echo "builder-without-params: Fails when trying to expand: {global_param}" + # Also fails when trying to expand: + - shell: !include-raw-expand: macro-uses-custom-defaults.yaml.inc + +- builder: + name: builder-with-params + # defaults: custom + builders: + - shell: | + echo "builder-with-params: Should be expanded: {param}" + - shell: | + echo "builder-with-params: Fails when trying to expand: {global_param}" + - shell: !include-raw-expand: macro-uses-custom-defaults.yaml.inc + +- job-template: + name: sample-job-template + display-name: sample-job-template + builders: + - builder-without-params + - builder-with-params: + param: sample macro param value + +- project: + name: sample-project + jobs: + - sample-job-template diff --git a/tests/yamlparser/error_fixtures/macro-uses-custom-defaults.yaml.inc b/tests/yamlparser/error_fixtures/macro-uses-custom-defaults.yaml.inc new file mode 100644 index 000000000..7c187717d --- /dev/null +++ b/tests/yamlparser/error_fixtures/macro-uses-custom-defaults.yaml.inc @@ -0,0 +1 @@ +echo "include-raw-expand: Fails when trying to expand: {global_param}" diff --git a/tests/yamlparser/error_fixtures/macro-uses-global-defaults.error b/tests/yamlparser/error_fixtures/macro-uses-global-defaults.error new file mode 100644 index 000000000..771fa729e --- /dev/null +++ b/tests/yamlparser/error_fixtures/macro-uses-global-defaults.error @@ -0,0 +1,18 @@ +macro-uses-global-defaults.yaml:32:3: In project 'sample-project' + - project: + ^ +macro-uses-global-defaults.yaml:35:7: Defined here + - sample-job-template + ^ +macro-uses-global-defaults.yaml:24:3: In job template 'sample-job-template' + - job-template: + ^ +macro-uses-global-defaults.yaml:28:7: While expanding builder macro call 'builder-without-params' + - builder-without-params + ^ +macro-uses-global-defaults.yaml:7:3: While expanding macro 'builder-without-params' + - builder: + ^ +macro-uses-global-defaults.yaml:11:9: While formatting string 'echo "builder-without-params: Fails when trying to expand: {global_param}"\n...': Missing parameter: 'global_param' + echo "builder-without-params: Fails when tryi ... + ^ diff --git a/tests/yamlparser/error_fixtures/macro-uses-global-defaults.yaml b/tests/yamlparser/error_fixtures/macro-uses-global-defaults.yaml new file mode 100644 index 000000000..e7d3fc5f8 --- /dev/null +++ b/tests/yamlparser/error_fixtures/macro-uses-global-defaults.yaml @@ -0,0 +1,35 @@ +# Macros do not use global defaults. + +- defaults: + name: global + global_param: sample global param value + +- builder: + name: builder-without-params + builders: + - shell: | + echo "builder-without-params: Fails when trying to expand: {global_param}" + # Also fails when trying to expand: + - shell: !include-raw-expand: macro-uses-global-defaults.yaml.inc + +- builder: + name: builder-with-params + builders: + - shell: | + echo "builder-with-params: Should be expanded: {param}" + - shell: | + echo "builder-with-params: Fails when trying to expand: {global_param}" + - shell: !include-raw-expand: macro-uses-global-defaults.yaml.inc + +- job-template: + name: sample-job-template + display-name: sample-job-template + builders: + - builder-without-params + - builder-with-params: + param: sample macro param value + +- project: + name: sample-project + jobs: + - sample-job-template diff --git a/tests/yamlparser/error_fixtures/macro-uses-global-defaults.yaml.inc b/tests/yamlparser/error_fixtures/macro-uses-global-defaults.yaml.inc new file mode 100644 index 000000000..7c187717d --- /dev/null +++ b/tests/yamlparser/error_fixtures/macro-uses-global-defaults.yaml.inc @@ -0,0 +1 @@ +echo "include-raw-expand: Fails when trying to expand: {global_param}"