diff --git a/test/e2e/atlas/atlas_e2e_test_generator_test.go b/test/e2e/atlas/atlas_e2e_test_generator_test.go index 130ebeffca..79fb0303dc 100644 --- a/test/e2e/atlas/atlas_e2e_test_generator_test.go +++ b/test/e2e/atlas/atlas_e2e_test_generator_test.go @@ -278,24 +278,30 @@ func deleteKeys(t *testing.T, cliPath string, toDelete map[string]struct{}) { var keys atlasv2.PaginatedApiApiUser err = json.Unmarshal(resp, &keys) require.NoError(t, err) + + uniqueKeysToDelete := make(map[string]struct{}) for _, key := range keys.GetResults() { keyID := key.GetId() desc := key.GetDesc() - errors := []error{} if _, ok := toDelete[desc]; ok { - t.Logf("Deleting key with ID: %s", keyID) - cmd = exec.Command(cliPath, - orgEntity, - "apiKeys", - "rm", - keyID, - "--force") - cmd.Env = os.Environ() - _, err = e2e.RunAndGetStdOut(cmd) - if err != nil { - errors = append(errors, err) - } + uniqueKeysToDelete[keyID] = struct{}{} + } + } + + for keyID := range uniqueKeysToDelete { + errors := []error{} + t.Logf("Deleting key with ID: %s", keyID) + cmd = exec.Command(cliPath, + orgEntity, + "apiKeys", + "rm", + keyID, + "--force") + cmd.Env = os.Environ() + _, err = e2e.RunAndGetStdOut(cmd) + if err != nil { + errors = append(errors, err) } if len(errors) > 0 { t.Errorf("unexpected errors while deleting keys: %v", errors)