MockAPI is a mock implementation of the Gmail API for testing.
| 8 | |
| 9 | // MockAPI is a mock implementation of the Gmail API for testing. |
| 10 | type MockAPI struct { |
| 11 | mu sync.Mutex |
| 12 | |
| 13 | // Profile to return |
| 14 | Profile *Profile |
| 15 | |
| 16 | // Labels to return |
| 17 | Labels []*Label |
| 18 | |
| 19 | // Messages indexed by ID |
| 20 | Messages map[string]*RawMessage |
| 21 | |
| 22 | // Message list pages - each page is a list of message IDs |
| 23 | MessagePages [][]string |
| 24 | |
| 25 | // History records |
| 26 | HistoryRecords []HistoryRecord |
| 27 | HistoryID uint64 |
| 28 | |
| 29 | // UseRawThreadID uses the ThreadID from RawMessage instead of generating "thread_" + id |
| 30 | UseRawThreadID bool |
| 31 | |
| 32 | // ListThreadIDOverride overrides the threadID returned by ListMessages for specific message IDs. |
| 33 | // This allows testing the case where list returns empty threadID but raw message has one. |
| 34 | ListThreadIDOverride map[string]string |
| 35 | |
| 36 | // Error injection |
| 37 | ProfileError error |
| 38 | LabelsError error |
| 39 | ListMessagesError error |
| 40 | GetMessageError map[string]error // Per-message errors |
| 41 | HistoryError error |
| 42 | |
| 43 | // Call tracking for assertions |
| 44 | ProfileCalls int |
| 45 | LabelsCalls int |
| 46 | ListMessagesCalls int |
| 47 | LastQuery string // Last query passed to ListMessages |
| 48 | GetMessageCalls []string |
| 49 | HistoryCalls []uint64 |
| 50 | TrashCalls []string |
| 51 | DeleteCalls []string |
| 52 | BatchDeleteCalls [][]string |
| 53 | } |
| 54 | |
| 55 | // NewMockAPI creates a new mock API with empty state. |
| 56 | func NewMockAPI() *MockAPI { |
nothing calls this directly
no outgoing calls
no test coverage detected