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:
ryan
2026-08-29 08:33:16 +08:00
parent 643bfca996
commit 3d2038a251
@@ -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.