Skip to content

Commit

Permalink
Use Batch deletion for integration test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Christenson II committed Dec 5, 2023
1 parent 16d0d6b commit e514e21
Showing 1 changed file with 25 additions and 132 deletions.
157 changes: 25 additions & 132 deletions test/integration/scripts/test-cleanup.sh
Original file line number Diff line number Diff line change
@@ -1,142 +1,35 @@
#! /bin/bash

apps=$( auth0 apps list --json --no-input )
function delete_resources {
local cmd=${1-} name=${2-} field=${3-}

for app in $( echo "${apps}" | jq -r '.[] | @base64' ); do
_jq() {
echo "${app}" | base64 --decode | jq -r "${1}"
}
printf "\r\nGathering resource %ss for %s...\r\n" ${field} ${cmd}
resources=$( auth0 ${cmd} list --json --no-input | jq -r ".[] | select(.name | test(\"^${name}.+\")) | .${field}" | tr '\n' ' ' )

clientid=$(_jq '.client_id')
name=$(_jq '.name')
# TODO(jfatta): should remove only those
# created during the same test session
if [[ $name = integration-test-app-* ]]
then
echo deleting "$name"
$( auth0 apps delete "$clientid")
fi
done
if [[ $resources ]]
then
echo "Deleting resources for ${cmd}... ${field} (e.g. IDs): ${resources}"
auth0 ${cmd} delete --force ${resources[*]}
fi
}

apis=$( auth0 apis list --json --no-input )

for api in $( echo "${apis}" | jq -r '.[] | @base64' ); do
_jq() {
echo "${api}" | base64 --decode | jq -r "${1}"
}

id=$(_jq '.id')
name=$(_jq '.name')
# TODO(jfatta): should remove only those
# created during the same test session
if [[ $name = integration-test-api-* ]]
then
echo deleting "$name"
$( auth0 apis delete "$id")
fi
done
delete_resources "apps" "integration-test-app" "client_id"
delete_resources "apis" "integration-test-api" "id"

print "\r\nGathering resource user_ids for users...\r\n"
# using the search command since users have no list command
users=$( auth0 users search -q "*" --json --no-input )

for user in $( echo "${users}" | jq -r '.[] | @base64' ); do
_jq() {
echo "${user}" | base64 --decode | jq -r "${1}"
}

userid=$(_jq '.user_id')
# created during the same test session
if [[ integration-* ]]
then
echo deleting "$userid"
$( auth0 users delete "$userid")
fi
done

roles=$( auth0 roles list --json --no-input )

for role in $( echo "${roles}" | jq -r '.[] | @base64' ); do
_jq() {
echo "${role}" | base64 --decode | jq -r "${1}"
}

id=$(_jq '.id')
name=$(_jq '.name')
# TODO(jfatta): should remove only those
# created during the same test session
if [[ $name = integration-test-role-* ]]
then
echo deleting "$name"
$( auth0 roles delete "$id")
fi
done

rules=$( auth0 rules list --json --no-input )

for rule in $( printf "%s" "$rules" | jq -r '.[] | @base64' ); do
_jq() {
echo "${rule}" | base64 --decode | jq -r "${1}"
}

id=$(_jq '.id')
name=$(_jq '.name')
# TODO(jfatta): should remove only those
# created during the same test session
if [[ $name = integration-test-rule-* ]]
then
echo deleting "$name"
$( auth0 rules delete "$id")
fi
done

orgs=$( auth0 orgs list --json --no-input )

for org in $( echo "${orgs}" | jq -r '.[] | @base64' ); do
_jq() {
echo "${org}" | base64 --decode | jq -r "${1}"
}

id=$(_jq '.id')
name=$(_jq '.name')
if [[ $name = integration-test-org-* ]]
then
echo deleting "$name"
$( auth0 orgs delete "$id")
fi
done

actions=$( auth0 actions list --json --no-input )

for action in $( echo "${actions}" | jq -r '.[] | @base64' ); do
_jq() {
echo "${action}" | base64 --decode | jq -r "${1}"
}

id=$(_jq '.id')
name=$(_jq '.name')

if [[ $name = integration-test-* ]]
then
echo deleting "$name"
$( auth0 actions delete "$id")
fi
done

logStreams=$( auth0 logs streams list --json )
for logStream in $( echo "${logStreams}" | jq -r '.[] | @base64' ); do
_jq() {
echo "${logStream}" | base64 --decode | jq -r "${1}"
}

id=$(_jq '.id')
name=$(_jq '.name')

if [[ $name = integration-test-* ]]
then
echo deleting "$name"
$( auth0 logs streams delete "$id")
fi
done
users=$( auth0 users search -q "*" --json --no-input | jq -r '.[] | select(.name | test("^integration-.+")) | .user_id' | tr '\n' ' ' )
if [[ $users ]]
then
echo "Deleting resources for users... id (e.g. IDs): ${users}"
auth0 users delete --force ${users[*]}
fi

delete_resources "roles" "integration-test-role" "id"
delete_resources "rules" "integration-test-rule" "id"
delete_resources "orgs" "integration-test-org" "id"
delete_resources "actions" "integration-test-" "id"
delete_resources "logs streams" "integration-test-" "id"

auth0 domains delete $(./test/integration/scripts/get-custom-domain-id.sh) --no-input

Expand Down

0 comments on commit e514e21

Please sign in to comment.