Replace os.exit in diff

This commit is contained in:
petya.slavcheva1 2022-12-13 14:27:35 +01:00
parent f892ab1bd7
commit 2dce194e16
2 changed files with 4 additions and 2 deletions

View File

@ -147,7 +147,7 @@ func NewCmdDiff(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.C
// return 1 if there was a problem. // return 1 if there was a problem.
if err := options.Run(); err != nil { if err := options.Run(); err != nil {
if exitErr := diffError(err); exitErr != nil { if exitErr := diffError(err); exitErr != nil {
os.Exit(exitErr.ExitStatus()) cmdutil.CheckErr(cmdutil.ErrExit)
} }
cmdutil.CheckDiffErr(err) cmdutil.CheckDiffErr(err)
} }

View File

@ -46,8 +46,10 @@ run_kubectl_diff_tests() {
# Make sure that: # Make sure that:
# 1. the exit code for diff is 1 because it found a difference # 1. the exit code for diff is 1 because it found a difference
# 2. the difference contains the changed image # 2. the difference contains the changed image
output_message=$(kubectl diff -f hack/testdata/pod-changed.yaml || test $? -eq 1) # 3. the output doesn't indicate this is an error
output_message=$(kubectl diff -f hack/testdata/pod-changed.yaml 2>&1 || test $? -eq 1)
kube::test::if_has_string "${output_message}" 'registry.k8s.io/pause:3.4' kube::test::if_has_string "${output_message}" 'registry.k8s.io/pause:3.4'
kube::test::if_has_not_string "${output_message}" 'exit status 1'
# Ensure diff only dry-runs and doesn't persist change # Ensure diff only dry-runs and doesn't persist change
resourceVersion=$(kubectl get "${kube_flags[@]:?}" -f hack/testdata/pod.yaml -o go-template='{{ .metadata.resourceVersion }}') resourceVersion=$(kubectl get "${kube_flags[@]:?}" -f hack/testdata/pod.yaml -o go-template='{{ .metadata.resourceVersion }}')