Skip to content

test: Check created_at for prepareData to ensure user order #6436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 3, 2023
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
Next Next commit
test: Check created_at for prepareData to ensure user order
  • Loading branch information
Emyrk committed Mar 3, 2023
commit 96de7d3d111fe6aa919c8a23ab34eae83a354369
32 changes: 26 additions & 6 deletions cli/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"runtime"
"strings"
"testing"
"time"

"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -197,13 +198,32 @@ func prepareTestData(t *testing.T) (*codersdk.Client, map[string]string) {
IncludeProvisionerDaemon: true,
})
firstUser := coderdtest.CreateFirstUser(t, rootClient)
secondUser, err := rootClient.CreateUser(ctx, codersdk.CreateUserRequest{
Email: "testuser2@coder.com",
Username: "testuser2",
Password: coderdtest.FirstUserParams.Password,
OrganizationID: firstUser.OrganizationID,
})

firstUserData, err := rootClient.User(ctx, firstUser.UserID.String())
require.NoError(t, err)

var secondUser codersdk.User
for {
secondUser, err = rootClient.CreateUser(ctx, codersdk.CreateUserRequest{
Email: "testuser2@coder.com",
Username: "testuser2",
Password: coderdtest.FirstUserParams.Password,
OrganizationID: firstUser.OrganizationID,
})
require.NoError(t, err)

// If the second user has the same timestamp as the first user, delete it and try again.
// This is because user order is determined by creation time, and we want to ensure
// second user is listed after first user.
// Round to microsecond since that is the precision of the database.
if secondUser.CreatedAt.Round(time.Microsecond).Equal(firstUserData.CreatedAt.Round(time.Microsecond)) {
err = rootClient.DeleteUser(ctx, secondUser.ID)
require.NoError(t, err)
continue
}
break
}

version := coderdtest.CreateTemplateVersion(t, rootClient, firstUser.OrganizationID, nil)
version = coderdtest.AwaitTemplateVersionJob(t, rootClient, version.ID)
template := coderdtest.CreateTemplate(t, rootClient, firstUser.OrganizationID, version.ID, func(req *codersdk.CreateTemplateRequest) {
Expand Down