Skip to content

Commit 57f587f

Browse files
committed
tests: Further improve ad server test
- create a common.sh file with settings - create a test-remove-ad-server.sh script to be able to separately remove Signed-off-by: Michael Adam <[email protected]>
1 parent 13647e4 commit 57f587f

File tree

4 files changed

+37
-24
lines changed

4 files changed

+37
-24
lines changed

tests/common.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)"
4+
BASE_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
5+
6+
AD_DEPLOYMENT_YAML="${SCRIPT_DIR}/files/samba-ad-server-deployment.yml"
7+
AD_DEPLOYMENT_NAME="samba-ad-server"
8+
9+
KEEP=${KEEP:-0}
10+
11+
_error() {
12+
echo "$@"
13+
exit 1
14+
}

tests/test-deploy-ad-server.sh

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
#!/usr/bin/env bash
22

3-
43
SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)"
5-
BASE_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
6-
DEPLOYMENT_YAML="${BASE_DIR}/tests/files/samba-ad-server-deployment.yml"
7-
DEPLOYMENT_NAME="samba-ad-server"
84

9-
_error() {
10-
echo "$@"
11-
exit 1
12-
}
5+
source "${SCRIPT_DIR}/common.sh"
136

147
echo "Creating ad server deployment..."
15-
ERROR_MSG=$(kubectl create -f "${DEPLOYMENT_YAML}" 2>&1 1>/dev/null)
8+
ERROR_MSG=$(kubectl create -f "${AD_DEPLOYMENT_YAML}" 2>&1 1>/dev/null)
169
if [ $? -ne 0 ] ; then
1710
if [[ "${ERROR_MSG}" =~ "AlreadyExists" ]] ; then
1811
echo "Deployment exists already. Continuing."
@@ -23,7 +16,7 @@ fi
2316

2417
kubectl get deployment
2518

26-
replicaset="$(kubectl describe deployment ${DEPLOYMENT_NAME} | grep -s "NewReplicaSet:" | awk '{ print $2 }')"
19+
replicaset="$(kubectl describe deployment ${AD_DEPLOYMENT_NAME} | grep -s "NewReplicaSet:" | awk '{ print $2 }')"
2720
[ $? -eq 0 ] || _error "Error getting replicaset"
2821

2922
podname="$(kubectl get pod | grep $replicaset | awk '{ print $1 }')"

tests/test-remove-ad-server.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)"
4+
5+
source "${SCRIPT_DIR}/common.sh"
6+
7+
if [ ${KEEP} -eq 1 ]; then
8+
echo "keeping ad server deployment (KEEP=1)"
9+
exit 0
10+
fi
11+
12+
echo "removing ad server deployment..."
13+
kubectl delete deployment "${AD_DEPLOYMENT_NAME}"
14+
[ $? -eq 0 ] || _error "Error deleting deployment"
15+
echo
16+
echo "ad server deployment removed"
Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
11
#!/usr/bin/env bash
22

33
SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)"
4-
BASE_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
5-
DEPLOYMENT_YAML="${BASE_DIR}/tests/files/samba-ad-server-deployment.yml"
6-
DEPLOYMENT_NAME="samba-ad-server"
74

8-
_error() {
9-
echo "$@"
10-
exit 1
11-
}
5+
source "${SCRIPT_DIR}/common.sh"
126

13-
. ${BASE_DIR}/tests/test-deploy-ad-server.sh
7+
source ${SCRIPT_DIR}/test-deploy-ad-server.sh
148

159
kubectl exec "${podname}" -- samba-tool domain info 127.0.0.1
1610
[ $? -eq 0 ] || _error "Error listing domain info"
1711
echo
1812

19-
if [ ${KEEP} -eq 0 ]; then
20-
echo "removing ad server deployment again..."
21-
kubectl delete deployment "samba-ad-server"
22-
[ $? -eq 0 ] || _error "Error deleting deployment"
23-
echo
24-
fi
13+
source ${SCRIPT_DIR}/test-remove-ad-server.sh
2514

15+
echo
2616
echo "Success"
2717
exit 0

0 commit comments

Comments
 (0)