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 ¶
- type Drive
- type Request
- type Server
- func (s *Server) AcceptToken(f func(string) bool)
- func (s *Server) AddDrive(id string) *Drive
- func (s *Server) AddSiteDrive(site, id string) *Drive
- func (s *Server) AddToken(tok string)
- func (s *Server) BaseURL() string
- func (s *Server) NotificationBody(subID string) []byte
- func (s *Server) Requests() []Request
- func (s *Server) SetMe(id string)
- func (s *Server) Subscriptions() map[string]Subscription
- type Subscription
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
Allow limits the drive as Grant does, to tokens f approves, such as an entratest token issued to one person.
func (*Drive) Grant ¶ added in v0.7.31
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 ¶
KeepVersions sets whether a change keeps the old content in the file's version history.
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 (*Server) AcceptToken ¶
AcceptToken also accepts any token f approves.
func (*Server) AddSiteDrive ¶
AddSiteDrive makes a drive reachable as /sites/{site}/drives/{id} and /drives/{id}.
func (*Server) NotificationBody ¶
NotificationBody is the JSON Graph POSTs to a subscription's notificationUrl after a change in its drive.
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.