mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-10-30 21:30:16 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			69 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			69 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
| #!/usr/bin/env bash
 | |
| 
 | |
| # Copyright 2018 The Kubernetes Authors.
 | |
| #
 | |
| # Licensed under the Apache License, Version 2.0 (the "License");
 | |
| # you may not use this file except in compliance with the License.
 | |
| # You may obtain a copy of the License at
 | |
| #
 | |
| #     http://www.apache.org/licenses/LICENSE-2.0
 | |
| #
 | |
| # Unless required by applicable law or agreed to in writing, software
 | |
| # distributed under the License is distributed on an "AS IS" BASIS,
 | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | |
| # See the License for the specific language governing permissions and
 | |
| # limitations under the License.
 | |
| 
 | |
| set -o errexit
 | |
| set -o nounset
 | |
| set -o pipefail
 | |
| 
 | |
| # Runs tests for kubectl diff
 | |
| run_kubectl_diff_tests() {
 | |
|     set -o nounset
 | |
|     set -o errexit
 | |
| 
 | |
|     create_and_use_new_namespace
 | |
|     kube::log::status "Testing kubectl diff"
 | |
| 
 | |
|     # Test that it works when the live object doesn't exist
 | |
|     output_message=$(! kubectl diff -f hack/testdata/pod.yaml)
 | |
|     kube::test::if_has_string "${output_message}" 'test-pod'
 | |
| 
 | |
|     kubectl apply -f hack/testdata/pod.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
 | |
|     set +o errexit
 | |
| }
 | |
| 
 | |
| run_kubectl_diff_same_names() {
 | |
|     set -o nounset
 | |
|     set -o errexit
 | |
| 
 | |
|     create_and_use_new_namespace
 | |
|     kube::log::status "Test kubectl diff with multiple resources with the same name"
 | |
| 
 | |
|     output_message=$(KUBECTL_EXTERNAL_DIFF="find" kubectl diff -Rf hack/testdata/diff/)
 | |
|     kube::test::if_has_string "${output_message}" 'v1\.Pod\..*\.test'
 | |
|     kube::test::if_has_string "${output_message}" 'apps\.v1\.Deployment\..*\.test'
 | |
|     kube::test::if_has_string "${output_message}" 'v1\.ConfigMap\..*\.test'
 | |
|     kube::test::if_has_string "${output_message}" 'v1\.Secret\..*\.test'
 | |
| 
 | |
|     set +o nounset
 | |
|     set +o errexit
 | |
| }
 |