Skarlso / crd-to-sample-yaml

Generate a sample YAML file from a CRD and view it rendered on a nice website
https://crdtoyaml.com/
Apache License 2.0
131 stars 17 forks source link

Add crd test command and GitHub action config #96

Closed Skarlso closed 3 months ago

Skarlso commented 3 months ago
./cty test sample-tests
+-----------------------------------+---------------+---------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------+
| IT                                | MATCHER       | ERROR                                                                                                                                 | TEMPLATE                                                           |
+-----------------------------------+---------------+---------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------+
| matches bootstrap crds correctly  | matchSnapshot | <nil>                                                                                                                                 | sample-tests/crds/bootstrap_crd.yaml                               |
| matches bootstrap crds correctly  | matchSnapshot | <nil>                                                                                                                                 | sample-tests/crds/bootstrap_crd.yaml                               |
| matches some custom stuff         | matchString   | <nil>                                                                                                                                 | sample-tests/crds/bootstrap_crd.yaml                               |
| matches AWSCluster crds correctly | matchSnapshot | <nil>                                                                                                                                 | sample-tests/crds/infrastructure.cluster.x-k8s.io_awsclusters.yaml |
| matches AWSCluster crds correctly | matchSnapshot | <nil>                                                                                                                                 | sample-tests/crds/infrastructure.cluster.x-k8s.io_awsclusters.yaml |
| matches AWSCluster crds correctly | matchString   | <nil>                                                                                                                                 | sample-tests/crds/infrastructure.cluster.x-k8s.io_awsclusters.yaml |
| matches AWSCluster crds correctly | matchString   | matcher returned failure: failed to validate kind AWSCluster: spec.controlPlaneEndpoint.host in body must be of type string: "number" | sample-tests/crds/infrastructure.cluster.x-k8s.io_awsclusters.yaml |
+-----------------------------------+---------------+---------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------+

Tests total: 7, failed: 1, passed: 6
Error: 1 test(s) failed
Usage:
  crd-to-sample test [flags]

Flags:
  -h, --help     help for test
  -u, --update   Update any existing snapshots.

2024/08/19 08:23:42 failed to run command: 1 test(s) failed

Arguably the output could be nicer and the failure including the HELP of the command is ugly.

Skarlso commented 3 months ago
✗ ./cty test sample-tests
+-----------------------------------+---------------+---------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------+
| IT                                | MATCHER       | ERROR                                                                                                                                 | TEMPLATE                                                           |
+-----------------------------------+---------------+---------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------+
| matches AWSCluster crds correctly | matchSnapshot | <nil>                                                                                                                                 | sample-tests/crds/infrastructure.cluster.x-k8s.io_awsclusters.yaml |
| matches AWSCluster crds correctly | matchSnapshot | <nil>                                                                                                                                 | sample-tests/crds/infrastructure.cluster.x-k8s.io_awsclusters.yaml |
| matches AWSCluster crds correctly | matchString   | <nil>                                                                                                                                 | sample-tests/crds/infrastructure.cluster.x-k8s.io_awsclusters.yaml |
| matches AWSCluster crds correctly | matchString   | matcher returned failure: failed to validate kind AWSCluster: spec.controlPlaneEndpoint.host in body must be of type string: "number" | sample-tests/crds/infrastructure.cluster.x-k8s.io_awsclusters.yaml |
| matches bootstrap crds correctly  | matchSnapshot | <nil>                                                                                                                                 | sample-tests/crds/bootstrap_crd.yaml                               |
| matches bootstrap crds correctly  | matchSnapshot | <nil>                                                                                                                                 | sample-tests/crds/bootstrap_crd.yaml                               |
| matches some custom stuff         | matchString   | <nil>                                                                                                                                 | sample-tests/crds/bootstrap_crd.yaml                               |
+-----------------------------------+---------------+---------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------+

Tests total: 7, failed: 1, passed: 6
➜  crd-to-sample-yaml git:(add-crd-test-command-and-github-action-config) ✗ echo $?
1
➜  crd-to-sample-yaml git:(add-crd-test-command-and-github-action-config) ✗

That's better.

Skarlso commented 3 months ago
Screenshot 2024-08-19 at 08 47 33

Added some color and wrapping of long text into the mix.