httput

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 31, 2019 License: MIT Imports: 5 Imported by: 0

README

Httput

Source GoDoc Build Status codecov License

httput package provide a tool suite to make an unitaries tests arround http and echo framework.

Requirements

Golang 1.12.4 or higher

download the package

go get -u github.com/ymohl-cl/gopkg/httput

Usage

import "github.com/ymohl-cl/gopkg/httput"

func main() {
    // build a request
    request := httptest.NewRequest(...)

    // build a fake echo context
    c := httput.NewContext(request)

    // the call your handlers to test them
    _ = MyHandler(c)

    // finally print the response content
    fmt.Printf("status code: %d", c.Rec.Code)
    fmt.Printf("content body: %s", c.Rec.Body.String())
}

Output:

> "status code: 200"
> "content body: {\"status\":\"200\"}"

Changelog

v0.0.1

Initial commit

  • fake echo context to tests handlers
  • tests and documentation

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequestJSON

func RequestJSON(method, path string, payload interface{}) (*http.Request, error)

RequestJSON build a httptest request with the specific payload

Types

type Context

type Context struct {
	Input echo.Context
	Rec   *httptest.ResponseRecorder
}

Context take an echo context and a httptest.Record to handlers tests

func NewContext

func NewContext(req *http.Request) Context

NewContext return a context to handlers tests

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL