util

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2021 License: Unlicense Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ResponseBingImageAsync   []byte
	ResponseBingImagesSearch []byte
	ResponseBingSettings     []byte
	ResponseExample          []byte
	ResponseFlickrSearch     []byte
	ResponseFlickrSearchAPI  []byte
	ResponseGoogleSearch     []byte
)

Functions

func CheckCmdOutput

func CheckCmdOutput(t *testing.T, output []byte, matchWith *regexp.Regexp)

CheckCmdOutput can be used to match output of a command with a target Regexp.

func CheckErr

func CheckErr(t *testing.T, err error)

CheckErr can be used to report generic test errors.

func DownloadWebpage

func DownloadWebpage(
	pageUrl string,
	expectedStatus int,
	headers map[string]string,
	params map[string]string,
) ([]byte, error)

DownloadWebpage downloads a webpage and returns content as byte array if successful. An error is returned otherwise.

func PrintResults

func PrintResults(items []interface{}, pages int, compact bool)

PrintResults writes search result to stdout.

func RegisterMockHTTPClient

func RegisterMockHTTPClient()

RegisterMockHTTPClient replaces real http client with a mock client.

func SearchRegex

func SearchRegex(expr string, target string, fieldName string) (string, error)

SearchRegex performs regex search on given string using a pattern returning the first matching group. In case of failure it returns an error.

Types

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}
var Client HTTPClient

type MockClient

type MockClient struct {
	MockDo func(req *http.Request) (*http.Response, error)
}

MockClient is the mock client.

func (*MockClient) Do

func (m *MockClient) Do(req *http.Request) (*http.Response, error)

type TestCase

type TestCase struct {
	In  interface{}
	Out interface{}
}

TestCase represents a generic test case.

Jump to

Keyboard shortcuts

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