added tests for db and user
Some checks reported errors
arbeitszeitmessung/pipeline/head Something is wrong with the build of this commit
Some checks reported errors
arbeitszeitmessung/pipeline/head Something is wrong with the build of this commit
This commit is contained in:
38
Backend/models/db_test.go
Normal file
38
Backend/models/db_test.go
Normal 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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user