From 132990e985751e40c263224a62983c8013409a36 Mon Sep 17 00:00:00 2001 From: xengineering Date: Sat, 27 Jun 2026 21:21:45 +0200 Subject: Switch Register() and Authenticate() to sql.Tx Using sql.Tx (database transactions) instead of a plain database has the advantage that the caller can wrap multiple library calls into one transaction. This guarantees that no database entries change between the library calls which is critical to prevent race conditions. --- handlers_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'handlers_test.go') diff --git a/handlers_test.go b/handlers_test.go index 78baac6..c4aba29 100644 --- a/handlers_test.go +++ b/handlers_test.go @@ -83,7 +83,9 @@ func TestApiAuthenticate(t *testing.T) { t.Fatalf("Could not migrate test database: %v", err) } - err = Register(db, "testuser", "mypass") + err = Transaction(db, func(tx *sql.Tx) error { + return Register(tx, "testuser", "mypass") + }) if err != nil { t.Fatalf("Failed to register test user: %v", err) } -- cgit v1.3.1