mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-02 14:56:38 +08:00
autoresearch iter 11: unimplemented auth mocks fail loudly instead of returning (nil, nil)
Authenticate, CreateAuthSource, UpdateAuthSource and ToggleAuthSource claimed success with a nil record, so any test that reached them surfaced a nil pointer dereference instead of the actual cause. Full suite confirms no test relied on the silent behaviour.
This commit is contained in:
@@ -170,6 +170,10 @@ type MockAuthService struct {
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
// errMockNotImplemented marks a mock method no test exercises yet, so an
|
||||
// accidental call reports this instead of dereferencing a nil result.
|
||||
var errMockNotImplemented = errors.New("mock auth service: not implemented")
|
||||
|
||||
// RequireAuthMiddleware returns a dummy auth middleware.
|
||||
func (a *MockAuthService) RequireAuthMiddleware() any {
|
||||
return func(c *gin.Context) { c.Next() }
|
||||
@@ -226,7 +230,7 @@ func (a *MockAuthService) VerifyToken(_ context.Context, token string) (*contrac
|
||||
|
||||
// Authenticate verifies credentials.
|
||||
func (a *MockAuthService) Authenticate(_ context.Context, _, _ string) (*contracts.UserDTO, error) {
|
||||
return nil, nil
|
||||
return nil, errMockNotImplemented
|
||||
}
|
||||
|
||||
// CreateSession creates a login session.
|
||||
@@ -257,12 +261,12 @@ func (a *MockAuthService) ListAuthSources(_ context.Context) ([]contracts.AuthSo
|
||||
|
||||
// CreateAuthSource creates an authentication source.
|
||||
func (a *MockAuthService) CreateAuthSource(_ context.Context, _ contracts.AuthSourceDTO) (*contracts.AuthSourceDTO, error) {
|
||||
return nil, nil
|
||||
return nil, errMockNotImplemented
|
||||
}
|
||||
|
||||
// UpdateAuthSource updates an authentication source.
|
||||
func (a *MockAuthService) UpdateAuthSource(_ context.Context, _ uint64, _ contracts.AuthSourceDTO) (*contracts.AuthSourceDTO, error) {
|
||||
return nil, nil
|
||||
return nil, errMockNotImplemented
|
||||
}
|
||||
|
||||
// DeleteAuthSource deletes an authentication source.
|
||||
@@ -272,7 +276,7 @@ func (a *MockAuthService) DeleteAuthSource(_ context.Context, _ uint64) error {
|
||||
|
||||
// ToggleAuthSource toggles an authentication source active state.
|
||||
func (a *MockAuthService) ToggleAuthSource(_ context.Context, _ uint64) (*contracts.AuthSourceDTO, error) {
|
||||
return nil, nil
|
||||
return nil, errMockNotImplemented
|
||||
}
|
||||
|
||||
// SetupTestEnv initializes test helper environment and binds DB, Cache, Storage, Auth mocks to shared services.
|
||||
|
||||
Reference in New Issue
Block a user