graphtest

package
v0.7.39 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 11 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 a fake Microsoft Graph for tests of code that reads SharePoint and OneDrive drives: the msgraph mount driver, and an app's own tests. It serves the routes the driver uses over drives held in memory: a folder's children, paged with @odata.nextLink; an item by path or id; its content, through a redirect to a download URL as Graph does; its version history and a version's content; the drive's delta feed; and subscriptions.

A drive is reachable as /drives/{id}, as /sites/{site}/drives/{id} after AddSiteDrive, and as /me/drive after SetMe. Every route needs a bearer token the fake accepts (AddToken, or AcceptToken for tokens another fake issued, such as connections/entratest's), and answers 401 otherwise.

Drive.Put changes a file as another writer would. With versions kept, the default, the file's old content stays in its version history. Each change moves the file's eTag and cTag and its last-modified time, and is recorded for the delta feed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Drive

type Drive struct {
	ID string
	// contains filtered or unexported fields
}

Drive is one drive in the fake.

func (*Drive) Allow added in v0.7.31

func (d *Drive) Allow(f func(token string) bool)

Allow limits the drive as Grant does, to tokens f approves, such as an entratest token issued to one person.

func (*Drive) Delete

func (d *Drive) Delete(p string)

Delete removes the file at p.

func (*Drive) Grant added in v0.7.31

func (d *Drive) Grant(tokens ...string)

Grant limits the drive to tokens, and to whatever Allow approves. Once the drive has a grant or an Allow, any other accepted token gets 403 accessDenied on its routes, as SharePoint answers a person who can't open a library. A drive with neither answers every accepted token.

func (*Drive) KeepVersions

func (d *Drive) KeepVersions(on bool)

KeepVersions sets whether a change keeps the old content in the file's version history.

func (*Drive) Put

func (d *Drive) Put(p, content string)

Put writes content at p, making the folders on the way.

type Request

type Request struct {
	Method string
	Path   string
	Token  string
}

Request is one request the fake answered.

type Server

type Server struct {
	*httptest.Server

	// PageSize is how many children one listing page holds. It defaults to 2, so a test of a
	// small folder still follows @odata.nextLink.
	PageSize int
	// contains filtered or unexported fields
}

Server is the fake. Its URL plus "/v1.0" is the base a driver is pointed at.

func New

func New(t testing.TB) *Server

New starts a fake and stops it when the test ends.

func (*Server) AcceptToken

func (s *Server) AcceptToken(f func(string) bool)

AcceptToken also accepts any token f approves.

func (*Server) AddDrive

func (s *Server) AddDrive(id string) *Drive

AddDrive makes an empty drive that keeps versions.

func (*Server) AddSiteDrive

func (s *Server) AddSiteDrive(site, id string) *Drive

AddSiteDrive makes a drive reachable as /sites/{site}/drives/{id} and /drives/{id}.

func (*Server) AddToken

func (s *Server) AddToken(tok string)

AddToken makes tok an accepted token.

func (*Server) BaseURL

func (s *Server) BaseURL() string

BaseURL is the Graph root a driver is pointed at with msgraph.WithBaseURL.

func (*Server) NotificationBody

func (s *Server) NotificationBody(subID string) []byte

NotificationBody is the JSON Graph POSTs to a subscription's notificationUrl after a change in its drive.

func (*Server) Requests

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

Requests returns every request answered so far, oldest first.

func (*Server) SetMe

func (s *Server) SetMe(id string)

SetMe makes /me/drive the drive id.

func (*Server) Subscriptions

func (s *Server) Subscriptions() map[string]Subscription

Subscriptions returns the live subscriptions, by ID.

type Subscription

type Subscription struct {
	ID              string `json:"id"`
	Resource        string `json:"resource"`
	ChangeType      string `json:"changeType"`
	NotificationURL string `json:"notificationUrl"`
	ClientState     string `json:"clientState"`
	Expires         string `json:"expirationDateTime"`
}

Subscription is a subscription made through the fake.

Jump to

Keyboard shortcuts

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