goss-org / goss

Quick and Easy server testing/validation
https://goss.rocks
Apache License 2.0
5.5k stars 470 forks source link

yaml escaping seen as string and not boolean #913

Closed smerle33 closed 1 month ago

smerle33 commented 1 month ago

Describe the bug if I escape the skip part I got and unmarshal error

visualstudio:
    exec: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe -nologo -version
    exit-status: 0
    stdout:
      - /16\.\d+\.\d+\.\d+/
    skip: '{{ not (eq .Env.AGENT_OS_VERSION "2019") }}'
export GOSS_USE_ALPHA=1; export AGENT_OS_VERSION=2022; goss -g ./goss/goss-windows.yaml render
2024/05/14 14:30:33 yaml: unmarshal errors:
  line 62: cannot unmarshal !!str `true` into bool

but if I don't escape then the yaml seems to be wrong as told by https://github.com/goccy/go-yaml/tree/master (used within updatecli):

visualstudio:
    exec: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe -nologo -version
    exit-status: 0
    stdout:
      - /16\.\d+\.\d+\.\d+/
    skip: {{ not (eq .Env.AGENT_OS_VERSION "2019") }}
ERROR: something went wrong in target "updateJDK21VersionInGoss" : "updating yaml file: parsing yaml file: [62:12] unexpected mapping key\n      59 |     exit-status: 0\n      60 |     stdout:\n      61 |       - /16\\.\\d+\\.\\d+\\.\\d+/\n    > 62 |     skip: {{ not (eq .Env.AGENT_OS_VERSION \"2019\") }}\n                      ^\n      63 | file:\n      64 |   C:\\Program Files\\Chromium\\Application\\:\n      65 |     contains: []"

How To Reproduce everything is public here : https://github.com/jenkins-infra/packer-images from the goss file: https://github.com/jenkins-infra/packer-images/blob/main/goss/goss-windows.yaml to one of the updatecli manifest that break if the skip line is not escape: https://github.com/jenkins-infra/packer-images/blob/main/updatecli/updatecli.d/jdk21.yml

export GOSS_USE_ALPHA=1; export AGENT_OS_VERSION=2022; goss -g ./goss/goss-windows.yaml render

updatecli diff --values ./updatecli/values.yaml --config ./updatecli/updatecli.d/jdk21.yml

Expected Behavior that this version:

visualstudio:
    exec: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe -nologo -version
    exit-status: 0
    stdout:
      - /16\.\d+\.\d+\.\d+/
    skip: '{{ not (eq .Env.AGENT_OS_VERSION "2019") }}'

or

visualstudio:
    exec: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe -nologo -version
    exit-status: 0
    stdout:
      - /16\.\d+\.\d+\.\d+/
    skip: |
        {{ not (eq .Env.AGENT_OS_VERSION "2019") }}

manage to convert true or false string to boolean

Actual Behavior error line 62: cannot unmarshal !!str true into bool

Environment:

smerle33 commented 1 month ago

in fact the online version should be seen as correct yaml, changing the engine on the updatecli solved the issue.

aelsabbahy commented 1 month ago

Sounds like updatecli had/has the bug?

pilere commented 1 month ago

Sounds like updatecli had/has the bug?

not really, but depending on the yaml engine used, it's seen as wrong yaml ... the smart thing about updatecli is that you can choose your yaml engine