Documentation ¶
Overview ¶
Package testing provides a fake implementation of the Docker API, useful for testing purpose.
Index ¶
- type DockerServer
- func (s *DockerServer) CustomHandler(path string, handler http.Handler)
- func (s *DockerServer) DefaultHandler() http.Handler
- func (s *DockerServer) MutateContainer(id string, state docker.State) error
- func (s *DockerServer) PrepareFailure(id string, urlRegexp string)
- func (s *DockerServer) ResetFailure(id string)
- func (s *DockerServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *DockerServer) Stop()
- func (s *DockerServer) URL() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DockerServer ¶
type DockerServer struct {
// contains filtered or unexported fields
}
DockerServer represents a programmable, concurrent (not much), HTTP server implementing a fake version of the Docker remote API.
It can used in standalone mode, listening for connections or as an arbitrary HTTP handler.
For more details on the remote API, check http://goo.gl/G3plxW.
func NewServer ¶
func NewServer(bind string, containerChan chan<- *docker.Container, hook func(*http.Request)) (*DockerServer, error)
NewServer returns a new instance of the fake server, in standalone mode. Use the method URL to get the URL of the server.
It receives the bind address (use 127.0.0.1:0 for getting an available port on the host), a channel of containers and a hook function, that will be called on every request.
The fake server will send containers in the channel whenever the container changes its state, via the HTTP API (i.e.: create, start and stop). This channel may be nil, which means that the server won't notify on state changes.
func (*DockerServer) CustomHandler ¶
func (s *DockerServer) CustomHandler(path string, handler http.Handler)
CustomHandler registers a custom handler for a specific path.
For example:
server.CustomHandler("/containers/json", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { http.Error(w, "Something wrong is not right", http.StatusInternalServerError) }))
func (*DockerServer) DefaultHandler ¶
func (s *DockerServer) DefaultHandler() http.Handler
DefaultHandler returns default http.Handler mux, it allows customHandlers to call the default behavior if wanted.
func (*DockerServer) MutateContainer ¶
func (s *DockerServer) MutateContainer(id string, state docker.State) error
MutateContainer changes the state of a container, returning an error if the given id does not match to any container "running" in the server.
func (*DockerServer) PrepareFailure ¶
func (s *DockerServer) PrepareFailure(id string, urlRegexp string)
PrepareFailure adds a new expected failure based on a URL regexp it receives an id for the failure.
func (*DockerServer) ResetFailure ¶
func (s *DockerServer) ResetFailure(id string)
ResetFailure removes an expected failure identified by the given id.
func (*DockerServer) ServeHTTP ¶
func (s *DockerServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handles HTTP requests sent to the server.
func (*DockerServer) URL ¶
func (s *DockerServer) URL() string
URL returns the HTTP URL of the server.