kubectl-diff: Test return code on failure and changes

This commit is contained in:
Antoine Pelisse 2020-01-21 14:31:47 -08:00
parent f2b21f08d9
commit 38c5f318c9
2 changed files with 18 additions and 1 deletions

8
hack/testdata/invalid-pod.yaml vendored Normal file
View File

@ -0,0 +1,8 @@
apiVersion: v1
kind: Pod
metadata:
name: test
spec:
containers:
- name:
image: nginx

View File

@ -32,9 +32,18 @@ run_kubectl_diff_tests() {
kubectl apply -f hack/testdata/pod.yaml
output_message=$(! kubectl diff -f hack/testdata/pod-changed.yaml)
# Make sure that diffing the resource right after returns nothing (0 exit code).
kubectl diff -f hack/testdata/pod.yaml
# Make sure that:
# 1. the exit code for diff is 1 because it found a difference
# 2. the difference contains the changed image
output_message=$(kubectl diff -f hack/testdata/pod-changed.yaml || test $? -eq 1)
kube::test::if_has_string "${output_message}" 'k8s.gcr.io/pause:3.0'
# Test that we have a return code bigger than 1 if there is an error when diffing
kubectl diff -f hack/testdata/invalid-pod.yaml || test $? -gt 1
kubectl delete -f hack/testdata/pod.yaml
set +o nounset