Documentation
¶
Overview ¶
Package sheets is an in-memory fake of the parts of the Google Sheets v4 and Drive v3 APIs that leadscore uses: spreadsheet create and get, batchUpdate with the requests the Sheets store sends, values get and batchGet, and Drive permissions. It is an http.Handler, so a test serves it with httptest and points a store's `base_url` at it.
It keeps the real API's rules that the store depends on: a batchUpdate is all-or-nothing, tab names are unique, appendCells writes after the last row with data, a tab cannot lose all its non-frozen rows or freeze all its rows, a cell holds at most 50,000 characters, a workbook at most 10 million cells, and a request body at most 10 MB. Reads trim trailing empty rows and cells, a range naming a missing tab is "Unable to parse range", and a range starting below the grid "exceeds grid limits". Tab names match ignoring case.
Formulas are not evaluated: a formula cell reads back as its formula text.
Index ¶
- Constants
- type Server
- func (s *Server) AddPermission(id, email, role string)
- func (s *Server) BlockSharing(id, msg string)
- func (s *Server) Calls(kind string) int
- func (s *Server) Cell(id, title, a1 string) string
- func (s *Server) ConditionalFormats(id, title string) []*sheetsapi.ConditionalFormatRule
- func (s *Server) DeleteTab(id, title string)
- func (s *Server) Deny(id string, denied bool)
- func (s *Server) FailAbout(fail bool)
- func (s *Server) IDs() []string
- func (s *Server) InsertRow(id, title string, at int, values []string)
- func (s *Server) IsFormula(id, title, a1 string) bool
- func (s *Server) NewSpreadsheet(title string) string
- func (s *Server) Note(id, title, a1 string) string
- func (s *Server) OnBatchUpdate(f func())
- func (s *Server) OnValuesRead(f func())
- func (s *Server) Permissions(id string) []*drive.Permission
- func (s *Server) Put(id, title string, rows [][]any) error
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) SetCaller(email string)
- func (s *Server) SlowDown(n int)
- func (s *Server) Spreadsheet(id string) *sheetsapi.Spreadsheet
- func (s *Server) SwapRows(id, title string, a, b int)
- func (s *Server) ValueReads() []string
- func (s *Server) WritersCanShare(id string) bool
Constants ¶
const ( MaxCellChars = 50_000 MaxCells = 10_000_000 MaxBodyBytes = 10 << 20 )
Limits the real API enforces.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the fake. The zero value is not usable; call New.
func (*Server) AddPermission ¶
AddPermission shares a spreadsheet with an account in a role, by hand.
func (*Server) BlockSharing ¶
BlockSharing makes sharing the spreadsheet (every spreadsheet, for an empty id) fail with Drive's 403 and msg, as a Workspace sharing policy does. An empty msg allows sharing again.
func (*Server) Calls ¶
Calls returns how many calls of a kind were served: "create", "get", "batchUpdate", "values" (get and batchGet) or "permissions".
func (*Server) Cell ¶
Cell returns the text of one cell given in A1 form ("H1"), a formula as its formula text; "" when empty or missing.
func (*Server) ConditionalFormats ¶
func (s *Server) ConditionalFormats(id, title string) []*sheetsapi.ConditionalFormatRule
ConditionalFormats returns a tab's conditional format rules.
func (*Server) Deny ¶
Deny makes every call on the spreadsheet answer 403, as when it is not shared with the caller.
func (*Server) InsertRow ¶
InsertRow inserts a row of text at a zero-based row index, as a person inserting a row (or sorting) would, shifting the rows below down.
func (*Server) IsFormula ¶
IsFormula reports whether a cell (A1 form) holds a formula rather than text.
func (*Server) NewSpreadsheet ¶
NewSpreadsheet creates an empty spreadsheet with one tab, "Sheet1", as the real API does, and returns its id.
func (*Server) OnBatchUpdate ¶
func (s *Server) OnBatchUpdate(f func())
OnBatchUpdate sets f to run before each batchUpdate is applied, outside the fake's lock, so it can change the spreadsheet as a person editing it at that moment would.
func (*Server) OnValuesRead ¶
func (s *Server) OnValuesRead(f func())
OnValuesRead sets f to run before each values get or batchGet, outside the fake's lock.
func (*Server) Permissions ¶
func (s *Server) Permissions(id string) []*drive.Permission
Permissions returns the Drive permissions made on a spreadsheet.
func (*Server) Put ¶
Put writes rows into a tab as a person typing would, creating the tab when missing and growing it to fit. A value is a string, a float64, an int or a bool; a string starting with "=" is a formula.
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP routes the Sheets v4 and Drive v3 paths the store uses.
func (*Server) SlowDown ¶
SlowDown makes the next n calls answer 429 RESOURCE_EXHAUSTED, Google's "slow down".
func (*Server) Spreadsheet ¶
func (s *Server) Spreadsheet(id string) *sheetsapi.Spreadsheet
Spreadsheet returns a copy of a spreadsheet's properties and tabs (with their protected ranges), as spreadsheets.get returns them; nil when missing.
func (*Server) ValueReads ¶
ValueReads returns every range read through values get and batchGet, as "<valueRenderOption> <range>", in order.
func (*Server) WritersCanShare ¶
WritersCanShare reports Drive's writersCanShare setting for a spreadsheet.