Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix data race
  • Loading branch information
mafredri committed Feb 8, 2023
commit 41178ed74d549f3b665d6340d8d6bf9994e3d89d
44 changes: 19 additions & 25 deletions cli/server_createadminuser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -135,11 +138,6 @@ func TestServerCreateAdminUser(t *testing.T) {
errC <- err
}()

// 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(ctx, testutil.WaitSuperLong)
defer cancel()

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()))
Expand All @@ -163,8 +161,11 @@ 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", "ed25519")
Expand All @@ -183,11 +184,6 @@ func TestServerCreateAdminUser(t *testing.T) {
errC <- err
}()

// 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(ctx, testutil.WaitSuperLong)
defer cancel()

pty.ExpectMatchContext(ctx, "User created successfully.")
pty.ExpectMatchContext(ctx, username)
pty.ExpectMatchContext(ctx, email)
Expand All @@ -208,8 +204,11 @@ 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",
Expand All @@ -227,20 +226,15 @@ 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)

// 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(ctx, testutil.WaitSuperLong)
defer cancel()

pty.ExpectMatchContext(ctx, "User created successfully.")
pty.ExpectMatchContext(ctx, username)
pty.ExpectMatchContext(ctx, email)
Expand Down