Hello everyone! Previously I wrote about cty[^1] that can be used to generate valid YAML samples from a CRD ( now, including things like, valid Pattern generated random string, enums, default values, minimum int, minimum number of items.. etc ). It also has a website that can be used to achieve the same thing here: https://crdtoyaml.com/ This update https://github.com/Skarlso/crd-to-sample-yaml/releases/tag/v... brings a feature with it, which I think is super cool. If not, well, then no. :) Basically, inspired by `helm unittest` the user can define a test like this:
This will take a CRD and test the CRD validates a given sample. In this case, it's a string and two snapshot values. The snapshots can be generated using `cty test sample-tests --update`.The snapshots will contain valid values, such as minimum integer, minimum number of items, defaults, enums, Patterns ( yes it generates random value that will satisfy a given pattern regex ) and more. It will only ever match the right version with the right version. Meaning it won't try `v1beta2` to match to `v1alpha1`. Since CRD files can have multiple versions in them. It can be added as a simple make target like helm unittest. This is very much an alpha feature, so please, if you do use it, report any problems. :) Thank you! Enjoy. |