goss-org / goss

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

Unclear how to leveragle semver matcher to filter execution #676

Closed vromero closed 3 years ago

vromero commented 3 years ago

After the fix of #355 (thanks!) I was expecting to be able to convert something like this:

{{ if and (.Env.VERSION | regexMatch "(1.5.[^012]|[^1]\\.\\d+\\.\\d+)") }}
  /some/file:
    exists: true
{{ end }}

to something like this

{{ if and (.Env.ACTIVEMQ_ARTEMIS_VERSION | semverConstraint: ">=1.5.3") }}
  /some/file:
    exists: true
{{ end }}

But either the current implementation only matches packages or I just don't get it.

Is this filter I'm trying to apply something actually possible?

Thanks

vromero commented 3 years ago

FYI @aelsabbahy @pedroMMM

EleanorRigby commented 3 years ago

I am interested in this solution too. We need to test the OS kernel versions to be at least greater than some semver.

more: https://github.com/kubernetes-sigs/image-builder/pull/472

cc: @sanikagawhane

pedroMMM commented 3 years ago

I am sorry everyone I haven't been paying attention to OSS since under my current contract I can't contribute code (gaming industry quirks).

@vromero I found your issue. semverConstraint isn't the custom matcher, the custom matcher is semver-constraint. But custom matchers don't function inside the template language, lucky we integrated Sprig Template Functions which comes with its own function for SemVer. With this I was able to replicate your use case by using:

file:
{{ if .Env.VERSION | semverCompare ">=1.5.3" }}
  /some/file:
    exists: true
{{ end }}

@EleanorRigby I am sure of the technical reason but you can't use the matchers on the command, @aelsabbahy can you explain the details and/or give some alternative.

vromero commented 3 years ago

@pedroMMM thanks a lot! This is super useful. Also thanks for your original PR, even if I end upusing Sprig, your contribution to OSS is very appretiated.