follow sql schema

This commit is contained in:
venture
2026-11-14 09:52:18 +01:00
parent f7649f24ef
commit 276a9fe320
23 changed files with 855 additions and 548 deletions
+55
View File
@@ -0,0 +1,55 @@
package identity
import (
"context"
"testing"
"mediarr/database"
)
func newTestService(t *testing.T) *Service {
t.Helper()
t.Chdir(t.TempDir())
err, db := database.NewDatabase(database.NewDatabaseParams{})
if err != nil {
t.Fatalf("NewDatabase : %v", err)
}
t.Cleanup(func() {
if err := db.Close(); err != nil {
t.Errorf("Close : %v", err)
}
})
return NewService(*db)
}
func mustCreatePrincipal(t *testing.T, service *Service, kind, name string) *Principal {
t.Helper()
created, err := service.CreatePrincipal(context.Background(), CreatePrincipalParams{
Kind: kind,
Name: name,
})
if err != nil {
t.Fatalf("CreatePrincipal(%q) : %v", name, err)
}
return created
}
func mustGroup(t *testing.T, service *Service, name string) database.Principal {
t.Helper()
group, err := service.db.Queries.GetPrincipalByNameAndKind(context.Background(), database.GetPrincipalByNameAndKindParams{
Kind: KindGroup,
Name: name,
})
if err != nil {
t.Fatalf("groupe %q : %v", name, err)
}
return group
}