sigs.k8s.io/kubebuilder/v3@v3.14.0/test/integration.sh (about) 1 #!/usr/bin/env bash 2 3 # Copyright 2018 The Kubernetes Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 source $(dirname "$0")/common.sh 18 19 header_text "Running kubebuilder integration tests" 20 21 build_kb 22 fetch_tools 23 24 pushd . 25 26 kb_test_dir=$kb_root_dir/test 27 kb_test_cache_dir=$kb_root_dir/cache 28 29 function prepare_test_dir { 30 header_text "Preparing test directory $kb_test_dir" 31 rm -rf "$kb_test_dir" && mkdir -p "$kb_test_dir" && cd "$kb_test_dir" 32 header_text "Running kubebuilder commands in test directory $kb_test_dir" 33 } 34 35 function cache_project { 36 header_text "Caching project '$1'" 37 if [ -d "$kb_test_cache_dir/$1" ]; then 38 rm -rf "$kb_test_cache_dir/$1" 39 fi 40 mkdir -p "$kb_test_cache_dir/$1" 41 cp -r $PWD/* $kb_test_cache_dir/$1 42 } 43 44 function dump_project { 45 header_text "Restoring cached project '$1'" 46 if [ -d "$kb_test_cache_dir/$1" ]; then 47 cp -r $kb_test_cache_dir/$1/* . 48 fi 49 } 50 51 52 function test_init_project { 53 header_text "Init project" 54 go mod init kubebuilder.io/test 55 $kb init --domain example.com <<< "n" 56 } 57 58 function test_make_project { 59 header_text "Running make" 60 make 61 } 62 63 function test_create_api_controller { 64 header_text "Creating api and controller" 65 $kb create api --group insect --version v1beta1 --kind Bee --namespaced false <<EOF 66 y 67 y 68 EOF 69 } 70 71 function test_create_namespaced_api_controller { 72 header_text "Creating namespaced api and controller" 73 $kb create api --group insect --version v1beta1 --kind Bee --namespaced true <<EOF 74 y 75 y 76 EOF 77 } 78 79 function test_create_api_only { 80 header_text "Creating api only" 81 $kb create api --group insect --version v1beta1 --kind Bee --namespaced false <<EOF 82 y 83 n 84 EOF 85 } 86 87 function test_create_namespaced_api_only { 88 header_text "Creating namespaced api only" 89 $kb create api --group insect --version v1beta1 --kind Bee --namespaced true <<EOF 90 y 91 n 92 EOF 93 } 94 95 function test_create_core_type_controller { 96 header_text "Creating coretype controller" 97 $kb create api --group apps --version v1 --kind Deployment --namespaced false <<EOF 98 n 99 y 100 EOF 101 } 102 103 prepare_test_dir 104 test_init_project 105 cache_project "init" 106 test_make_project 107 108 prepare_test_dir 109 dump_project "init" 110 test_create_api_controller 111 112 prepare_test_dir 113 dump_project "init" 114 test_create_namespaced_api_controller 115 116 prepare_test_dir 117 dump_project "init" 118 test_create_api_only 119 120 prepare_test_dir 121 dump_project "init" 122 test_create_namespaced_api_only 123 124 prepare_test_dir 125 dump_project "init" 126 test_create_core_type_controller 127 128 popd