Перенести пользователей в PostgreSQL и добавить пароли

This commit is contained in:
2026-10-06 14:54:34 +03:00
parent 46c00436a0
commit 618d3919d1
17 changed files with 482 additions and 219 deletions
+4
View File
@@ -121,6 +121,9 @@ func run(baseURL string, clients, perClient int) (Report, error) {
return report, nil
}
// clientPassword is shared by the synthetic clients of one run.
const clientPassword = "concurrency-check-password"
func registerClients(api *client, runID string, n int) ([]string, error) {
ids := make([]string, 0, n)
for i := range n {
@@ -128,6 +131,7 @@ func registerClients(api *client, runID string, n int) ([]string, error) {
body := map[string]string{
"username": fmt.Sprintf("load_%s_%d", runID, i),
"display_name": fmt.Sprintf("Load client %d", i),
"password": clientPassword,
}
if err := api.post("/api/v1/users", "", body, &created); err != nil {
return nil, fmt.Errorf("register client %d: %w", i, err)
+19 -1
View File
@@ -1,17 +1,35 @@
package main
import (
"context"
"fmt"
"io"
"log/slog"
"net/http/httptest"
"os"
"testing"
"messenger/internal/app"
"messenger/internal/testenv"
)
var db *testenv.DB
func TestMain(m *testing.M) {
var err error
db, err = testenv.StartPostgres(context.Background())
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
code := m.Run()
db.Close()
os.Exit(code)
}
func TestRunAgainstLiveServer(t *testing.T) {
log := slog.New(slog.NewTextHandler(io.Discard, nil))
srv := httptest.NewServer(app.New(log, 64*1024).Engine)
srv := httptest.NewServer(app.New(app.Deps{Log: log, DB: db.Pool, MaxBodyBytes: 64 * 1024}).Engine)
defer srv.Close()
report, err := run(srv.URL, 10, 10)