mirror of https://github.com/coder/coder.git
chore: fix flake in create-admin-user test (#6103)
This commit is contained in:
parent
3da33d23a4
commit
b5e5959649
|
@ -86,14 +86,17 @@ func TestServerCreateAdminUser(t *testing.T) {
|
|||
connectionURL, closeFunc, err := postgres.Open()
|
||||
require.NoError(t, err)
|
||||
defer closeFunc()
|
||||
ctx, cancelFunc := context.WithCancel(context.Background())
|
||||
defer cancelFunc()
|
||||
|
||||
sqlDB, err := sql.Open("postgres", connectionURL)
|
||||
require.NoError(t, err)
|
||||
defer sqlDB.Close()
|
||||
db := database.New(sqlDB)
|
||||
|
||||
// Sometimes generating SSH keys takes a really long time if there isn't
|
||||
// enough entropy. We don't want the tests to fail in these cases.
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitSuperLong)
|
||||
defer cancel()
|
||||
|
||||
pingCtx, pingCancel := context.WithTimeout(ctx, testutil.WaitShort)
|
||||
defer pingCancel()
|
||||
_, err = db.Ping(pingCtx)
|
||||
|
@ -135,14 +138,14 @@ func TestServerCreateAdminUser(t *testing.T) {
|
|||
errC <- err
|
||||
}()
|
||||
|
||||
pty.ExpectMatch("Creating user...")
|
||||
pty.ExpectMatch("Generating user SSH key...")
|
||||
pty.ExpectMatch(fmt.Sprintf("Adding user to organization %q (%s) as admin...", org1Name, org1ID.String()))
|
||||
pty.ExpectMatch(fmt.Sprintf("Adding user to organization %q (%s) as admin...", org2Name, org2ID.String()))
|
||||
pty.ExpectMatch("User created successfully.")
|
||||
pty.ExpectMatch(username)
|
||||
pty.ExpectMatch(email)
|
||||
pty.ExpectMatch("****")
|
||||
pty.ExpectMatchContext(ctx, "Creating user...")
|
||||
pty.ExpectMatchContext(ctx, "Generating user SSH key...")
|
||||
pty.ExpectMatchContext(ctx, fmt.Sprintf("Adding user to organization %q (%s) as admin...", org1Name, org1ID.String()))
|
||||
pty.ExpectMatchContext(ctx, fmt.Sprintf("Adding user to organization %q (%s) as admin...", org2Name, org2ID.String()))
|
||||
pty.ExpectMatchContext(ctx, "User created successfully.")
|
||||
pty.ExpectMatchContext(ctx, username)
|
||||
pty.ExpectMatchContext(ctx, email)
|
||||
pty.ExpectMatchContext(ctx, "****")
|
||||
|
||||
require.NoError(t, <-errC)
|
||||
|
||||
|
@ -158,11 +161,14 @@ func TestServerCreateAdminUser(t *testing.T) {
|
|||
connectionURL, closeFunc, err := postgres.Open()
|
||||
require.NoError(t, err)
|
||||
defer closeFunc()
|
||||
ctx, cancelFunc := context.WithCancel(context.Background())
|
||||
defer cancelFunc()
|
||||
|
||||
// Sometimes generating SSH keys takes a really long time if there isn't
|
||||
// enough entropy. We don't want the tests to fail in these cases.
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitSuperLong)
|
||||
defer cancel()
|
||||
|
||||
t.Setenv("CODER_POSTGRES_URL", connectionURL)
|
||||
t.Setenv("CODER_SSH_KEYGEN_ALGORITHM", "ecdsa")
|
||||
t.Setenv("CODER_SSH_KEYGEN_ALGORITHM", "ed25519")
|
||||
t.Setenv("CODER_USERNAME", username)
|
||||
t.Setenv("CODER_EMAIL", email)
|
||||
t.Setenv("CODER_PASSWORD", password)
|
||||
|
@ -178,10 +184,10 @@ func TestServerCreateAdminUser(t *testing.T) {
|
|||
errC <- err
|
||||
}()
|
||||
|
||||
pty.ExpectMatch("User created successfully.")
|
||||
pty.ExpectMatch(username)
|
||||
pty.ExpectMatch(email)
|
||||
pty.ExpectMatch("****")
|
||||
pty.ExpectMatchContext(ctx, "User created successfully.")
|
||||
pty.ExpectMatchContext(ctx, username)
|
||||
pty.ExpectMatchContext(ctx, email)
|
||||
pty.ExpectMatchContext(ctx, "****")
|
||||
|
||||
require.NoError(t, <-errC)
|
||||
|
||||
|
@ -198,13 +204,16 @@ func TestServerCreateAdminUser(t *testing.T) {
|
|||
connectionURL, closeFunc, err := postgres.Open()
|
||||
require.NoError(t, err)
|
||||
defer closeFunc()
|
||||
ctx, cancelFunc := context.WithCancel(context.Background())
|
||||
defer cancelFunc()
|
||||
|
||||
// Sometimes generating SSH keys takes a really long time if there isn't
|
||||
// enough entropy. We don't want the tests to fail in these cases.
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitSuperLong)
|
||||
defer cancel()
|
||||
|
||||
root, _ := clitest.New(t,
|
||||
"server", "create-admin-user",
|
||||
"--postgres-url", connectionURL,
|
||||
"--ssh-keygen-algorithm", "rsa4096",
|
||||
"--ssh-keygen-algorithm", "ed25519",
|
||||
)
|
||||
pty := ptytest.New(t)
|
||||
root.SetIn(pty.Input())
|
||||
|
@ -217,19 +226,19 @@ func TestServerCreateAdminUser(t *testing.T) {
|
|||
errC <- err
|
||||
}()
|
||||
|
||||
pty.ExpectMatch("> Username")
|
||||
pty.ExpectMatchContext(ctx, "> Username")
|
||||
pty.WriteLine(username)
|
||||
pty.ExpectMatch("> Email")
|
||||
pty.ExpectMatchContext(ctx, "> Email")
|
||||
pty.WriteLine(email)
|
||||
pty.ExpectMatch("> Password")
|
||||
pty.ExpectMatchContext(ctx, "> Password")
|
||||
pty.WriteLine(password)
|
||||
pty.ExpectMatch("> Confirm password")
|
||||
pty.ExpectMatchContext(ctx, "> Confirm password")
|
||||
pty.WriteLine(password)
|
||||
|
||||
pty.ExpectMatch("User created successfully.")
|
||||
pty.ExpectMatch(username)
|
||||
pty.ExpectMatch(email)
|
||||
pty.ExpectMatch("****")
|
||||
pty.ExpectMatchContext(ctx, "User created successfully.")
|
||||
pty.ExpectMatchContext(ctx, username)
|
||||
pty.ExpectMatchContext(ctx, email)
|
||||
pty.ExpectMatchContext(ctx, "****")
|
||||
|
||||
require.NoError(t, <-errC)
|
||||
|
||||
|
|
Loading…
Reference in New Issue