- Notifications
You must be signed in to change notification settings - Fork1k
refactor(scaletest): generate user and workspace names if omitted#19885
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
41 changes: 3 additions & 38 deletionscli/exp_scaletest.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
14 changes: 7 additions & 7 deletionsscaletest/createworkspaces/config.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -13,9 +13,9 @@ import ( | ||
type UserConfig struct { | ||
// OrganizationID is the ID of the organization to add the user to. | ||
OrganizationID uuid.UUID `json:"organization_id"` | ||
// Username is the username of the new user. Generated if empty. | ||
Username string `json:"username"` | ||
// Email is the email of the new user. Generated if empty. | ||
ethanndickson marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
Email string `json:"email"` | ||
// SessionToken is the session token of an already existing user. If set, no | ||
// user will be created. | ||
@@ -26,12 +26,12 @@ func (c UserConfig) Validate() error { | ||
if c.OrganizationID == uuid.Nil { | ||
return xerrors.New("organization_id must not be a nil UUID") | ||
} | ||
if c.SessionToken!= "" { | ||
if c.Username!= "" { | ||
return xerrors.New("username must beempty when session_token isset") | ||
} | ||
if c.Email!= "" { | ||
return xerrors.New("email must beempty when session_token isset") | ||
} | ||
} | ||
21 changes: 14 additions & 7 deletionsscaletest/createworkspaces/config_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletionsscaletest/loadtestutil/names.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package loadtestutil | ||
import ( | ||
"fmt" | ||
"strings" | ||
"github.com/coder/coder/v2/cryptorand" | ||
) | ||
const ( | ||
// Prefix for all scaletest resources (users and workspaces) | ||
ScaleTestPrefix = "scaletest" | ||
// Email domain for scaletest users | ||
EmailDomain = "@scaletest.local" | ||
DefaultRandLength = 8 | ||
) | ||
// GenerateUserIdentifier generates a username and email for scale testing. | ||
// The username follows the pattern: scaletest-<random>-<id> | ||
// The email follows the pattern: <random>-<id>@scaletest.local | ||
func GenerateUserIdentifier(id string) (username, email string, err error) { | ||
randStr, err := cryptorand.String(DefaultRandLength) | ||
if err != nil { | ||
return "", "", err | ||
} | ||
username = fmt.Sprintf("%s-%s-%s", ScaleTestPrefix, randStr, id) | ||
email = fmt.Sprintf("%s-%s%s", randStr, id, EmailDomain) | ||
return username, email, nil | ||
} | ||
// GenerateWorkspaceName generates a workspace name for scale testing. | ||
// The workspace name follows the pattern: scaletest-<random>-<id> | ||
func GenerateWorkspaceName(id string) (name string, err error) { | ||
randStr, err := cryptorand.String(DefaultRandLength) | ||
if err != nil { | ||
return "", err | ||
} | ||
return fmt.Sprintf("%s-%s-%s", ScaleTestPrefix, randStr, id), nil | ||
} | ||
// IsScaleTestUser checks if a username indicates it was created for scale testing. | ||
func IsScaleTestUser(username, email string) bool { | ||
return strings.HasPrefix(username, ScaleTestPrefix+"-") || | ||
strings.HasSuffix(email, EmailDomain) | ||
} | ||
// IsScaleTestWorkspace checks if a workspace name indicates it was created for scale testing. | ||
func IsScaleTestWorkspace(workspaceName, ownerName string) bool { | ||
return strings.HasPrefix(workspaceName, ScaleTestPrefix+"-") || | ||
strings.HasPrefix(ownerName, ScaleTestPrefix+"-") | ||
} |
7 changes: 3 additions & 4 deletionsscaletest/workspacebuild/run.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.