goss-org / goss

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

Support multiple valid values for the `file.mode` check #782

Closed samuel-phan closed 10 months ago

samuel-phan commented 1 year ago

Describe the feature:

Support multiple valid values instead of just one for a check.

Eg:

file:
  /foo:
    exists: true
    mode: "0644"

but if on a host, the file has the mode 0444, I want to consider it as good also.

Describe the solution you'd like

Instead of supporting only 1 value for mode, it could support a list of valid modes.

file:
  /foo:
    exists: true
    mode:
      - "0644"
      - "0444"

Describe alternatives you've considered

I don't know any workaround except dropping the file.mode check.

ekelali commented 1 year ago

This can be done today using or:

yaml

file:
  /foo:
    exists: true
    mode:
      or:
        - "0644"
        - "0444"
samuel-phan commented 1 year ago

Thanks @ekelali ! It works indeed.

I didn't find it in the doc https://github.com/aelsabbahy/goss/blob/master/docs/manual.md . I guess it's part of the gomega matchers, but the gomega doc is pretty unreadable for most of non-Golang humans, and if I search for have-len for example, I can't find it in the gomega doc.

Could we add some doc about the logical & more matchers, because I was searching for logical operator or keywords like that, and found none in the Goss doc :(

aelsabbahy commented 1 year ago

@samuel-phan that's a great call out regarding documentation being difficult to navigate for non-golang crowd.

This test + gomega is the current docs, ex:

https://github.com/aelsabbahy/goss/blob/master/resource/gomega_test.go#L124-L125

That said, the next major release of Goss will have improved documentation, but it's not released yet, and there's no current estimate on the release date.

Is the new format clearer? Please note a lot of the new documentation wouldn't work for the current release. But would love your feedback on the format.

https://github.com/aelsabbahy/goss/blob/v4/docs/manual.md#misc-matchers

Also, in the meantime if you'd like to submit a PR for the current version, I would gladly accept it.

aelsabbahy commented 10 months ago

Now that the new version of go is released the documentation is much improved.

Feel free to open a new ticket if it's still unclear.