gmailapitest

package
v1.39.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gmailapitest is an in-process fake Gmail REST API v1 server for backend contract tests and coretest end-to-end tests, with zero external network dependency.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Delivery

type Delivery struct {
	Rcpts []string
	Raw   []byte
}

Delivery is one message accepted by users.messages.send.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is an in-process fake Gmail REST API v1 server for one account.

func Start

func Start(tb testing.TB) *Server

Start starts a new fake Gmail API server, closed when tb ends.

func (*Server) Accepted

func (s *Server) Accepted() []Delivery

Accepted returns all messages accepted by messages.send, in order.

func (*Server) AddMessage

func (s *Server) AddMessage(raw []byte, labelNamesOrIDs ...string) string

AddMessage adds a message with the given label names or IDs (such as "INBOX", "UNREAD", "Work") and returns its Gmail message ID.

func (*Server) DeleteLabel

func (s *Server) DeleteLabel(id string)

DeleteLabel deletes a user label and removes it from all messages.

func (*Server) DeleteMessage

func (s *Server) DeleteMessage(msgID string)

DeleteMessage permanently deletes msgID on the server, recording messagesDeleted.

func (*Server) Deliver

func (s *Server) Deliver(folder string, raw []byte) string

Deliver delivers raw as a new unread message into folder (creating a user label if needed).

func (*Server) EnsureLabel

func (s *Server) EnsureLabel(name string) string

EnsureLabel returns the label ID for name, creating a user label if needed.

func (*Server) ExpireHistory

func (s *Server) ExpireHistory()

ExpireHistory invalidates all historyIds issued so far so history.list returns 404.

func (*Server) HostPort

func (s *Server) HostPort() (string, int)

HostPort is the listener's host and port.

func (*Server) ListMessageRequests

func (s *Server) ListMessageRequests() int

ListMessageRequests returns how many messages.list HTTP calls the server handled.

func (*Server) LoseVerdict

func (s *Server) LoseVerdict()

LoseVerdict makes the next messages.send drop the TCP connection after reading the body.

func (*Server) MaxInFlight

func (s *Server) MaxInFlight() int

MaxInFlight returns the peak concurrent requests observed by the server.

func (*Server) MessageLabels

func (s *Server) MessageLabels(msgID string) []string

MessageLabels returns a copy of msgID's current label IDs, or nil if deleted.

func (*Server) ModifyLabels

func (s *Server) ModifyLabels(msgID string, add, remove []string)

ModifyLabels adds and removes labels (by name or ID) on msgID, as webmail would.

func (*Server) Refuse

func (s *Server) Refuse(rcpt string)

Refuse makes messages.send permanently reject mail addressed to rcpt.

func (*Server) RejectAuth

func (s *Server) RejectAuth()

RejectAuth makes every request fail with 401 Unauthorized.

func (*Server) RenameLabel

func (s *Server) RenameLabel(id, newName string)

RenameLabel renames an existing user label while preserving its ID.

func (*Server) SetAPIDisabled

func (s *Server) SetAPIDisabled(disabled bool)

SetAPIDisabled makes every request fail with 403 accessNotConfigured.

func (*Server) SetEmail

func (s *Server) SetEmail(email string)

SetEmail sets the address getProfile reports.

func (*Server) SetPageLimit

func (s *Server) SetPageLimit(n int)

SetPageLimit caps list/history page sizes to test pagination.

func (*Server) SetTokenValidator

func (s *Server) SetTokenValidator(fn func(string) bool)

SetTokenValidator sets a custom Bearer token check (such as testoauth's).

func (*Server) ThrottleNext

func (s *Server) ThrottleNext(n, status int, retryAfter string)

ThrottleNext makes the next n authenticated requests return status (429 or 403 rateLimitExceeded) with optional Retry-After header before succeeding.

func (*Server) Token

func (s *Server) Token() string

Token is the default valid Bearer token when SetTokenValidator is not set.

func (*Server) URL

func (s *Server) URL() string

URL is the server's base URL (http://127.0.0.1:port).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL