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
Next Next commit
fixup! chore: fix flake in create-admin-user test
  • Loading branch information
deansheather committed Feb 8, 2023
commit dfdce8b94f07acdf69ed58a1042c93845e2a12a3
51 changes: 35 additions & 16 deletions cli/server_createadminuser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"runtime"
"testing"
"time"

"github.com/google/uuid"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -135,14 +136,20 @@ 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("****")
// 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.
//nolint:gocritic
ctx, cancel := context.WithTimeout(ctx, 1*time.Minute)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ctx, cancel := context.WithTimeout(ctx, 1*time.Minute)
ctx, cancel := context.WithTimeout(ctx, testutil.WaitSuperLong)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait we have that? awesome

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()))
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)

Expand Down Expand Up @@ -178,10 +185,16 @@ func TestServerCreateAdminUser(t *testing.T) {
errC <- err
}()

pty.ExpectMatch("User created successfully.")
pty.ExpectMatch(username)
pty.ExpectMatch(email)
pty.ExpectMatch("****")
// 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.
//nolint:gocritic
ctx, cancel := context.WithTimeout(ctx, 1*time.Minute)
defer cancel()

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

require.NoError(t, <-errC)

Expand Down Expand Up @@ -226,10 +239,16 @@ func TestServerCreateAdminUser(t *testing.T) {
pty.ExpectMatch("> Confirm password")
pty.WriteLine(password)

pty.ExpectMatch("User created successfully.")
pty.ExpectMatch(username)
pty.ExpectMatch(email)
pty.ExpectMatch("****")
// 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.
//nolint:gocritic
ctx, cancel := context.WithTimeout(ctx, 1*time.Minute)
defer cancel()

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

require.NoError(t, <-errC)

Expand Down