testsrv: github.com/arschles/testsrv Index | Files

package testsrv

import "github.com/arschles/testsrv"

Index

Package Files

received_request.go server.go

Constants

const (
    UUIDHeaderName = "HTTP-Sub-UUID"
)

type ReceivedRequest Uses

type ReceivedRequest struct {
    // The request the subscriber received
    Request *http.Request
    // The receipt time
    Time time.Time
    // Unique identifier of the request. will be returned as UUIDHeaderName in each
    // response that the subscriber sends
    UUID string
}

ReceivedRequest represents a request that the subscriber received.

type Server Uses

type Server struct {
    // contains filtered or unexported fields
}

Server is a HTTP server that you can send real HTTP requests to in your unit tests. Each request is handled by a http.Handler that you specify, and the server records each request after your handler finishes execution. You can later retreive details about each received request

func StartServer Uses

func StartServer(handler http.Handler) *Server

StartServer starts the server listening in the background. All requests sent to the server at s.URLStr() are sent to handler, flushed and then recorded for later retrieval using the AcceptN func

func (*Server) AcceptN Uses

func (s *Server) AcceptN(n int, maxWait time.Duration) []*ReceivedRequest

AcceptN consumes and returns up to n requests that were sent to the server before maxWait is up. returns all of the requests received. each individual request returned will not be returned by this func again.

func (*Server) Close Uses

func (s *Server) Close()

Close releases all resources on this subscriber

func (*Server) URLStr Uses

func (s *Server) URLStr() string

URLStr returns the string representation of the URL to call to hit this server

Package testsrv imports 6 packages (graph). Updated 2018-09-14. Refresh now. Tools for package owners.