mirror of
https://github.com/coder/coder.git
synced 2026-10-31 11:02:50 +08:00
feat: add --username-infix to scaletest create-users (#28514)
This commit is contained in:
@@ -23,6 +23,7 @@ func (r *RootCmd) scaletestCreateUsers() *serpent.Command {
|
||||
var (
|
||||
count int64
|
||||
templateAdminPercentage float64
|
||||
usernameInfix string
|
||||
noCleanup bool
|
||||
|
||||
tracingFlags = &scaletestTracingFlags{}
|
||||
@@ -93,6 +94,15 @@ func (r *RootCmd) scaletestCreateUsers() *serpent.Command {
|
||||
|
||||
th := harness.NewTestHarness(strategy.toStrategy(), cleanupStrategy.toStrategy())
|
||||
|
||||
// The scaletest- root is always kept so the cleanup command still
|
||||
// finds these users; --username-infix is inserted between it and the
|
||||
// random suffix, e.g. --username-infix asdf produces usernames like
|
||||
// scaletest-asdf-<random>-<id>.
|
||||
userPrefix := loadtestutil.ScaleTestPrefix + "-"
|
||||
if usernameInfix != "" {
|
||||
userPrefix += usernameInfix + "-"
|
||||
}
|
||||
|
||||
_, _ = fmt.Fprintln(inv.Stderr, "Creating users...")
|
||||
for i := range count {
|
||||
id := strconv.FormatInt(i, 10)
|
||||
@@ -110,9 +120,15 @@ func (r *RootCmd) scaletestCreateUsers() *serpent.Command {
|
||||
return xerrors.Errorf("create runner client: %w", err)
|
||||
}
|
||||
|
||||
// Username and email are generated by createusers when left empty.
|
||||
username, email, err := loadtestutil.GenerateUserIdentifierWithPrefix(userPrefix, id)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("generate user identifier: %w", err)
|
||||
}
|
||||
|
||||
config := createusers.Config{
|
||||
OrganizationID: me.OrganizationIDs[0],
|
||||
Username: username,
|
||||
Email: email,
|
||||
}
|
||||
if err := config.Validate(); err != nil {
|
||||
return xerrors.Errorf("validate config: %w", err)
|
||||
@@ -191,6 +207,12 @@ func (r *RootCmd) scaletestCreateUsers() *serpent.Command {
|
||||
Description: "Percentage of users to assign the Template Admin role to (0-100).",
|
||||
Value: serpent.Float64Of(&templateAdminPercentage),
|
||||
},
|
||||
{
|
||||
Flag: "username-infix",
|
||||
Env: "CODER_SCALETEST_CREATE_USERS_USERNAME_INFIX",
|
||||
Description: "Optional infix inserted between the mandatory \"scaletest-\" root and the rest of each generated username. For example --username-infix asdf produces usernames like scaletest-asdf-<random>-<id>; leave empty for the default scaletest-<random>-<id> names. Use it to partition users into disjoint pools that a matching --reuse-users run can select. The scaletest- root is always kept so the cleanup command still discovers the users.",
|
||||
Value: serpent.StringOf(&usernameInfix),
|
||||
},
|
||||
{
|
||||
Flag: "no-cleanup",
|
||||
Env: "CODER_SCALETEST_NO_CLEANUP",
|
||||
|
||||
Reference in New Issue
Block a user