davtest

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: 16 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 davtest is an in-process CardDAV and CalDAV server for tests, as imapxtest is for IMAP (docs/design/pim.md): memory collections, ETags, sync tokens over a change log, conditional writes, and hooks to change objects as another client would and to make requests fail.

It serves one user. The principal is PrincipalPath; address books live under ContactsHome and calendars under CalendarsHome, and /.well-known/carddav and caldav redirect to /dav/.

Index

Constants

View Source
const (
	User          = "user"
	Password      = "secret"
	PrincipalPath = "/dav/principals/user/"
	ContactsHome  = "/dav/user/contacts/"
	CalendarsHome = "/dav/user/calendars/"
	// InboxPath is the scheduling inbox, named with ScheduleDefault.
	InboxPath = "/dav/user/inbox/"
)

The server's fixed names.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Bearer, when set, is a token accepted as "Authorization: Bearer …"
	// besides User and Password.
	Bearer string
	// NoSync makes collections neither list nor answer sync-collection.
	NoSync bool
	// NoWellKnown answers /.well-known/ with 404.
	NoWellKnown bool
	// Truncate cuts sync-collection answers after this many changes and
	// marks them 507, as servers with a result limit do; 0 never cuts.
	Truncate int
	// CDATA writes object data in CDATA sections with literal line
	// endings, which XML parsers turn from CRLF into LF.
	CDATA bool
	// NoETagOnPut leaves the ETag header out of PUT responses.
	NoETagOnPut bool
	// ScheduleDefault is the decoded path of the user's default calendar,
	// named by the scheduling inbox (RFC 6638 §9.2); "" names no inbox.
	ScheduleDefault string
	// RelocateCreates stores a new object at a name of the server's
	// choosing, from its UID, and answers 201 with a Location and no ETag,
	// as Google's CalDAV does.
	RelocateCreates bool
	// NoInitialSync answers a sync-collection without a token with 400,
	// as Google's CardDAV does, while still listing the report.
	NoInitialSync bool
	// KeepSequence refuses with 409, as Google's CalDAV does, a calendar
	// object whose highest SEQUENCE is lower than the stored one's.
	KeepSequence bool
}

Options tune the server.

type Request

type Request struct {
	Method string
	Path   string // escaped, as sent
	Depth  string
	Report string // REPORTs: sync-collection, addressbook-multiget or calendar-multiget
	Token  string // sync-collection: the token sent
	Hrefs  int    // multiget: how many hrefs
	Header http.Header
}

Request is one request the server received.

type Server

type Server struct {
	// URL is the server's https:// origin.
	URL string
	// Client trusts the server's certificate.
	Client *http.Client
	// contains filtered or unexported fields
}

Server is a running DAV server.

func New

func New(t testing.TB, opts Options) *Server

New starts a server, stopped when the test ends.

func (*Server) AddressBook

func (s *Server) AddressBook(name, display string) string

AddressBook adds an address book named name (a path segment) and returns its path.

func (*Server) Calendar

func (s *Server) Calendar(name, display, color string, comps ...string) string

Calendar adds a calendar with the components (VEVENT, VTODO; VEVENT when none) and returns its path. color is #rrggbb, or "".

func (*Server) Delete

func (s *Server) Delete(path string)

Delete removes the object at path as another client would.

func (*Server) FailWith

func (s *Server) FailWith(f func(*http.Request) int)

FailWith makes each request for which f returns a status other than 0 fail with that status; nil stops failing. f runs without the server's lock and must not block.

func (*Server) HideFromSync

func (s *Server) HideFromSync(path string)

HideFromSync makes a sync-collection call the object at path deleted, from no token as well, whenever it reports a change to path, while a PROPFIND, a multiget and a GET still serve it: Google does so for a single occurrence whose series is gone.

func (*Server) InvalidateTokens

func (s *Server) InvalidateTokens()

InvalidateTokens makes every sync token handed out so far invalid, as a server that pruned its change log.

func (*Server) Object

func (s *Server) Object(path string) (data []byte, etag string, ok bool)

Object returns the object at path.

func (*Server) Paths

func (s *Server) Paths(coll string) []string

Paths returns the paths of a collection's objects, sorted.

func (*Server) Phantom

func (s *Server) Phantom(path string)

Phantom makes a PROPFIND of path's collection list path with an ETag, while a sync-collection, a multiget and a GET do not have it: Google lists events its sync reports as deleted and does not serve.

func (*Server) Put

func (s *Server) Put(path string, data []byte) string

Put stores data at path, a decoded path inside a collection, as another client would, and returns the new ETag.

func (*Server) RemoveCollection

func (s *Server) RemoveCollection(coll string)

RemoveCollection deletes a collection and its objects.

func (*Server) Rename

func (s *Server) Rename(coll, display string)

Rename changes a collection's display name.

func (*Server) Requests

func (s *Server) Requests() []Request

Requests returns the requests received so far.

func (*Server) ResetRequests

func (s *Server) ResetRequests()

ResetRequests forgets the requests received so far.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

func (*Server) SetReadOnly

func (s *Server) SetReadOnly(coll string, ro bool)

SetReadOnly makes a collection refuse (or accept again) PUT and DELETE.

Jump to

Keyboard shortcuts

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