From e514e215e0f96a09d2a2c9a5fbc1e9d3036a6897 Mon Sep 17 00:00:00 2001 From: Michael Christenson II Date: Tue, 5 Dec 2023 10:15:38 -0500 Subject: [PATCH] Use Batch deletion for integration test cleanup --- test/integration/scripts/test-cleanup.sh | 157 ++++------------------- 1 file changed, 25 insertions(+), 132 deletions(-) diff --git a/test/integration/scripts/test-cleanup.sh b/test/integration/scripts/test-cleanup.sh index da5a09913..e080e04c4 100755 --- a/test/integration/scripts/test-cleanup.sh +++ b/test/integration/scripts/test-cleanup.sh @@ -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