Documentation
¶
Overview ¶
Package testserver implements a barebone Mastodon server for testing.
Index ¶
- func NewFakeAccount(accountID mastodon.ID, username string) mastodon.Account
- func NewFakeNotification(notifID mastodon.ID, notifType string, accountSrcID mastodon.ID, ...) *mastodon.Notification
- func NewFakeStatus(statusID mastodon.ID, accountID mastodon.ID) *mastodon.Status
- func NewHTTPErrorf(status int, format string, a ...any) error
- func WriteError(w http.ResponseWriter, req *http.Request, err error)
- type Entity
- type EntityList
- func (list *EntityList[T]) ByID(id string) (T, error)
- func (list *EntityList[T]) Clear()
- func (list *EntityList[T]) CreateNextID() string
- func (list *EntityList[T]) Insert(value T, id string) error
- func (list *EntityList[T]) List(req *http.Request, linkPath string) ([]T, string, error)
- func (list *EntityList[T]) Update(id string, t T) error
- type HTTPError
- type JSONHandler
- type LoggingHandler
- type Server
- func (s *Server) AddFakeNotification() error
- func (s *Server) AddFakeStatus() (*mastodon.Status, error)
- func (s *Server) AddJSONStatuses(statusesFS fs.FS) error
- func (s *Server) AddReblog(idToReblog mastodon.ID) (*mastodon.Status, error)
- func (s *Server) ClearNotifications()
- func (s *Server) RegisterOn(mux *http.ServeMux)
- func (s *Server) SetListDelay(delay time.Duration)
- func (s *Server) SetStatusContent(id mastodon.ID, content string) error
- func (s *Server) SetStatusFavourite(id mastodon.ID) error
- func (s *Server) SetStatusUnfavourite(id mastodon.ID) error
- func (s *Server) UpdateStatus(status *mastodon.Status) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewFakeNotification ¶
func NewFakeStatus ¶
func WriteError ¶
func WriteError(w http.ResponseWriter, req *http.Request, err error)
Types ¶
type EntityList ¶
type EntityList[T any] struct { // contains filtered or unexported fields }
EntityList manages a sorted list, suitable for being queried with pagination.
func (*EntityList[T]) ByID ¶
func (list *EntityList[T]) ByID(id string) (T, error)
ByID returns the entity with that ID. Returns the default value if not found.
func (*EntityList[T]) Clear ¶
func (list *EntityList[T]) Clear()
func (*EntityList[T]) CreateNextID ¶
func (list *EntityList[T]) CreateNextID() string
CreateNextID gives back an ID suitable for this list which would insert an entity at the end of the list. The ID is not reserved, so multiple call to this function without insertion might return the same value.
func (*EntityList[T]) Insert ¶
func (list *EntityList[T]) Insert(value T, id string) error
Insert a new value in the list, keeping it sorted.
func (*EntityList[T]) List ¶
List manages a listing requests as a mastodon server. It takes care of pagination, and returns:
- The list of matching values
- The content for the `Link` header (can be empty)
- or an error
func (*EntityList[T]) Update ¶
func (list *EntityList[T]) Update(id string, t T) error
Update changes in-place the value of an entity.
type JSONHandler ¶
func (JSONHandler) ServeHTTP ¶
func (h JSONHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
type LoggingHandler ¶
type LoggingHandler struct {
Logf func(format string, args ...any)
Handler http.Handler
// contains filtered or unexported fields
}
LoggingHandler is an intercept http handler which writes http traffic on the provided testing construct.
func (*LoggingHandler) ServeHTTP ¶
func (h *LoggingHandler) ServeHTTP(writer http.ResponseWriter, req *http.Request)
type Server ¶
type Server struct {
// If present, block on list request.
// When a request arrives, it will send a `chan struct{}` over the provided channel.
// The receiver must then close the sent channel to indicate that the test server
// can continue serving.
// Must be set before any request is started.
TestBlockList chan chan struct{}
// contains filtered or unexported fields
}
func (*Server) AddFakeNotification ¶
func (*Server) AddReblog ¶
AddReblog creates a reblog of the provided status ID. If the status ID does not already exists, create one.
func (*Server) ClearNotifications ¶
func (s *Server) ClearNotifications()