testdrive

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package testdrive is an internal httptest fixture for Drive, Docs, and Sheets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(t testing.TB, fx *FX, holder *vfs.TokenHolder) vfs.Open

Open builds Drive, Docs, and Sheets clients against this fixture over httptest.

Types

type FX

type FX struct {
	Nodes   map[string]*Node
	Exports int
	// contains filtered or unexported fields
}

FX is an in-memory Drive tree that speaks Drive v3, Docs, and Sheets HTTP.

func New

func New() *FX

New returns an empty fixture.

func Tree

func Tree() *FX

Tree is the shared Drive fixture used by mount tests.

func (*FX) Add

func (d *FX) Add(parent string, meta vfs.DriveMeta, body []byte)

Add inserts a node.

func (*FX) Fail added in v0.5.0

func (d *FX) Fail(f Fault)

Fail plans f. The faults that match one call occur in the order they were planned.

func (*FX) FailDocBatch

func (d *FX) FailDocBatch()

FailDocBatch makes the next documents.batchUpdate call return HTTP 400 (ErrInvalidWrite).

func (*FX) FailNextDocWrites

func (d *FX) FailNextDocWrites(n int)

FailNextDocWrites makes the next n documents.batchUpdate calls return a revision conflict.

func (*FX) SeedDoc

func (d *FX) SeedDoc(id, rev string, spans []vfs.DocsSpan, tabs []vfs.DocTab)

SeedDoc sets documents.get state for id.

func (*FX) SeedSheet

func (d *FX) SeedSheet(id string, snap vfs.SheetsSnapshot)

SeedSheet sets spreadsheets.get state for id.

func (*FX) ServeHTTP

func (d *FX) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP answers the Drive v3, Docs v1 and Sheets v4 calls of the vfs clients. A request with no bearer token gets 401.

func (*FX) SetDocRev

func (d *FX) SetDocRev(id, rev string)

SetDocRev is an out-of-band revision bump (CAS tests).

func (*FX) SheetSnap

func (d *FX) SheetSnap(id string) vfs.SheetsSnapshot

SheetSnap is a copy of the seeded workbook (CAS / out-of-band mutation tests).

type Fault added in v0.5.0

type Fault struct {
	// Call is the API method that fails: files.get, files.media,
	// files.list, files.export, files.create, files.update, documents.get,
	// documents.batchUpdate, spreadsheets.get, spreadsheets.batchUpdate or
	// spreadsheets.values.batchUpdate.
	Call string
	// ID is the file, document or spreadsheet the call names (the folder
	// for files.list). An empty ID matches every call.
	ID string
	// Skip is the number of matching calls that pass before the fault.
	Skip int
	// Status is the HTTP status of the Google error reply.
	Status int
	// Message is the message of the Google error reply.
	Message string
	// Cut answers 200 and then drops the connection in the body. It is
	// for drops: a request that gets no reply at all is sent again by
	// net/http, so the call does not fail.
	Cut bool
	// Then runs when the fault occurs, before the reply.
	Then func()
}

Fault is one planned failure of a call to the fixture.

type Node

type Node struct {
	Meta   vfs.DriveMeta
	Parent string
	Body   []byte
	Export []byte
}

Node is one Drive file or folder in the fixture.

Jump to

Keyboard shortcuts

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