test(e2e): Clean up user if test fails (#3180)

This commit is contained in:
Michael Li authored and GitHub committed 2023-04-25 09:47:08 -04:00
1 parent 33f3a5ff9c
commit cecc959a94
1 file changed
+13
@@ -18,6 +18,8 @@ import (
// TestCliSessionEndWhenUserIsDeleted tests that an active session is canceled when the respective
// user who started the session is deleted.
func TestCliSessionEndWhenUserIsDeleted(t *testing.T) {
userIsDeleted := false
e2e.MaybeSkipTest(t)
c, err := loadConfig()
require.NoError(t, err)
@@ -50,6 +52,16 @@ func TestCliSessionEndWhenUserIsDeleted(t *testing.T) {
require.NoError(t, output.Err, string(output.Stderr))
})
newUserId := boundary.CreateNewUserCli(t, ctx, "global")
t.Cleanup(func() {
if !userIsDeleted {
t.Log("Deleting user...")
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("users", "delete", "-id", newUserId),
)
require.NoError(t, output.Err, string(output.Stderr))
}
})
boundary.SetAccountToUserCli(t, ctx, newUserId, newAccountId)
newRoleId := boundary.CreateNewRoleCli(t, ctx, newProjectId)
boundary.AddGrantToRoleCli(t, ctx, newRoleId, "id=*;type=target;actions=authorize-session")
@@ -89,6 +101,7 @@ func TestCliSessionEndWhenUserIsDeleted(t *testing.T) {
t.Log("Deleting user...")
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("users", "delete", "-id", newUserId))
require.NoError(t, output.Err, string(output.Stderr))
userIsDeleted = true
// Check if session has terminated
t.Log("Waiting for session to be canceling/terminated...")