replace static status definition by const
This commit is contained in:
@@ -19,6 +19,12 @@ const (
|
||||
RoleMember = "member"
|
||||
)
|
||||
|
||||
const (
|
||||
StatusActive = "active"
|
||||
StatusDisabled = "disabled"
|
||||
StatusRevoked = "revoked"
|
||||
)
|
||||
|
||||
type Principal struct {
|
||||
ID ident.UUID
|
||||
Kind string
|
||||
|
||||
@@ -31,9 +31,11 @@ func (s *Service) CreatePrincipal(ctx context.Context, params CreatePrincipalPar
|
||||
|
||||
status := params.Status
|
||||
if status == "" {
|
||||
status = "active"
|
||||
status = StatusActive
|
||||
}
|
||||
if status != "active" && status != "disabled" && status != "revoked" {
|
||||
switch status {
|
||||
case StatusActive, StatusDisabled, StatusRevoked:
|
||||
default:
|
||||
return nil, fmt.Errorf("%w: %q", ErrInvalidStatus, status)
|
||||
}
|
||||
|
||||
@@ -87,7 +89,7 @@ func (s *Service) CreateGuest(ctx context.Context, name string) (*Principal, err
|
||||
ID: id,
|
||||
Kind: KindGuest,
|
||||
Name: name,
|
||||
Status: "active",
|
||||
Status: StatusActive,
|
||||
CreatedAt: now,
|
||||
}); err != nil {
|
||||
return err
|
||||
|
||||
@@ -27,8 +27,8 @@ func TestCreatePrincipal(t *testing.T) {
|
||||
if created.Name != "alice" {
|
||||
t.Fatalf("name = %q, attendu alice", created.Name)
|
||||
}
|
||||
if created.Status != "active" {
|
||||
t.Fatalf("status = %q, attendu active", created.Status)
|
||||
if created.Status != StatusActive {
|
||||
t.Fatalf("status = %q, attendu %q", created.Status, StatusActive)
|
||||
}
|
||||
if len(created.Groups) != 0 {
|
||||
t.Fatalf("groupes = %+v, attendu aucun", created.Groups)
|
||||
|
||||
Reference in New Issue
Block a user