mirror of
https://github.com/sstent/go-garminconnect.git
synced 2025-12-05 23:52:03 +00:00
2.2 KiB
2.2 KiB
Mock Authenticator Implementation Tasks
Overview
Implement a shared MockAuthenticator to fix test failures caused by:
- Improper interface implementation in tests
- Duplicate mock implementations across files
- Inconsistent test client creation patterns
Tasks
Phase 1: Create Shared Test Helper (test_helpers.go)
package api
type MockAuthenticator struct {
RefreshTokenFunc func(oauth1Token, oauth1Secret string) (string, error)
CallCount int
}
func (m *MockAuthenticator) RefreshToken(oauth1Token, oauth1Secret string) (string, error) {
m.CallCount++
if m.RefreshTokenFunc != nil {
return m.RefreshTokenFunc(oauth1Token, oauth1Secret)
}
return "refreshed-test-token", nil
}
func NewMockAuthenticator() *MockAuthenticator {
return &MockAuthenticator{}
}
func NewMockAuthenticatorWithFunc(refreshFunc func(string, string) (string, error)) *MockAuthenticator {
return &MockAuthenticator{
RefreshTokenFunc: refreshFunc,
}
}
Phase 2: Update Test Files
-
bodycomposition_test.go
Replace existing mock with:mockAuth := NewMockAuthenticator() -
gear_test.go
RemovemockAuthImpldefinition and use:mockAuth := NewMockAuthenticator() -
health_test.go
Update client creation:mockAuth := NewMockAuthenticator() client, err := NewClient(mockAuth, session, "") -
user_test.go
Update client creation:mockAuth := NewMockAuthenticator() client, err := NewClient(mockAuth, session, "") -
mock_server_test.go
UpdateNewClientWithBaseURL:auth := NewMockAuthenticator()
Phase 3: Verification
- Run tests:
go test ./internal/api/... - Fix any remaining compilation errors
- Verify all tests pass
- Check for consistent mock usage across all test files
Progress Tracking
- test_helpers.go created
- bodycomposition_test.go updated
- gear_test.go updated
- health_test.go updated
- user_test.go updated
- mock_server_test.go updated
- integration_test.go updated
- Run tests:
go test ./internal/api/... - Verify all tests pass