goss-org / goss

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

Consider allowing individual '--vars' via the command line instead of requiring a file #439

Closed mkobit closed 4 years ago

mkobit commented 5 years ago

Some shells don't have process substitution, and environment variables can't be structured as easily when you want to pass in multiple inputs. It could be useful to pass in --vars without modifying a file for adhoc testing, or for just running things without requiring a vars file at all.

A possible example

goss --var ip.addr='[1.1.1.1, 2.2.2.2]' validate
aelsabbahy commented 4 years ago

I'm not sure how easy it will be to implement this in Go the way you've requested to be honest. (handling complex/nested) objects.

Would allowing JSON on the CLI meet your needs? Or is that not a useful feature?

goss --vars '{"ip": {"addr": [1.1.1.1, 2.2.2.2]}}' validate

Tagging @pedroMMM since he :+1: this, would love your feedback also.

pedroMMM commented 4 years ago

In my use case, I was calling Goss from Packer and I needed to inject multiple runtime values alongside my variables file to Goss. In my case, I just got around it by forking and expanding the Goss Packer Provisioner to support exactly what you just described since the Provisioner was already moving the variables file to the instance.

I support adding a --vars-inline '{...}' variable since it will enable users to run Goss for ad hoc testing/debugging but also in more complex scenarios like mine. To be clear the --vars-inline will be loaded after the --vars which means that keys from inline (that overlap) will overwrite those that were sourced from the file. This will have to be made clear to users.

aelsabbahy commented 4 years ago

Yup, documentation should be clear that not only will vars-inline win, but no advanced deep merging will be done.

aelsabbahy commented 4 years ago

released