diff --git a/cmd/goyco/commands/parallel_processor.go b/cmd/goyco/commands/parallel_processor.go index 444e56e..0ab6f90 100644 --- a/cmd/goyco/commands/parallel_processor.go +++ b/cmd/goyco/commands/parallel_processor.go @@ -9,14 +9,14 @@ import ( "sync" "time" - "golang.org/x/crypto/bcrypt" "goyco/internal/database" "goyco/internal/repositories" ) type ParallelProcessor struct { - maxWorkers int - timeout time.Duration + maxWorkers int + timeout time.Duration + passwordHash string } func NewParallelProcessor() *ParallelProcessor { @@ -28,6 +28,10 @@ func NewParallelProcessor() *ParallelProcessor { } } +func (p *ParallelProcessor) SetPasswordHash(hash string) { + p.passwordHash = hash +} + func (p *ParallelProcessor) CreateUsersInParallel(userRepo repositories.UserRepository, count int, progress *ProgressIndicator) ([]database.User, error) { ctx, cancel := context.WithTimeout(context.Background(), p.timeout) defer cancel() @@ -292,18 +296,12 @@ func generateRandomIdentifier() string { } func (p *ParallelProcessor) createSingleUser(userRepo repositories.UserRepository, index int) (database.User, error) { - password := "password123" randomID := generateRandomIdentifier() username := fmt.Sprintf("user_%s", randomID) email := fmt.Sprintf("user_%s@goyco.local", randomID) - hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) - if err != nil { - return database.User{}, fmt.Errorf("hash password: %w", err) - } - const maxRetries = 10 - for attempt := 0; attempt < maxRetries; attempt++ { + for range maxRetries { user, err := userRepo.GetByEmail(email) if err == nil { return *user, nil @@ -312,7 +310,7 @@ func (p *ParallelProcessor) createSingleUser(userRepo repositories.UserRepositor user = &database.User{ Username: username, Email: email, - Password: string(hashedPassword), + Password: p.passwordHash, EmailVerified: true, } @@ -379,7 +377,7 @@ func (p *ParallelProcessor) createSinglePost(postRepo repositories.PostRepositor content := fmt.Sprintf("Autogenerated seed post #%d\n\nThis is sample content for testing purposes. The post discusses %s and provides valuable insights.", index, title) const maxRetries = 10 - for attempt := 0; attempt < maxRetries; attempt++ { + for range maxRetries { post := &database.Post{ Title: title, URL: url,