Documentation
¶
Overview ¶
Package github provides a client for checking GitHub user login status. This supports the login revalidation worker in detecting renamed and deleted accounts.
Package github provides test mocks for the GitHub client.
Index ¶
- type Client
- type HTTPClient
- type LoginResult
- type LoginStatus
- type MockClient
- func (m *MockClient) CallCount() int
- func (m *MockClient) CalledLogins() []string
- func (m *MockClient) CheckLogin(ctx context.Context, login string) (*LoginResult, error)
- func (m *MockClient) Reset()
- func (m *MockClient) SetDefaultResult(result *LoginResult)
- func (m *MockClient) SetResponse(login string, result *LoginResult)
- func (m *MockClient) WasCalled(login string) bool
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface {
// CheckLogin checks if a login exists on GitHub and returns its status.
//
// Returns:
// - LoginResult with Status, optional NewLogin, and optional ErrorMsg
// - error if the check itself fails (network issue, malformed response, etc.)
CheckLogin(ctx context.Context, login string) (*LoginResult, error)
}
Client defines the interface for checking GitHub login status. This allows for test mocks without making live API calls.
func NewHTTPClient ¶
NewHTTPClient creates a new GitHub API client.
Parameters:
- token: GitHub personal access token for authentication
- timeout: Request timeout (default 15s if 0)
Returns:
- A configured Client that makes real HTTP requests to GitHub API
type HTTPClient ¶
type HTTPClient struct {
// contains filtered or unexported fields
}
HTTPClient implements Client using the real GitHub API.
func (*HTTPClient) CheckLogin ¶
func (c *HTTPClient) CheckLogin(ctx context.Context, login string) (*LoginResult, error)
CheckLogin checks a login against the GitHub API.
type LoginResult ¶
type LoginResult struct {
Status LoginStatus // The detected status
NewLogin *string // The new login if Status == StatusRenamed, otherwise nil
ErrorMsg *string // Error message if Status == StatusRetry, otherwise nil
}
LoginResult represents the result of checking a login's status.
type LoginStatus ¶
type LoginStatus string
LoginStatus represents the possible outcomes of checking a login's liveness.
const ( // StatusValidated means the login exists and matches the queried login StatusValidated LoginStatus = "validated" // StatusRenamed means the login was renamed to a different login StatusRenamed LoginStatus = "renamed" // StatusDeleted means the login no longer exists (account deleted) StatusDeleted LoginStatus = "deleted" // StatusRetry means a transient error occurred and the check should be retried StatusRetry LoginStatus = "retry" )
type MockClient ¶
type MockClient struct {
// contains filtered or unexported fields
}
MockClient is a mock implementation of Client for testing. It returns predefined responses without making HTTP calls.
func NewMockClient ¶
func NewMockClient() *MockClient
NewMockClient creates a new mock client with no predefined responses. By default, it returns StatusValidated for any login. Use SetResponse to configure specific responses.
func (*MockClient) CallCount ¶
func (m *MockClient) CallCount() int
CallCount returns the number of times CheckLogin was called.
func (*MockClient) CalledLogins ¶
func (m *MockClient) CalledLogins() []string
CalledLogins returns a list of logins that were checked, in order. This is useful for verifying that the worker processed logins in the expected sequence.
func (*MockClient) CheckLogin ¶
func (m *MockClient) CheckLogin(ctx context.Context, login string) (*LoginResult, error)
CheckLogin checks a login and returns the configured result. If no specific result was configured for this login, returns the default result.
func (*MockClient) Reset ¶
func (m *MockClient) Reset()
Reset clears all configured responses and call history.
func (*MockClient) SetDefaultResult ¶
func (m *MockClient) SetDefaultResult(result *LoginResult)
SetDefaultResult configures the default result returned for logins without specific responses configured via SetResponse.
func (*MockClient) SetResponse ¶
func (m *MockClient) SetResponse(login string, result *LoginResult)
SetResponse configures the mock to return a specific result for a given login.
Example:
mock.SetResponse("old-name", &LoginResult{
Status: StatusRenamed,
NewLogin: strPtr("new-name"),
})
mock.SetResponse("deleted-user", &LoginResult{
Status: StatusDeleted,
})
func (*MockClient) WasCalled ¶
func (m *MockClient) WasCalled(login string) bool
WasCalled checks if a specific login was queried.