added tests for db and user
Some checks reported errors
arbeitszeitmessung/pipeline/head Something is wrong with the build of this commit

This commit is contained in:
2025-08-13 15:50:11 +02:00
parent ba885357c2
commit b614049d03
14 changed files with 126 additions and 36 deletions

38
Backend/models/db_test.go Normal file
View File

@@ -0,0 +1,38 @@
package models_test
import (
"arbeitszeitmessung/models"
"database/sql"
"testing"
_ "github.com/lib/pq"
)
type DBFixture struct {
Database models.IDatabase
TX *sql.Tx
}
func SetupDBFixture(t *testing.T) *DBFixture {
t.Helper()
db, err := sql.Open("postgres", "postgres://postgres:password@localhost:5433/arbeitszeitmessung?sslmode=disable")
if err != nil {
t.Fatalf("failed to connect to database: %v", err)
}
tx, err := db.Begin()
if err != nil {
t.Fatalf("Failed to start transaction: %v", err)
}
t.Cleanup(func() {
tx.Rollback()
db.Close()
})
return &DBFixture{
Database: tx,
TX: tx,
}
}