Documentation ¶
Overview ¶
Package gandalftest provides a fake implementation of the Gandalf API.
Index ¶
- type Failure
- type GandalfServer
- func (s *GandalfServer) Grants() map[string][]string
- func (s *GandalfServer) Keys(user string) (map[string]string, error)
- func (s *GandalfServer) PrepareDiff(repository, content string)
- func (s *GandalfServer) PrepareFailure(failure Failure)
- func (s *GandalfServer) ReadOnlyGrants() map[string][]string
- func (s *GandalfServer) Repositories() []Repository
- func (s *GandalfServer) Reset()
- func (s *GandalfServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *GandalfServer) Stop() error
- func (s *GandalfServer) URL() string
- func (s *GandalfServer) Users() []string
- type Repository
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GandalfServer ¶
type GandalfServer struct { // Host is used for building repositories URLs. Host string // contains filtered or unexported fields }
GandalfServer is a fake gandalf server. An instance of the client can be pointed to the address generated for this server
func NewServer ¶
func NewServer(bind string) (*GandalfServer, error)
NewServer returns an instance of the test server, bound to the specified address. To get a random port, users can specify the :0 port.
Examples:
server, err := NewServer("127.0.0.1:8080") // will bind on port 8080 server, err := NewServer("127.0.0.1:0") // will get a random available port
func (*GandalfServer) Grants ¶
func (s *GandalfServer) Grants() map[string][]string
Grants returns a map of grant in repositories, mapping the name of the repository to the slice of users that have access to it.
func (*GandalfServer) Keys ¶
func (s *GandalfServer) Keys(user string) (map[string]string, error)
Keys returns all the keys registered for the given users, or an error if the user doesn't exist.
func (*GandalfServer) PrepareDiff ¶
func (s *GandalfServer) PrepareDiff(repository, content string)
PrepareDiff prepares a diff for the given repository and writes it to the next getDiff call in the server.
func (*GandalfServer) PrepareFailure ¶
func (s *GandalfServer) PrepareFailure(failure Failure)
PrepareFailure prepares a failure in the server. The next request matching the given URL and request path will fail with a 500 code and the provided response in the body.
func (*GandalfServer) ReadOnlyGrants ¶
func (s *GandalfServer) ReadOnlyGrants() map[string][]string
ReadOnlyGrants returns a map of read-only grants in repositories, mapping the name of the repository to the slice of users that have access to it.
func (*GandalfServer) Repositories ¶
func (s *GandalfServer) Repositories() []Repository
Repository returns the list of repositories registered in the server.
func (*GandalfServer) Reset ¶
func (s *GandalfServer) Reset()
Reset resets all internal information of the server, like keys, repositories, users and prepared failures.
func (*GandalfServer) ServeHTTP ¶
func (s *GandalfServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handler HTTP requests, dealing with prepared failures before dispatching the request to the proper internal handler.
func (*GandalfServer) Stop ¶
func (s *GandalfServer) Stop() error
Stop stops the server, cleaning the internal listener and freeing the allocated port.
func (*GandalfServer) URL ¶
func (s *GandalfServer) URL() string
URL returns the URL of the server, in the format "http://<host>:<port>/".
func (*GandalfServer) Users ¶
func (s *GandalfServer) Users() []string
Users returns the list of users registered in the server.