Documentation ¶
Overview ¶
Package techo is equivalent to http.httptest, but uses labstack/echo for greater ease of use, and provides several additional useful things.
For more, visit: https://github.com/neilotoole/techo
Example:
func TestHello(t *testing.T) { te := techo.New() defer te.Stop() te.GET("/hello", func(c echo.Context) error { param := c.QueryParam("name") assert.Equal(t, param, "World") return c.String(http.StatusOK, fmt.Sprintf("Hello %v", param)) }) resp, err := http.Get(te.AbsURL("/hello?name=World")) defer resp.Body.Close() require.Nil(t, err) body, err := ioutil.ReadAll(resp.Body) require.Nil(t, err) assert.Equal(t, "Hello World", string(body)) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetDefaultTLSCert ¶
SetDefaultTLSCert is used to specify the TLS cert/key used by NewTLS(). Set the params to nil to restore to the internal default (localhost) cert.
func SkipDefaultClientInsecureTLSVerify ¶
func SkipDefaultClientInsecureTLSVerify()
SkipDefaultClientInsecureTLSVerify is a convenience method that sets InsecureSkipVerify to true on http.DefaultClient. This means that you can use insecure certs without receiving an error (assuming your client is using http.DefaultClient).
Types ¶
type Config ¶
type Config struct { // Addr is the address to listen on, e.g. ":1234" or "localhost:8080". Addr string // TLS indicates to start a TLS/HTTPS server. TLS bool // TLSCert is the TLS certificate to use. TLSCert []byte // TLSKey is the TLS private key to use. TLSKey []byte }
Config is the options available for staring a techo instance with techo.NewWith().
type Techo ¶
type Techo struct { // Port is the port number the server is listening at. Port int // Base is the base URL (scheme + host + port), e.g. http://127.0.0.1:61241 URL string // Addr provides access to the underlying TCP address object. Addr *net.TCPAddr *echo.Echo // contains filtered or unexported fields }
Techo is a techo server instance.
func New ¶
func New() *Techo
New starts a server on any available port. This value is available in the Port field. In the unlikely event of an error, the error is logged, and nil is returned.
func NewTLS ¶
func NewTLS() *Techo
NewTLS starts a TLS/HTTPS server on a random port. In the unusual event of an error, the error is logged, and nil is returned.
func (*Techo) AbsURL ¶
AbsURL constructs an absolute URL from the supplied (relative) path. For example, calling te.AbsURL("/my/path") could return "http://127.0.0.1:53262/my/path".