Files
arbeitszeitmessung/Backend/models/db_test.go
Tom Tröger b614049d03
Some checks reported errors
arbeitszeitmessung/pipeline/head Something is wrong with the build of this commit
added tests for db and user
2025-08-13 15:50:11 +02:00

39 lines
640 B
Go

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,
}
}