Skip to content

refactor: define interfaces for Google API clients to enable unit testing #35

@rianjs

Description

@rianjs

Summary

Critical testability blocker. Direct dependency on concrete Google API types makes unit testing impossible. All command tests require real API credentials.

Current State

  • gmail.Client.Service is *gmail.Service (concrete)
  • calendar.Client.Service is *calendar.Service (concrete)
  • contacts.Client.Service is *people.Service (concrete)
  • No way to inject mocks

Files:

  • internal/gmail/client.go:28-32
  • internal/calendar/client.go:25-26
  • internal/contacts/client.go:22-23

Problems

  1. Cannot swap implementations (mock, different versions)
  2. Cannot add caching, rate limiting, or circuit breakers without touching all call sites
  3. Tests require real Google services

Proposed Solution

Define interfaces for each service:

type GmailService interface {
    GetMessage(userID, messageID string) (*Message, error)
    SearchMessages(userID, query string, maxResults int64) ([]*Message, error)
    GetThread(userID, threadID string) (*Thread, error)
    // ...
}

Make Service field private, expose only through interface.

Priority

P0 - Critical for testability

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions