Some checks reported errors
arbeitszeitmessung/pipeline/head Something is wrong with the build of this commit
39 lines
640 B
Go
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,
|
|
}
|
|
}
|