vetrag/auth_test.go

54 lines
1.7 KiB
Go

package main
import (
"context"
"errors"
)
var ErrUserExists = errors.New("user already exists")
var ErrUserNotFound = errors.New("user not found")
// mockRepo implements ChatRepositoryAPI for auth tests
// Only implements methods needed for auth
type mockRepo struct {
users map[string]string // username: passwordHash
}
func (m *mockRepo) CountUsers(ctx context.Context) (int, error) {
return len(m.users), nil
}
func (m *mockRepo) CreateUser(ctx context.Context, username, passwordHash string) error {
if _, exists := m.users[username]; exists {
return ErrUserExists
}
m.users[username] = passwordHash
return nil
}
func (m *mockRepo) GetUserByUsername(ctx context.Context, username string) (*User, error) {
hash, ok := m.users[username]
if !ok {
return nil, ErrUserNotFound
}
return &User{Username: username, PasswordHash: hash}, nil
}
// Add stubs for all ChatRepositoryAPI methods not used in tests
func (m *mockRepo) SaveChatInteraction(ctx context.Context, rec ChatInteraction) error { return nil }
func (m *mockRepo) ListChatInteractions(ctx context.Context, limit, offset int) ([]ChatInteraction, error) {
return nil, nil
}
func (m *mockRepo) SaveLLMRawEvent(ctx context.Context, correlationID, phase, raw string) error {
return nil
}
func (m *mockRepo) ListLLMRawEvents(ctx context.Context, correlationID string, limit, offset int) ([]RawLLMEvent, error) {
return nil, nil
}
func (m *mockRepo) SaveKnowledgeModel(ctx context.Context, text string) error { return nil }
func (m *mockRepo) ListKnowledgeModels(ctx context.Context, limit, offset int) ([]knowledgeModelMeta, error) {
return nil, nil
}
func (m *mockRepo) GetKnowledgeModelText(ctx context.Context, id int64) (string, error) {
return "", nil
}