graphtest

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 14 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 graphtest is an in-process Microsoft Graph for tests of Graph sync (docs/design/pim.md, Microsoft Graph), as davtest is for DAV: the account's calendars and contact folders in memory, delta rounds with tokens and pages, series read with their exceptions, contact photos, Graph's writes, and hooks that play another client's changes. It answers as Graph did the probe of an Outlook.com account (plan 0010, Phase 1).

Index

Constants

View Source
const PageSize = 2

PageSize is how many items a page holds, small so tests page.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	URL   string // the base URL, as graph.BaseURL
	Token string // the bearer token it accepts
	// User is the account's address, the organizer of the events it
	// creates; "" names none.
	User string

	// Requests counts requests by method and path, without the query.
	Requests map[string]int
	// contains filtered or unexported fields
}

Server is the fake Graph.

func Start

func Start(t testing.TB, token string) *Server

Start runs a server that accepts token, with a default calendar ("cal-1", "Calendar") and the default contact folder.

func (*Server) AddCalendar

func (s *Server) AddCalendar(id, name string, canEdit bool)

AddCalendar adds a calendar.

func (*Server) Contact

func (s *Server) Contact(id string) (map[string]any, []byte)

Contact returns a contact's JSON as stored and its photo, or nil.

func (*Server) DeleteContact

func (s *Server) DeleteContact(folderID, id string)

DeleteContact deletes a contact.

func (*Server) DeleteEvent

func (s *Server) DeleteEvent(calendarID, id string)

DeleteEvent deletes an event or a series.

func (*Server) Event

func (s *Server) Event(id string) map[string]any

Event returns an event's or a series' JSON as stored, or nil.

func (*Server) Events

func (s *Server) Events(calendarID string) []string

Events returns a calendar's live events' IDs, sorted, for assertions.

func (*Server) OnWrite

func (s *Server) OnWrite(f func(method, path string))

OnWrite calls f before each write the server answers, as another client's change or the user's next edit would come; nil stops it. f runs without the server's lock.

func (*Server) PutContact

func (s *Server) PutContact(folderID, contact string, photo []byte)

PutContact stores a contact in a folder ("contacts" is the default), with photo when it is not nil.

func (*Server) PutEvent

func (s *Server) PutEvent(calendarID, event string)

PutEvent stores an event (a single event, or a master with "exceptionOccurrences") in a calendar, as another client would. The event's "id" names it; its change key and ETag are set here.

func (*Server) Throttle

func (s *Server) Throttle(n int)

Throttle answers the next n requests with 429 and Retry-After: 0.

func (*Server) WriteCount

func (s *Server) WriteCount() int

WriteCount is how many writes the server took.

func (*Server) WritesSince

func (s *Server) WritesSince(n int) []string

WritesSince returns the writes after the first n.

type Write

type Write struct {
	Method, Path, IfMatch, Body string
}

Write is a write the server took, for assertions: Body is the JSON sent, its keys sorted.

func (Write) String

func (w Write) String() string

Jump to

Keyboard shortcuts

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