Documentation ¶
Overview ¶
Package client provides a remote.Client implementation that makes requests to cozy-stack. It also provides a fake implementation that mocks it for tests.
Index ¶
- type Change
- type Client
- func (c *Client) Changes(seq *remote.Seq, limit int, skipTrashed bool) (*remote.ChangesResponse, error)
- func (c *Client) CreateDir(parentID remote.ID, name string) (*remote.Doc, error)
- func (c *Client) DocsByID() map[remote.ID]*remote.Doc
- func (c *Client) EmptyTrash() error
- func (c *Client) NewRequest(verb, path string) *request
- func (c *Client) Refresh() error
- func (c *Client) Register() error
- func (c *Client) Synchronized() error
- func (c *Client) Trash(doc *remote.Doc) (*remote.Doc, error)
- type Fake
- func (f *Fake) AddInitialDocs(changed ...*remote.ChangedDoc)
- func (f *Fake) Changes(seq *remote.Seq, limit int, skipTrashed bool) (*remote.ChangesResponse, error)
- func (f *Fake) CheckInvariants() error
- func (f *Fake) CreateDir(parentID remote.ID, name string) (*remote.Doc, error)
- func (f *Fake) DocsByID() map[remote.ID]*remote.Doc
- func (f *Fake) EmptyTrash() error
- func (f *Fake) MatchSequence(seq remote.Seq)
- func (f *Fake) Refresh() error
- func (f *Fake) Synchronized() error
- func (f *Fake) Trash(doc *remote.Doc) (*remote.Doc, error)
- type Instance
- type ReadOnly
- func (ro *ReadOnly) Changes(seq *remote.Seq, limit int, skipTrashed bool) (*remote.ChangesResponse, error)
- func (ro *ReadOnly) CreateDir(parentID remote.ID, name string) (*remote.Doc, error)
- func (ro *ReadOnly) EmptyTrash() error
- func (ro *ReadOnly) Refresh() error
- func (ro *ReadOnly) Synchronized() error
- func (ro *ReadOnly) Trash(doc *remote.Doc) (*remote.Doc, error)
- type Stack
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Change ¶
type Change struct { Seq int *remote.ChangedDoc Skip bool }
Change describes an entry in the changes feed of a fake stack/client.
type Client ¶
type Client struct { Address string ClientID string ClientSecret string AccessToken string RefreshToken string Client *http.Client }
Client is a client for cozy-stack.
func (*Client) Changes ¶
func (c *Client) Changes(seq *remote.Seq, limit int, skipTrashed bool) (*remote.ChangesResponse, error)
Changes is required by the remote.Client interface.
Note: the design docs are ignored
func (*Client) EmptyTrash ¶
EmptyTrash is required by remote.Client interface.
func (*Client) NewRequest ¶
NewRequest creates a request representation that can be forged to send an HTTP request to the stack.
func (*Client) Synchronized ¶
Synchronized is required by the remote.Client interface.
type Fake ¶
type Fake struct { Address string SyncCount int ByID map[remote.ID]*remote.Doc Feed []Change // Those functions can be overloaded for some tests where we want to // control the values. GenerateID func() remote.ID GenerateRev func(id remote.ID, generation int) remote.Rev GenerateSeq func(generation int) remote.Seq ConflictName func(id remote.ID, name string) string }
Fake can be used to simulate a cozy-stack client (and the stack its-self) for tests.
TODO find a way to simulate latency
func NewFake ¶
NewFake creates a fake client that can be used for tests. It doesn't make any HTTP request, it just simulate them via an in-memory mock.
func (*Fake) AddInitialDocs ¶
func (f *Fake) AddInitialDocs(changed ...*remote.ChangedDoc)
AddInitialDocs will create the tree for a new instance (root, trash, etc.).
func (*Fake) Changes ¶
func (f *Fake) Changes(seq *remote.Seq, limit int, skipTrashed bool) (*remote.ChangesResponse, error)
Changes is required by the remote.Client interface.
func (*Fake) CheckInvariants ¶
CheckInvariants checks that we don't have inconsistencies in the fake client. It can be used as a way to detect some bugs in the Fake code.
func (*Fake) EmptyTrash ¶
EmptyTrash is required by remote.Client interface.
func (*Fake) MatchSequence ¶
MatchSequence will create dumb entries in the changes feed until it reaches the given sequence generation number. It is used to compensate for the lack of design docs.
func (*Fake) Synchronized ¶
Synchronized is required by the remote.Client interface.
type Instance ¶
Instance describes a cozy instance on a stack.
func (*Instance) Address ¶
Address return the http address that can be used to access this instance.
func (*Instance) CreateAccessToken ¶
CreateAccessToken runs a cozy-stack command to create an access token for the given client (admin endpoint, no user interaction).
type ReadOnly ¶
type ReadOnly struct {
Fake *Fake
}
func NewReadOnly ¶
NewReadOnly returns a mock of a cozy-stack client that can be used in tests, and it panics if any write operation is called.
func (*ReadOnly) Changes ¶
func (ro *ReadOnly) Changes(seq *remote.Seq, limit int, skipTrashed bool) (*remote.ChangesResponse, error)
Changes is required by the remote.Client interface.
func (*ReadOnly) EmptyTrash ¶
EmptyTrash is required by the remote.Client interface.
func (*ReadOnly) Synchronized ¶
Synchronized is required by the remote.Client interface.
type Stack ¶
Stack can be used to control a cozy-stack running locally for tests.
func NewStack ¶
NewStack builds a stack object, but you have to call Start on it to run the cozy-stack process.
func (*Stack) CreateInstance ¶
CreateInstance creates an instance with a name like "alice".