56 lines
1.0 KiB
Go
56 lines
1.0 KiB
Go
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
|
|
}
|