tsk-19: Service login (#23)

Closes #19

Reviewed-on: phoenix/textsender-auth#23
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
phoenix
2025-11-21 18:42:58 +00:00
committed by phoenix
parent c340693b24
commit 0a00282ba7
9 changed files with 205 additions and 29 deletions
+18 -6
View File
@@ -3,11 +3,11 @@ package mock
import (
"context"
"errors"
"fmt"
"sync"
"github.com/google/uuid"
"git.kundeng.us/phoenix/textsender-models/pkg/user"
"github.com/google/uuid"
)
type MockServiceUserStore struct {
@@ -53,10 +53,6 @@ func (m *MockServiceUserStore) CheckWithUsername(ctx context.Context, username s
return false, m.Error
}
if m.Error != nil {
return false, m.Error
}
var exists bool
for _, serviceUser := range m.ServiceUsers {
@@ -72,3 +68,19 @@ func (m *MockServiceUserStore) CheckWithUsername(ctx context.Context, username s
return exists, nil
}
}
func (m *MockServiceUserStore) GetWithUsername(ctx context.Context, username string) (*user.ServiceUser, error) {
m.mu.Lock()
defer m.mu.Unlock()
if m.Error != nil {
return nil, m.Error
}
serviceUser := m.ServiceUsersByUsername[username]
if serviceUser != nil {
return serviceUser, nil
} else {
return nil, fmt.Errorf("User not found")
}
}