reduce integration test noise

This commit is contained in:
Jeffrey Regan
2018-05-21 11:14:21 -07:00
parent 314e66a06c
commit eea598f667

View File

@@ -29,11 +29,15 @@
set -x set -x
function configureCluster { function configureCluster {
local tmpDir=$1
local target=$2
echo Kustomizing: \"$target\"
ls $target
kustomize build $target > $tmpDir/my.yaml kustomize build $target > $tmpDir/my.yaml
[[ $? -eq 0 ]] || { exitWith "Failed to kustomize build"; } [[ $? -eq 0 ]] || { exitWith "Failed to kustomize build"; }
cat $tmpDir/my.yaml
# Setting the namespace this way is a test-infra thing? # Setting the namespace this way is a test-infra thing?
kubectl config set-context \ kubectl config set-context \
$(kubectl config current-context) --namespace=default $(kubectl config current-context) --namespace=default
@@ -45,6 +49,7 @@ function configureCluster {
} }
function tearDownCluster { function tearDownCluster {
local tmpDir=$1
kubectl delete -f $tmpDir/my.yaml kubectl delete -f $tmpDir/my.yaml
rm -rf $tmpDir rm -rf $tmpDir
} }
@@ -58,22 +63,26 @@ function podExec {
} }
function addUser { function addUser {
local tmpDir=$1
local namespace=`getPodField '{.items[0].metadata.namespace}'` local namespace=`getPodField '{.items[0].metadata.namespace}'`
[[ -z $namespace ]] && { exitWith "Unable to get namespace"; } [[ -z $namespace ]] && { exitWith "Unable to get namespace"; }
# Create a user ldif file local myUserFile=$tmpDir/user.ldif
local userFile="user.ldif" local podUserFile=/tmp/user.ldif
cat <<EOF >$tmpDir/$userFile
cat <<EOF >$myUserFile
dn: cn=The Postmaster,dc=example,dc=org dn: cn=The Postmaster,dc=example,dc=org
objectClass: organizationalRole objectClass: organizationalRole
cn: The Postmaster cn: The Postmaster
EOF EOF
[[ -f $tmpDir/$userFile ]] || { exitWith "Failed to create $tmpDir/$userFile"; } [[ -f $myUserFile ]] || \
{ exitWith "Failed to create $myUserFile"; }
kubectl cp $tmpDir/$userFile $namespace/$podName:/tmp/$userFile || \ kubectl cp $myUserFile \
{ exitWith "Failed to copy ldif file to Pod $podName"; } $namespace/$podName:$podUserFile || \
{ exitWith "Failed to copy $myUserFile to pod $podName"; }
rm $tmpDir/$userFile rm $myUserFile
podExec \ podExec \
ldapadd \ ldapadd \
@@ -81,7 +90,7 @@ EOF
-w admin \ -w admin \
-H ldap://localhost \ -H ldap://localhost \
-D "cn=admin,dc=example,dc=org" \ -D "cn=admin,dc=example,dc=org" \
-f /tmp/$userFile -f $podUserFile
} }
function getUserCount { function getUserCount {
@@ -108,27 +117,20 @@ function deleteAddedUser {
"cn=The Postmaster,dc=example,dc=org" "cn=The Postmaster,dc=example,dc=org"
} }
target=$1
echo Kustomizing: \"$target\"
ls $target
tmpDir=$(mktemp -d) tmpDir=$(mktemp -d)
configureCluster configureCluster $tmpDir $1
podName=`getPodField '{.items[0].metadata.name}'` podName=`getPodField '{.items[0].metadata.name}'`
[[ -z $podName ]] && { exitWith "Unable to get pod name"; } [[ -z $podName ]] && { exitWith "Unable to get pod name"; }
echo pod is $podName
containerName="ldap" containerName="ldap"
getUserCount; [[ $? -eq 0 ]] || { exitWith "Expected no users."; } getUserCount; [[ $? -eq 0 ]] || { exitWith "Expected no users."; }
addUser || { exitWith "Failed to add a user"; } addUser $tmpDir || { exitWith "Failed to add a user"; }
getUserCount; [[ $? -eq 1 ]] || { exitWith "Couldn't find the new added user"; } getUserCount; [[ $? -eq 1 ]] || { exitWith "Couldn't find the new added user"; }
deleteAddedUser || { exitWith "Failed to delete the user"; } deleteAddedUser || { exitWith "Failed to delete the user"; }
getUserCount; [[ $? -eq 0 ]] || { exitWith "User has not been deleted."; } getUserCount; [[ $? -eq 0 ]] || { exitWith "User has not been deleted."; }
tearDownCluster tearDownCluster $tmpDir