xhttptest

package
v0.0.0-...-ed9fe1d Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2018 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCookie

func GetCookie(w *httptest.ResponseRecorder, name string) (*http.Cookie, error)

GetCookie returns *http.Cookie from httptes.ResponseRecorder

func GetCookies

func GetCookies(w *httptest.ResponseRecorder) ([]*http.Cookie, error)

func StubCreator

func StubCreator(basedir string, c *http.Client) *http.Client

StubCreator returns *http.Client that creates files for stubs by real accesses if stub file does not exists. The stub files are created(or used) at {basedir}/{domain}/{path} structure.

func StubFile

func StubFile(mapping map[string]string, c *http.Client) *http.Client

StubFile is like a Stub but access local file resources instead of making actual HTTP requests. The following fields are valid and others should not be used in your test.

  • .Status
  • .StatusCode
  • .Header.Get("content-type")
  • .ContentLength
  • .Body

If you want to test full http request transactions, use StubServer instead.

func UseStubServer

func UseStubServer(handler http.Handler, f func(*StubServer))

UseStubServer launches a stub server configured by handler and execute test function f.

Types

type StubServer

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

StubServer is an http server that serve the request as stub.

func (*StubServer) Client

func (s *StubServer) Client(mapping map[string]string, c *http.Client) *http.Client

Client enforce http.Client to request to the stub server instead of requesting external resources. mapping should be the map from external urls to stub server paths. if mapping is nil, all external requests are mapped to the StubServer s.

Jump to

Keyboard shortcuts

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