github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/integration/kubernetes/k8s-attach-handlers.bats (about) 1 #!/usr/bin/env bats 2 # 3 # Copyright (c) 2018 Intel Corporation 4 # 5 # SPDX-License-Identifier: Apache-2.0 6 # 7 8 load "${BATS_TEST_DIRNAME}/../../.ci/lib.sh" 9 load "${BATS_TEST_DIRNAME}/tests_common.sh" 10 11 setup() { 12 nginx_version=$(get_test_version "docker_images.nginx.version") 13 nginx_image="nginx:$nginx_version" 14 15 export KUBECONFIG="${KUBECONFIG:-$HOME/.kube/config}" 16 pod_name="handlers" 17 18 get_pod_config_dir 19 } 20 21 @test "Running with postStart and preStop handlers" { 22 # Create yaml 23 sed -e "s/\${nginx_version}/${nginx_image}/" \ 24 "${pod_config_dir}/lifecycle-events.yaml" > "${pod_config_dir}/test-lifecycle-events.yaml" 25 26 # Create the pod with postStart and preStop handlers 27 kubectl create -f "${pod_config_dir}/test-lifecycle-events.yaml" 28 29 # Check pod creation 30 kubectl wait --for=condition=Ready --timeout=$timeout pod $pod_name 31 32 # Check postStart message 33 display_message="cat /usr/share/message" 34 check_postStart=$(kubectl exec $pod_name -- sh -c "$display_message" | grep "Hello from the postStart handler") 35 } 36 37 teardown(){ 38 # Debugging information 39 kubectl describe "pod/$pod_name" 40 41 rm -f "${pod_config_dir}/test-lifecycle-events.yaml" 42 kubectl delete pod "$pod_name" 43 }