Skip to content

Commit 0133d14

Browse files
authored
Merge pull request kubernetes#72939 from runyontr/test-cmd-what
Test cmd what
2 parents 8993fbc + d4df887 commit 0133d14

File tree

6 files changed

+75
-23
lines changed

6 files changed

+75
-23
lines changed

build/root/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ test-cmd:
291291
@echo "$$TEST_CMD_HELP_INFO"
292292
else
293293
test-cmd: generated_files
294-
hack/make-rules/test-kubeadm-cmd.sh
295294
hack/make-rules/test-cmd.sh
296295
endif
297296

hack/.shellcheck_failures

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
./hack/make-rules/test-cmd.sh
6969
./hack/make-rules/test-e2e-node.sh
7070
./hack/make-rules/test-integration.sh
71-
./hack/make-rules/test-kubeadm-cmd.sh
7271
./hack/make-rules/test.sh
7372
./hack/make-rules/update.sh
7473
./hack/make-rules/verify.sh

hack/make-rules/BUILD

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,6 @@ sh_binary(
4141
],
4242
)
4343

44-
sh_binary(
45-
name = "test-kubeadm-cmd",
46-
srcs = ["test-kubeadm-cmd.sh"],
47-
deps = [
48-
"//hack/lib",
49-
],
50-
)
51-
5244
sh_binary(
5345
name = "build",
5446
srcs = ["build.sh"],

test/cmd/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Kubernetes Command-Line Integration Test Suite
2+
3+
This document describes how you can use the Kubernetes command-line integration test-suite.
4+
5+
## Running Tests
6+
7+
### All Tests
8+
9+
To run this entire suite, execute `make test-cmd` from the top level. This will import each file containing tests functions
10+
11+
### Specific Tests
12+
13+
To run a subset of tests (e.g. `run_deployment_test` and `run_impersonation_test`), execute `make test-cmd WHAT="deployment impersonation"`. Running specific
14+
tests will not try and validate any required resources are available on the server.
15+
16+
## Adding Tests
17+
18+
Test functions need to have the format `run_*_test` so they can executed individually. Once a test has been added, insert a section in `legacy-script.sh` like
19+
20+
```bash
21+
######################
22+
# Replica Sets #
23+
######################
24+
25+
if kube::test::if_supports_resource "${replicasets}" ; then
26+
record_command run_rs_tests
27+
fi
28+
```
29+
30+
Be sure to validate any supported resouces required for the test by using the `kube::test::if_supports_resource` function.
31+
32+
33+
### New File
34+
35+
If the test resides in a new file, source the file in the top of the `legacy-script.sh` file by adding a new line in
36+
```bash
37+
source "${KUBE_ROOT}/test/cmd/apply.sh"
38+
source "${KUBE_ROOT}/test/cmd/apps.sh"
39+
source "${KUBE_ROOT}/test/cmd/authorization.sh"
40+
source "${KUBE_ROOT}/test/cmd/batch.sh"
41+
...
42+
```
43+
44+
Please keep the order of the source list alphabetical.

hack/make-rules/test-kubeadm-cmd.sh renamed to test/cmd/kubeadm.sh

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@ set -o errexit
1818
set -o nounset
1919
set -o pipefail
2020

21-
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
22-
source "${KUBE_ROOT}/hack/lib/init.sh"
21+
run_kubeadm_tests() {
22+
set -o nounset
23+
set -o errexit
2324

24-
KUBEADM_PATH="${KUBEADM_PATH:=$(kube::realpath "${KUBE_ROOT}")/cluster/kubeadm.sh}"
25+
KUBEADM_PATH="${KUBEADM_PATH:=$(kube::realpath "${KUBE_ROOT}")/cluster/kubeadm.sh}"
2526

26-
# If testing a different version of kubeadm than the current build, you can
27-
# comment this out to save yourself from needlessly building here.
28-
make -C "${KUBE_ROOT}" WHAT=cmd/kubeadm
27+
# If testing a different version of kubeadm than the current build, you can
28+
# comment this out to save yourself from needlessly building here.
29+
make -C "${KUBE_ROOT}" WHAT=cmd/kubeadm
2930

30-
make -C "${KUBE_ROOT}" test \
31+
make -C "${KUBE_ROOT}" test \
3132
WHAT=k8s.io/kubernetes/cmd/kubeadm/test/cmd \
3233
KUBE_TEST_ARGS="--kubeadm-path '${KUBEADM_PATH}'"
34+
set +o nounset
35+
set +o errexit
36+
}

test/cmd/legacy-script.sh

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ source "${KUBE_ROOT}/test/cmd/diff.sh"
4040
source "${KUBE_ROOT}/test/cmd/discovery.sh"
4141
source "${KUBE_ROOT}/test/cmd/generic-resources.sh"
4242
source "${KUBE_ROOT}/test/cmd/get.sh"
43+
source "${KUBE_ROOT}/test/cmd/kubeadm.sh"
4344
source "${KUBE_ROOT}/test/cmd/kubeconfig.sh"
4445
source "${KUBE_ROOT}/test/cmd/node-management.sh"
4546
source "${KUBE_ROOT}/test/cmd/old-print.sh"
@@ -385,6 +386,23 @@ runTests() {
385386
kubectl get "${kube_flags[@]}" -f hack/testdata/kubernetes-service.yaml
386387
fi
387388

389+
cleanup_tests(){
390+
kube::test::clear_all
391+
if [[ -n "${foundError}" ]]; then
392+
echo "FAILED TESTS: ""${foundError}"
393+
exit 1
394+
fi
395+
}
396+
397+
if [[ -n "${WHAT-}" ]]; then
398+
for pkg in ${WHAT}
399+
do
400+
record_command run_${pkg}_tests
401+
done
402+
cleanup_tests
403+
return
404+
fi
405+
388406
#########################
389407
# Kubectl version #
390408
#########################
@@ -836,6 +854,7 @@ runTests() {
836854

837855
record_command run_plugins_tests
838856

857+
839858
#################
840859
# Impersonation #
841860
#################
@@ -847,10 +866,5 @@ runTests() {
847866

848867
record_command run_wait_tests
849868

850-
kube::test::clear_all
851-
852-
if [[ -n "${foundError}" ]]; then
853-
echo "FAILED TESTS: ""${foundError}"
854-
exit 1
855-
fi
869+
cleanup_tests
856870
}

0 commit comments

Comments
 (0)