Documentation
¶
Overview ¶
Package mongofake is a fake of a MongoDB server for the tests of the MongoDB flag source: it speaks the wire protocol (OP_MSG, and the OP_QUERY of the first handshake) on a loopback port, and answers hello, ping, find (sorted by _id, in batches), getMore, killCursors, listCollections and endSessions from collections it keeps in memory. A client that uses authMechanism=PLAIN can log in; the other mechanisms are refused. What it models is from the documentation of the protocol and the behaviour of the Go driver; it is no MongoDB: the docker tests of the flag source run the real server.
Index ¶
- type Fault
- type Server
- func (s *Server) Close()
- func (s *Server) Commands() []string
- func (s *Server) Drop(database, collection string)
- func (s *Server) Hold(hook func(context.Context) error)
- func (s *Server) Host() string
- func (s *Server) Inject(fault Fault)
- func (s *Server) InjectOn(command string, fault Fault)
- func (s *Server) OpenCursors() int
- func (s *Server) Require(user, password string)
- func (s *Server) Set(database, collection string, docs ...bson.D)
- func (s *Server) URI() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Fault ¶
type Fault int
Fault is what the server does with the next data commands (find, getMore, listCollections).
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a MongoDB fake on a loopback port. Its listener is open from New on.
func NewTLS ¶
NewTLS starts a server that speaks TLS with the configuration (its certificate and its versions). The URI of the server asks for TLS: tls=true.
func (*Server) Close ¶
func (s *Server) Close()
Close stops the server and closes its connections. It is safe to call twice.
func (*Server) Commands ¶
Commands are the data commands the server received so far, as "name database.collection" (listCollections as "listCollections database").
func (*Server) Hold ¶
Hold makes the data commands wait for hook before they are answered; a hook that returns an error closes the connection. The context of the hook ends when the connection or the server closes. Nil removes the hold.
func (*Server) Inject ¶
Inject makes the data commands fail the way the fault says until it is called again with FaultNone.
func (*Server) InjectOn ¶
InjectOn is Server.Inject for one command (find, getMore or listCollections); the fault of the command wins over the one of Inject.
func (*Server) OpenCursors ¶
OpenCursors is the number of cursors that the server still keeps: a cursor is kept for the documents that no batch has carried yet, and ends when its last batch is read or when the client kills it.
func (*Server) Require ¶
Require makes the server ask for a login: the user and the password of authMechanism=PLAIN. The URI of such a client is "mongodb://user:password@host/?authMechanism=PLAIN".