Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling helm error exitcode #110

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ integ-test: install-dev-bin
helm chartsnap --chart cilium -f example/remote/cilium.values.yaml $(ARGS) -- --namespace kube-system --repo https://helm.cilium.io $(EXTRA_ARGS)
helm chartsnap --chart ingress-nginx -f example/remote/ingress-nginx.values.yaml $(ARGS) -- --repo https://kubernetes.github.io/ingress-nginx --namespace ingress-nginx --skip-tests $(EXTRA_ARGS)
helm chartsnap --chart example/app2 --namespace default $(ARGS)
helm chartsnap --chart example/app3 --namespace default $(ARGS)
helm chartsnap --chart example/app3 --namespace default $(ARGS) -f example/app3/test/ok.yaml

.PHONY: integ-test-kong
integ-test-kong:
Expand Down
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ Examples:
# Snapshot remote chart in Helm repository:
chartsnap -c CHART_NAME -f YOUR_VALUES_FILE -- --repo HELM_REPO_URL

# Snapshot [`ingress-nginx`](https://kubernetes.github.io/ingress-nginx/) helm chart for a specific version with your value file:
# Snapshot ingress-nginx (https://kubernetes.github.io/ingress-nginx/) helm chart for a specific version with your value file:
chartsnap -c ingress-nginx -f YOUR_VALUES_FILE -- --repo https://kubernetes.github.io/ingress-nginx --namespace kube-system --version 4.8.3

# Snapshot [`cilium`](https://cilium.io) helm chart with default value and set flags:
# Snapshot cilium (https://cilium.io) helm chart with default value and set flags:
chartsnap -c cilium -- --repo https://helm.cilium.io --namespace kube-system --set hubble.relay.enabled=true --set hubble.ui.enabled=true

# Snapshot charts in OCI registry
Expand All @@ -160,19 +160,21 @@ Examples:
NO_COLOR=1 chartsnap -c YOUR_CHART

Flags:
-c, --chart string path to the chart directory. this flag is passed to 'helm template RELEASE_NAME CHART --values VALUES' as 'CHART'
--config-file string config file name or path, which defines snapshot behavior e.g. dynamic fields (default ".chartsnap.yaml")
-N, --ctx-lines int number of lines to show in diff output. 0 for full output (default 3)
--debug debug mode
--failfast fail once any test case failed
-h, --help help for chartsnap
-n, --namespace string namespace. this flag is passed to 'helm template RELEASE_NAME CHART --values VALUES --namespace NAMESPACE' as 'NAMESPACE' (default "default")
-o, --output-dir string directory which is __snapshot__ directory is created. (default: values file directory if --values is set; chart directory if chart is local; else current directory)
--parallelism int test concurrency if taking multiple snapshots for a test value file directory. default is unlimited (default -1)
--release-name string release name. this flag is passed to 'helm template RELEASE_NAME CHART --values VALUES' as 'RELEASE_NAME' (default "chartsnap")
-u, --update-snapshot update snapshot mode
-f, --values string path to a test values file or directory. if the directory is set, all test files are tested. if empty, default values are used. this flag is passed to 'helm template RELEASE_NAME CHART --values VALUES' as 'VALUES'
-v, --version version for chartsnap
-c, --chart string path to the chart directory. this flag is passed to 'helm template RELEASE_NAME CHART --values VALUES' as 'CHART'
--config-file string config file name or path, which defines snapshot behavior e.g. dynamic fields (default ".chartsnap.yaml")
-N, --ctx-lines int number of lines to show in diff output. 0 for full output (default 3)
--debug debug mode
--fail-helm-error fail if 'helm template' command failed
--failfast fail once any test case failed
-h, --help help for chartsnap
-n, --namespace string namespace. this flag is passed to 'helm template RELEASE_NAME CHART --values VALUES --namespace NAMESPACE' as 'NAMESPACE' (default "default")
-o, --output-dir string directory which is __snapshot__ directory is created. (default: values file directory if --values is set; chart directory if chart is local; else current directory)
--parallelism int test concurrency if taking multiple snapshots for a test value file directory. default is unlimited (default -1)
--release-name string release name. this flag is passed to 'helm template RELEASE_NAME CHART --values VALUES' as 'RELEASE_NAME' (default "chartsnap")
--snapshot-version string use a specific snapshot format version. v1, v2, v3 are supported. (default: latest)
-u, --update-snapshot update snapshot mode
-f, --values string path to a test values file or directory. if the directory is set, all test files are tested. if empty, default values are used. this flag is passed to 'helm template RELEASE_NAME CHART --values VALUES' as 'VALUES'
-v, --version version for chartsnap

```

Expand Down
60 changes: 60 additions & 0 deletions __snapshots__/main_test.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,56 @@
['rootCmd --help should show help 1']
SnapShot = """
Usage:
chartsnap -c CHART [flags]

Examples:

# Snapshot with default values:
chartsnap -c YOUR_CHART

# Update snapshot files:
chartsnap -c YOUR_CHART -u

# Snapshot with test case values:
chartsnap -c YOUR_CHART -f YOUR_TEST_VALUES_FILE

# Snapshot all test cases:
chartsnap -c YOUR_CHART -f YOUR_TEST_VALUES_FILES_DIRECTOY

# Set additional args or flags for the 'helm template' command:
chartsnap -c YOUR_CHART -f YOUR_TEST_VALUES_FILE -- --skip-tests

# Snapshot remote chart in Helm repository:
chartsnap -c CHART_NAME -f YOUR_VALUES_FILE -- --repo HELM_REPO_URL

# Snapshot ingress-nginx (https://kubernetes.github.io/ingress-nginx/) helm chart for a specific version with your value file:
chartsnap -c ingress-nginx -f YOUR_VALUES_FILE -- --repo https://kubernetes.github.io/ingress-nginx --namespace kube-system --version 4.8.3

# Snapshot cilium (https://cilium.io) helm chart with default value and set flags:
chartsnap -c cilium -- --repo https://helm.cilium.io --namespace kube-system --set hubble.relay.enabled=true --set hubble.ui.enabled=true

# Snapshot charts in OCI registry
chartsnap -c oci://ghcr.io/nginxinc/charts/nginx-gateway-fabric -n nginx-gateway

# Output with no colors:
NO_COLOR=1 chartsnap -c YOUR_CHART

Flags:
-c, --chart string path to the chart directory. this flag is passed to 'helm template RELEASE_NAME CHART --values VALUES' as 'CHART'
--config-file string config file name or path, which defines snapshot behavior e.g. dynamic fields (default \".chartsnap.yaml\")
-N, --ctx-lines int number of lines to show in diff output. 0 for full output (default 3)
--debug debug mode
--fail-helm-error fail if 'helm template' command failed
--failfast fail once any test case failed
-n, --namespace string namespace. this flag is passed to 'helm template RELEASE_NAME CHART --values VALUES --namespace NAMESPACE' as 'NAMESPACE' (default \"default\")
-o, --output-dir string directory which is __snapshot__ directory is created. (default: values file directory if --values is set; chart directory if chart is local; else current directory)
--parallelism int test concurrency if taking multiple snapshots for a test value file directory. default is unlimited (default -1)
--release-name string release name. this flag is passed to 'helm template RELEASE_NAME CHART --values VALUES' as 'RELEASE_NAME' (default \"chartsnap\")
--snapshot-version string use a specific snapshot format version. v1, v2, v3 are supported. (default: latest)
-u, --update-snapshot update snapshot mode
-f, --values string path to a test values file or directory. if the directory is set, all test files are tested. if empty, default values are used. this flag is passed to 'helm template RELEASE_NAME CHART --values VALUES' as 'VALUES'
"""

['rootCmd fail including dynamic outputs should fail 1']
SnapShot = 'snapshot does not match chart=example/app1 values='

Expand All @@ -7,6 +60,13 @@ SnapShot = 'unknown flag: --invalid'
['rootCmd fail required flag is not set should fail 1']
SnapShot = 'required flag(s) "chart" not set'

['rootCmd fail snapshot helm error with --fail-helm-error should fail 1']
SnapShot = """
failed to get snapshot chart=example/app3 values=: 'helm template' command failed: exit status 1: Error: execution error at (app3/templates/secret.yaml:8:13): apiKey is required

Use --debug flag to render out invalid YAML
"""

['rootCmd fail snapshot is different should fail 1']
SnapShot = 'snapshot does not match chart=example/app1 values=example/app1/testfail/test_ingress_enabled.yaml'

Expand Down
50 changes: 25 additions & 25 deletions coverage.out
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
github.com/jlandowner/helm-chartsnap/main.go:51: Debug 100.0%
github.com/jlandowner/helm-chartsnap/main.go:59: Namespace 75.0%
github.com/jlandowner/helm-chartsnap/main.go:67: HelmBin 75.0%
github.com/jlandowner/helm-chartsnap/main.go:75: OK 66.7%
github.com/jlandowner/helm-chartsnap/main.go:83: snapshotVersion 66.7%
github.com/jlandowner/helm-chartsnap/main.go:92: init 100.0%
github.com/jlandowner/helm-chartsnap/main.go:96: initRootCmd 84.6%
github.com/jlandowner/helm-chartsnap/main.go:195: main 0.0%
github.com/jlandowner/helm-chartsnap/main.go:202: slogHandler 100.0%
github.com/jlandowner/helm-chartsnap/main.go:213: loadSnapshotConfig 57.1%
github.com/jlandowner/helm-chartsnap/main.go:226: run 86.2%
github.com/jlandowner/helm-chartsnap/main.go:352: bannerPrintln 100.0%
github.com/jlandowner/helm-chartsnap/main.go:359: printOptions 100.0%
github.com/jlandowner/helm-chartsnap/main.go:52: Debug 100.0%
github.com/jlandowner/helm-chartsnap/main.go:60: Namespace 75.0%
github.com/jlandowner/helm-chartsnap/main.go:68: HelmBin 75.0%
github.com/jlandowner/helm-chartsnap/main.go:76: OK 66.7%
github.com/jlandowner/helm-chartsnap/main.go:84: snapshotVersion 66.7%
github.com/jlandowner/helm-chartsnap/main.go:93: init 100.0%
github.com/jlandowner/helm-chartsnap/main.go:97: initRootCmd 85.2%
github.com/jlandowner/helm-chartsnap/main.go:197: main 0.0%
github.com/jlandowner/helm-chartsnap/main.go:204: slogHandler 100.0%
github.com/jlandowner/helm-chartsnap/main.go:215: loadSnapshotConfig 57.1%
github.com/jlandowner/helm-chartsnap/main.go:228: run 89.2%
github.com/jlandowner/helm-chartsnap/main.go:355: bannerPrintln 100.0%
github.com/jlandowner/helm-chartsnap/main.go:362: printOptions 100.0%
github.com/jlandowner/helm-chartsnap/pkg/api/v1alpha1/header.go:13: ToString 100.0%
github.com/jlandowner/helm-chartsnap/pkg/api/v1alpha1/header.go:17: ParseHeader 100.0%
github.com/jlandowner/helm-chartsnap/pkg/api/v1alpha1/testspec.go:11: FromFile 100.0%
Expand All @@ -26,16 +26,16 @@ github.com/jlandowner/helm-chartsnap/pkg/charts/helm.go:19: Args 100.0%
github.com/jlandowner/helm-chartsnap/pkg/charts/helm.go:35: Execute 100.0%
github.com/jlandowner/helm-chartsnap/pkg/charts/snap.go:27: SetLogger 0.0%
github.com/jlandowner/helm-chartsnap/pkg/charts/snap.go:31: log 100.0%
github.com/jlandowner/helm-chartsnap/pkg/charts/snap.go:53: updateSnapshot 75.0%
github.com/jlandowner/helm-chartsnap/pkg/charts/snap.go:61: prependSnapshotHeader 100.0%
github.com/jlandowner/helm-chartsnap/pkg/charts/snap.go:67: getVersionFromSnapshotFile 66.7%
github.com/jlandowner/helm-chartsnap/pkg/charts/snap.go:77: Snap 74.3%
github.com/jlandowner/helm-chartsnap/pkg/charts/snap.go:143: snapV1 81.2%
github.com/jlandowner/helm-chartsnap/pkg/charts/snap.go:180: snapV2 82.4%
github.com/jlandowner/helm-chartsnap/pkg/charts/snap.go:214: snapV3 75.0%
github.com/jlandowner/helm-chartsnap/pkg/charts/snap.go:249: DefaultSnapshotFilePath 100.0%
github.com/jlandowner/helm-chartsnap/pkg/charts/snap.go:263: SnapshotFileName 100.0%
github.com/jlandowner/helm-chartsnap/pkg/charts/snap.go:271: SnapshotFilePath 100.0%
github.com/jlandowner/helm-chartsnap/pkg/charts/snap.go:54: updateSnapshot 75.0%
github.com/jlandowner/helm-chartsnap/pkg/charts/snap.go:62: prependSnapshotHeader 100.0%
github.com/jlandowner/helm-chartsnap/pkg/charts/snap.go:68: getVersionFromSnapshotFile 66.7%
github.com/jlandowner/helm-chartsnap/pkg/charts/snap.go:78: Snap 70.3%
github.com/jlandowner/helm-chartsnap/pkg/charts/snap.go:148: snapV1 81.2%
github.com/jlandowner/helm-chartsnap/pkg/charts/snap.go:185: snapV2 82.4%
github.com/jlandowner/helm-chartsnap/pkg/charts/snap.go:219: snapV3 75.0%
github.com/jlandowner/helm-chartsnap/pkg/charts/snap.go:254: DefaultSnapshotFilePath 100.0%
github.com/jlandowner/helm-chartsnap/pkg/charts/snap.go:268: SnapshotFileName 100.0%
github.com/jlandowner/helm-chartsnap/pkg/charts/snap.go:276: SnapshotFilePath 100.0%
github.com/jlandowner/helm-chartsnap/pkg/jsonpatch/jsonpatch.go:16: DecodePatchKey 100.0%
github.com/jlandowner/helm-chartsnap/pkg/jsonpatch/jsonpatch.go:20: SplitPathDecoded 100.0%
github.com/jlandowner/helm-chartsnap/pkg/snap/cachefs.go:21: WriteFile 70.0%
Expand Down Expand Up @@ -98,12 +98,12 @@ github.com/jlandowner/helm-chartsnap/pkg/yaml/diff.go:173: printHeader 100.0
github.com/jlandowner/helm-chartsnap/pkg/yaml/diff.go:177: findNextKind 80.0%
github.com/jlandowner/helm-chartsnap/pkg/yaml/diff.go:187: findNextName 87.5%
github.com/jlandowner/helm-chartsnap/pkg/yaml/yaml.go:19: SetLogger 100.0%
github.com/jlandowner/helm-chartsnap/pkg/yaml/yaml.go:23: log 66.7%
github.com/jlandowner/helm-chartsnap/pkg/yaml/yaml.go:23: log 100.0%
github.com/jlandowner/helm-chartsnap/pkg/yaml/yaml.go:30: Encode 100.0%
github.com/jlandowner/helm-chartsnap/pkg/yaml/yaml.go:37: Decode 80.0%
github.com/jlandowner/helm-chartsnap/pkg/yaml/yaml.go:54: decode 100.0%
github.com/jlandowner/helm-chartsnap/pkg/yaml/yaml.go:63: ApplyFixedValueToDynamicFieleds 87.5%
github.com/jlandowner/helm-chartsnap/pkg/yaml/yaml.go:81: convertInvalidYAMLToUnknown 100.0%
github.com/jlandowner/helm-chartsnap/pkg/yaml/yaml.go:97: convertScalerNodeToUnknownNode 100.0%
github.com/jlandowner/helm-chartsnap/pkg/yaml/yaml.go:112: Replace 100.0%
total: (statements) 86.4%
total: (statements) 86.6%
Loading
Loading