test

package
v0.0.0-...-4c183b5 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2013 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Utility functions to help writing tests for a Go-Json-Rest app

Go comes with net/http/httptest to help writing test for an http server. When this http server implements a JSON REST API, some basic checks end up to be always the same. This test package tries to save some typing by providing helpers for this particular use case.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BodyIs

func BodyIs(t *testing.T, r *httptest.ResponseRecorder, expectedBody string)

func CodeIs

func CodeIs(t *testing.T, r *httptest.ResponseRecorder, expectedCode int)

func ContentEncodingIsGzip

func ContentEncodingIsGzip(t *testing.T, r *httptest.ResponseRecorder)

func ContentTypeIsJson

func ContentTypeIsJson(t *testing.T, r *httptest.ResponseRecorder)

func DecodeJsonPayload

func DecodeJsonPayload(r *httptest.ResponseRecorder, v interface{}) error

func HeaderIs

func HeaderIs(t *testing.T, r *httptest.ResponseRecorder, headerKey, expectedValue string)

func MakeSimpleRequest

func MakeSimpleRequest(method string, urlStr string, payload interface{}) *http.Request

Types

type Recorded

type Recorded struct {
	T        *testing.T
	Recorder *httptest.ResponseRecorder
}

func RunRequest

func RunRequest(t *testing.T, handler http.Handler, request *http.Request) *Recorded

func (*Recorded) BodyIs

func (self *Recorded) BodyIs(expectedBody string)

func (*Recorded) CodeIs

func (self *Recorded) CodeIs(expectedCode int)

func (*Recorded) ContentEncodingIsGzip

func (self *Recorded) ContentEncodingIsGzip()

func (*Recorded) ContentTypeIsJson

func (self *Recorded) ContentTypeIsJson()

func (*Recorded) DecodeJsonPayload

func (self *Recorded) DecodeJsonPayload(v interface{}) error

func (*Recorded) HeaderIs

func (self *Recorded) HeaderIs(headerKey, expectedValue string)

Jump to

Keyboard shortcuts

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