http

package
v3.14.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2017 License: Apache-2.0, Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Provides both HTTP client and HTTP fake server configuration for testing.

Client Configuration

The "HttpClientConfig" is main configuration object defines tested service of HTTP.

Client Initialization

The "HttpClientConfig" has "NewClient()" and "NewRequest()" to provide out-of-box gentleman client object.

Fake Server Configuration

The object of "FakeServerConfig" defines the network socket you like to use in testing.

Listener and URL of Fake Server

You could use "FakeServerConfig.GetListener()" or "FakeServerConfig.GetUrl()" to get configuration of network when needing of fake server.

See "common/testing/http/gock" for mock server.

Index

Constants

This section is empty.

Variables

View Source
var GinTestServer = &struct {
	GoCheckOrSkip            func(c *check.C) bool
	GoCheckStartGinWebServer func(c *check.C, engineFunc GinEngineConfigFunc)
	GoCheckGetConfig         func(c *check.C) *ogin.GinConfig
}{
	GoCheckOrSkip:            goCheckOrSkip,
	GoCheckStartGinWebServer: goCheckStartGinWebServer,
	GoCheckGetConfig:         goCheckGetGinConfig,
}

functions in namespace for set-up gin server(with GoCheck library)

"test.gin_mode" - The mode of Gin framework
"test.web_host" - The host of web
"test.web_port" - The port of web

The default value of port is "0", hence HasSetting() would be "false"

Deprecated: Try to use testing/http/gock to start a mock server

View Source
var WebTestServer = &struct {
	// Gets value of "test.web_host
	GetHost func() string
	// Gets value of "test.web_port
	GetPort func() uint16
	// Gets value of "http://<test.web_host>:<test.web_port>"
	GetUrl     func() string
	HasSetting func() bool
}{
	GetHost: getWebHost,
	GetPort: getWebPort,
	GetUrl: func() string {
		return fmt.Sprintf("http://%s:%d", getWebHost(), getWebPort())
	},
	HasSetting: func() bool {
		return getWebPort() > 0
	},
}

functions in namespace for getting value of flags for

"test.web_host" - The host of web
"test.web_port" - The port of web

The default value of port is "0", hence HasSetting() would be "false"

Deprecated: Try to use testing/http/gock to start a mock server

Functions

This section is empty.

Types

type CheckSlint

type CheckSlint struct {
	Slint        *sling.Sling
	LastResponse *http.Response
	// contains filtered or unexported fields
}

Slint with checker

func NewCheckSlint

func NewCheckSlint(checker *checker.C, sling *sling.Sling) *CheckSlint

Initialize a checker with slint support

func (*CheckSlint) AssertHasPaging

func (self *CheckSlint) AssertHasPaging()

Asserts the existing of paging header

func (*CheckSlint) GetJsonBody

func (self *CheckSlint) GetJsonBody(expectedStatus int) *json.Json

Gets body as JSON

The exepcted status is used to get expected status

func (*CheckSlint) GetResponse

func (self *CheckSlint) GetResponse() *http.Response

Gets the response for current request

func (*CheckSlint) GetStringBody

func (self *CheckSlint) GetStringBody(expectedStatus int) string

Gets body as string

The exepcted status is used to get expected status

func (*CheckSlint) Request

func (self *CheckSlint) Request() *http.Request

Gets request of slint

type FakeServerConfig

type FakeServerConfig struct {
	Host string
	Port uint16
}

Configuration used to set-up faking server.

func (*FakeServerConfig) GetListener

func (c *FakeServerConfig) GetListener() net.Listener

Gets the listener object.

func (*FakeServerConfig) GetUrl

func (c *FakeServerConfig) GetUrl() *url.URL

Gets the URL(http) object of fake server.

func (*FakeServerConfig) GetUrlString

func (c *FakeServerConfig) GetUrlString() string

Gets the URL(http) string of fake server.

type GentlemanClientConf

type GentlemanClientConf struct {
	*HttpClientConfig
}

Supporting configuration of testing by Gentleman library.

func (*GentlemanClientConf) NewClient

func (c *GentlemanClientConf) NewClient() *gt.Client

Consturcts a "*gentleman.Client" object by configuration.

The timeout of request is three seconds.

func (*GentlemanClientConf) NewRequest

func (c *GentlemanClientConf) NewRequest() *gt.Request

Consturcts a "*gentleman.Request" object by configuration.

The timeout of request is three seconds.

type GinEngineConfigFunc deprecated

type GinEngineConfigFunc func(*gin.Engine)

Callback to set-up of Gin engine.

Deprecated: Try to use testing/http/gock to start a fake server

type HttpClientConfig

type HttpClientConfig struct {
	Ssl      bool
	Host     string
	Port     uint16
	Resource string
}

The configuration of http client

See "NewHttpClientConfigByFlag()" to initialize this object by flag.

func NewHttpClientConfigByFlag

func NewHttpClientConfigByFlag() *HttpClientConfig

Initialize a client config by flag(properties).

client.http.host=
client.http.port=
client.http.resource=
client.http.ssl=

See common/testing/flag for detail

func (*HttpClientConfig) String

func (self *HttpClientConfig) String() string

Gets the full URL of tested service

type HttpTest

type HttpTest interface {
	NewServer(serverConfig *FakeServerConfig) *httptest.Server
	GetHttpHandler() http.Handler
}

Defines the interface used to set-up "*net/http/httptest.Server"

type ResponseResult

type ResponseResult struct {
	Response *http.Response
	// contains filtered or unexported fields
}

func NewResponseResultByGentlemanResp

func NewResponseResultByGentlemanResp(resp *gt.Response) *ResponseResult

func NewResponseResultByRequest

func NewResponseResultByRequest(req *http.Request) *ResponseResult

Performs request and reads the body into []byte

func NewResponseResultByResponse

func NewResponseResultByResponse(resp *http.Response) *ResponseResult

func NewResponseResultBySling

func NewResponseResultBySling(slingObj *sling.Sling) *ResponseResult

Performs request and reads the body into []byte

func (*ResponseResult) GetBodyAsJson

func (r *ResponseResult) GetBodyAsJson() *json.Json

func (*ResponseResult) GetBodyAsString

func (r *ResponseResult) GetBodyAsString() string

type SlingClientConf deprecated

type SlingClientConf struct {
	*HttpClientConfig
}

Supporting configuration of testing by Sling(deprecated) library

Deprecated: You should use gentleman library instead.

func (*SlingClientConf) NewClient

func (c *SlingClientConf) NewClient() *sling.Sling

Directories

Path Synopsis
Out-of-box Gock/Gentleman functions.
Out-of-box Gock/Gentleman functions.
Plugin for using Gock on Gentleman library.
Plugin for using Gock on Gentleman library.

Jump to

Keyboard shortcuts

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