Thanks to visit codestin.com
Credit goes to github.com

Skip to content

refactor: refactor authentication logic to use core types and interfaces#63

Merged
appleboy merged 1 commit intomainfrom
interface
Mar 1, 2026
Merged

refactor: refactor authentication logic to use core types and interfaces#63
appleboy merged 1 commit intomainfrom
interface

Conversation

@appleboy
Copy link
Member

@appleboy appleboy commented Mar 1, 2026

  • Move authentication result and provider interface definitions into the new core package
  • Update UserService, auth providers, and related code to use core.AuthProvider and core.AuthResult types
  • Add GoMock generation for the core.AuthProvider interface
  • Add tests for UserService authentication covering success, provider nil, wrong password, HTTP API provider, and user not found scenarios

- Move authentication result and provider interface definitions into the new core package
- Update UserService, auth providers, and related code to use core.AuthProvider and core.AuthResult types
- Add GoMock generation for the core.AuthProvider interface
- Add tests for UserService authentication covering success, provider nil, wrong password, HTTP API provider, and user not found scenarios

Signed-off-by: appleboy <[email protected]>
Copilot AI review requested due to automatic review settings March 1, 2026 02:12
@codecov
Copy link

codecov bot commented Mar 1, 2026

Codecov Report

❌ Patch coverage is 4.00000% with 24 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/mocks/mock_auth.go 0.00% 23 Missing ⚠️
internal/bootstrap/providers.go 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors authentication type definitions and provider interfaces by moving them from the internal/auth package into the new internal/core package, making UserService depend on an interface (core.AuthProvider) rather than concrete types. It also adds GoMock generation for the new interface and new tests for the Authenticate method on UserService.

Changes:

  • Introduces core.AuthResult and core.AuthProvider interface in a new internal/core/auth.go file; makes auth.Result a type alias for backward compatibility
  • Refactors UserService, LocalAuthProvider, HTTPAPIAuthProvider, and bootstrap/providers.go to use the new core.AuthProvider interface
  • Adds a GoMock-generated MockAuthProvider and six new unit tests for UserService.Authenticate

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/core/auth.go New file defining AuthResult struct and AuthProvider interface
internal/auth/types.go Replaces auth.Result struct with a type alias to core.AuthResult
internal/auth/local.go Adds compile-time interface compliance assertion
internal/auth/http_api.go Adds compile-time interface compliance assertion
internal/services/user.go Changes localProvider/httpAPIProvider fields and constructor params from concrete types to core.AuthProvider interface
internal/bootstrap/providers.go Returns core.AuthProvider interface instead of concrete pointer to avoid the typed-nil interface pitfall
internal/mocks/mock_auth.go Generated MockAuthProvider mock for use in tests
internal/mocks/generate.go Adds go:generate directive for mock_auth.go
internal/services/user_test.go Adds six tests for UserService.Authenticate covering local and HTTP API scenarios

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@appleboy appleboy merged commit 5985f73 into main Mar 1, 2026
20 of 21 checks passed
@appleboy appleboy deleted the interface branch March 1, 2026 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants