Skip to content

Commit

Permalink
Allow setting basename and password for generated users (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
rrenkert authored Dec 24, 2024
1 parent 2475dff commit 1ceed7d
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 23 deletions.
6 changes: 3 additions & 3 deletions connect/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (o Options) Run(ctx context.Context, cfg client.Config) error {

var clients []*client.Client

if o.MuliUserMeeting == -1 {
if o.MultiUserMeeting == -1 {
c, err := client.New(cfg)
if err != nil {
return fmt.Errorf("creating client: %w", err)
Expand All @@ -66,7 +66,7 @@ func (o Options) Run(ctx context.Context, cfg client.Config) error {
}

fmt.Println("login clients")
vote.MassLogin(ctx, clients, o.MuliUserMeeting)
vote.MassLogin(ctx, clients, o.MultiUserMeeting, o.BaseName, o.UsersPassword)
}

actionCh := make(chan struct{})
Expand Down Expand Up @@ -97,7 +97,7 @@ func (o Options) Run(ctx context.Context, cfg client.Config) error {
for i := 0; i < o.Amount; i++ {
go func(i int) {
client := clients[0]
if o.MuliUserMeeting != -1 {
if o.MultiUserMeeting != -1 {
client = clients[i]
}
var r io.ReadCloser
Expand Down
14 changes: 8 additions & 6 deletions connect/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import "os"

// Options is the meta information for the cli.
type Options struct {
Amount int `help:"Amount of connections to use." short:"n" default:"10"`
Body string `help:"Request Body." short:"b"`
BodyFile *os.File `help:"Request Body from a file. Use - for stdin"`
Action *os.File `help:"Request Body to use as an action. If set, press enter to sent the action"`
SkipFirst bool `help:"Use skip first flag to save traffic."`
MuliUserMeeting int `help:"Use dummy user accounts from meeting. 0 For global dummys. Uses the same account as default." short:"m" default:"-1"`
Amount int `help:"Amount of connections to use." short:"n" default:"10"`
Body string `help:"Request Body." short:"b"`
BodyFile *os.File `help:"Request Body from a file. Use - for stdin"`
Action *os.File `help:"Request Body to use as an action. If set, press enter to sent the action"`
SkipFirst bool `help:"Use skip first flag to save traffic."`
MultiUserMeeting int `help:"Use dummy user accounts from meeting. 0 For global dummys. Uses the same account as default." short:"m" default:"-1"`
BaseName string `help:"The name string that is concatenated with meeting id and user id, e.g. m1dummy1." default:"dummy"`
UsersPassword string `help:"The password used for all users" default:"pass"`
}

// Help returns the help message
Expand Down
10 changes: 6 additions & 4 deletions createusers/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package createusers

// Options is the meta information for the cli.
type Options struct {
Amount int `help:"Amount of user to be created." short:"n" default:"10"`
MeetingID int `help:"If set, put the user in the delegated group of this meeting." short:"m"`
Batch int `help:"Number of users to create with one request. Default is all at once." short:"b"`
FirstID int `help:"First id to use. Usefull when additional users should be created." default:"1"`
Amount int `help:"Amount of user to be created." short:"n" default:"10"`
MeetingID int `help:"If set, put the user in the delegated group of this meeting." short:"m"`
Batch int `help:"Number of users to create with one request. Default is all at once." short:"b"`
FirstID int `help:"First id to use. Usefull when additional users should be created." default:"1"`
BaseName string `help:"The name string that is concatenated with meeting id and user id, e.g. m1dummy1." default:"dummy"`
UsersPassword string `help:"The password used for all users" default:"pass"`
}

// Help returns the help message
Expand Down
7 changes: 5 additions & 2 deletions createusers/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,21 @@ func (o Options) Run(ctx context.Context, cfg client.Config) error {
userID := b*(o.Batch) + i + o.FirstID
user := fmt.Sprintf(
`{
"username": "%sdummy%d",
"default_password": "pass",
"username": "%s%s%d",
"default_password": "%s",
%s
"is_active":true
}`,
namePrefix,
o.BaseName,
userID,
o.UsersPassword,
extraFields,
)
users = append(users, user)
}

fmt.Printf("%s", users)
createBody := fmt.Sprintf(
`[{
"action": "user.create",
Expand Down
10 changes: 6 additions & 4 deletions vote/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package vote

// Options is the meta information for the cli.
type Options struct {
Amount int `help:"Amount users to use." short:"n" default:"10"`
PollID int `help:"ID of the poll to use." short:"i" default:"1"`
Interrupt bool `help:"Wait for a user input after login."`
Loop bool `help:"After the test, start it again with the logged in users."`
Amount int `help:"Amount users to use." short:"n" default:"10"`
PollID int `help:"ID of the poll to use." short:"i" default:"1"`
Interrupt bool `help:"Wait for a user input after login."`
Loop bool `help:"After the test, start it again with the logged in users."`
BaseName string `help:"The name string that is concatenated with meeting id and user id, e.g. m1dummy1." default:"dummy"`
UsersPassword string `help:"The password used for all users" default:"pass"`
}

// Help returns the help message
Expand Down
8 changes: 4 additions & 4 deletions vote/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (o Options) Run(ctx context.Context, cfg client.Config) error {

log.Printf("Login %d clients", len(clients))
start := time.Now()
MassLogin(ctx, clients, meetingID)
MassLogin(ctx, clients, meetingID, o.BaseName, o.UsersPassword)
log.Printf("All clients logged in %v", time.Now().Sub(start))

first := true
Expand Down Expand Up @@ -142,7 +142,7 @@ func dataKeys(m map[string]json.RawMessage) []string {
}

// MassLogin logs in a list of clients.
func MassLogin(ctx context.Context, clients []*client.Client, meetingID int) {
func MassLogin(ctx context.Context, clients []*client.Client, meetingID int, basename string, password string) {
var wgLogin sync.WaitGroup
progress := mpb.New(mpb.WithWaitGroup(&wgLogin))
loginBar := progress.AddBar(int64(len(clients)))
Expand All @@ -156,10 +156,10 @@ func MassLogin(ctx context.Context, clients []*client.Client, meetingID int) {

username := fmt.Sprintf("dummy%d", i+1)
if meetingID > 0 {
username = fmt.Sprintf("m%ddummy%d", meetingID, i+1)
username = fmt.Sprintf("m%d%s%d", meetingID, username, i+1)
}

if err := client.LoginWithCredentials(ctx, username, "pass"); err != nil {
if err := client.LoginWithCredentials(ctx, username, password); err != nil {
log.Printf("Login failed for user %s: %v", username, err)
return
}
Expand Down

0 comments on commit 1ceed7d

Please sign in to comment.