Skip to content

Commit 427b377

Browse files
committed
hack/tests: add test local --no-setup test
1 parent a279e10 commit 427b377

File tree

3 files changed

+51
-31
lines changed

3 files changed

+51
-31
lines changed

hack/lib/test_lib.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env bash
2+
13
function listPkgs() {
24
go list ./commands/... ./pkg/... ./test/... | grep -v generated
35
}
@@ -13,3 +15,34 @@ function listFiles() {
1315
# pipeline is much faster than for loop
1416
listPkgs | xargs -I {} find "${GOPATH}/src/{}" -name '*.go' | grep -v generated
1517
}
18+
19+
#===================================================================
20+
# FUNCTION trap_add ()
21+
#
22+
# Purpose: prepends a command to a trap
23+
#
24+
# - 1st arg: code to add
25+
# - remaining args: names of traps to modify
26+
#
27+
# Example: trap_add 'echo "in trap DEBUG"' DEBUG
28+
#
29+
# See: http://stackoverflow.com/questions/3338030/multiple-bash-traps-for-the-same-signal
30+
#===================================================================
31+
function trap_add() {
32+
trap_add_cmd=$1; shift || fatal "${FUNCNAME} usage error"
33+
new_cmd=
34+
for trap_add_name in "$@"; do
35+
# Grab the currently defined trap commands for this trap
36+
existing_cmd=`trap -p "${trap_add_name}" | awk -F"'" '{print $2}'`
37+
38+
# Define default command
39+
[ -z "${existing_cmd}" ] && existing_cmd="echo exiting @ `date`"
40+
41+
# Generate the new command
42+
new_cmd="${trap_add_cmd};${existing_cmd}"
43+
44+
# Assign the test
45+
trap "${new_cmd}" "${trap_add_name}" || \
46+
fatal "unable to add to trap ${trap_add_name}"
47+
done
48+
}

hack/tests/e2e-ansible.sh

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,6 @@
11
#!/usr/bin/env bash
22

3-
#===================================================================
4-
# FUNCTION trap_add ()
5-
#
6-
# Purpose: prepends a command to a trap
7-
#
8-
# - 1st arg: code to add
9-
# - remaining args: names of traps to modify
10-
#
11-
# Example: trap_add 'echo "in trap DEBUG"' DEBUG
12-
#
13-
# See: http://stackoverflow.com/questions/3338030/multiple-bash-traps-for-the-same-signal
14-
#===================================================================
15-
trap_add() {
16-
trap_add_cmd=$1; shift || fatal "${FUNCNAME} usage error"
17-
new_cmd=
18-
for trap_add_name in "$@"; do
19-
# Grab the currently defined trap commands for this trap
20-
existing_cmd=`trap -p "${trap_add_name}" | awk -F"'" '{print $2}'`
21-
22-
# Define default command
23-
[ -z "${existing_cmd}" ] && existing_cmd="echo exiting @ `date`"
24-
25-
# Generate the new command
26-
new_cmd="${trap_add_cmd};${existing_cmd}"
27-
28-
# Assign the test
29-
trap "${new_cmd}" "${trap_add_name}" || \
30-
fatal "unable to add to trap ${trap_add_name}"
31-
done
32-
}
3+
source hack/lib/test_lib.sh
334

345
DEST_IMAGE="quay.io/example/memcached-operator:v0.0.2"
356

hack/tests/test-subcommand.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
#!/usr/bin/env bash
2+
source hack/lib/test_lib.sh
3+
24
set -ex
35

4-
cd test/test-framework
6+
pushd test/test-framework
57
# test framework with defaults
68
operator-sdk test local .
79
# test operator-sdk test flags
810
operator-sdk test local . --global-manifest deploy/crds/cache_v1alpha1_memcached_crd.yaml --namespaced-manifest deploy/namespace-init.yaml --go-test-flags "-parallel 1" --kubeconfig $HOME/.kube/config
911
# test operator-sdk test local single namespace mode
1012
kubectl create namespace test-memcached
13+
# we use the test-memcached namespace for all future tests, so we only need to set this trap once
14+
trap_add 'kubectl delete namespace test-memcached' EXIT
1115
operator-sdk test local . --namespace=test-memcached
1216
kubectl delete namespace test-memcached
17+
# test operator in no-setup mode
18+
kubectl create namespace test-memcached
19+
kubectl create -f deploy/crds/cache_v1alpha1_memcached_crd.yaml
20+
# this runs after the popd at the end, so it needs the path from the project root
21+
trap_add 'kubectl delete -f test/test-framework/deploy/crds/cache_v1alpha1_memcached_crd.yaml' EXIT
22+
kubectl create -f deploy/service_account.yaml --namespace test-memcached
23+
kubectl create -f deploy/role.yaml --namespace test-memcached
24+
kubectl create -f deploy/role_binding.yaml --namespace test-memcached
25+
kubectl create -f deploy/operator.yaml --namespace test-memcached
26+
operator-sdk test local . --namespace=test-memcached --no-setup
27+
kubectl delete namespace test-memcached
28+
popd

0 commit comments

Comments
 (0)