got

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2020 License: MIT Imports: 17 Imported by: 8

README

Overview

A dependency-free test framework for go projects. Examples:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Each added in v0.0.3

func Each(t Testable, iteratee interface{}) (count int)

Each runs each exported method Fn on type Ctx as a subtest of t. The iteratee can be a struct Ctx or:

iteratee(t Testable) (ctx Ctx)

Each Fn will be called like:

ctx.Fn()

If iteratee is Ctx, its G and T fields will be set to New(t) and t for each test. Any Fn that has the same name with the embedded one will be ignored.

Types

type G added in v0.2.0

type G struct {
	Testable
	// contains filtered or unexported fields
}

G is the helper context

func New added in v0.0.3

func New(t Testable) G

New assertion helper

func NewWith added in v0.1.0

func NewWith(t Testable, opts Options) G

NewWith assertion helper with options

func (G) E added in v0.2.0

func (as G) E(args ...interface{})

E is a shortcut for Nil(args...).Must()

func (G) Eq added in v0.2.0

func (as G) Eq(a, b interface{}) (result Result)

Eq a ≂ b

func (G) Equal added in v0.2.0

func (as G) Equal(a, b interface{}) (result Result)

Equal a == b

func (G) Err added in v0.2.0

func (as G) Err(args ...interface{}) (result Result)

Err args[-1] is error and not nil

func (G) False added in v0.2.0

func (as G) False(a bool) (result Result)

False a == false

func (G) Gt added in v0.2.0

func (as G) Gt(a, b interface{}) (result Result)

Gt a > b

func (G) Gte added in v0.2.0

func (as G) Gte(a, b interface{}) (result Result)

Gte a >= b

func (G) Has added in v0.2.0

func (as G) Has(container, str string) (result Result)

Has str in container

func (G) Is added in v0.2.0

func (as G) Is(a, b interface{}) (result Result)

Is a a kind of b

func (G) Len added in v0.2.0

func (as G) Len(list interface{}, l int) (result Result)

Len len(list) == l

func (G) Lt added in v0.2.0

func (as G) Lt(a, b interface{}) (result Result)

Lt a < b

func (G) Lte added in v0.2.0

func (as G) Lte(a, b interface{}) (result Result)

Lte a <= b

func (G) Neq added in v0.2.0

func (as G) Neq(a, b interface{}) (result Result)

Neq a != b

func (G) Nil added in v0.2.0

func (as G) Nil(args ...interface{}) (result Result)

Nil args[-1] == nil

func (G) NotNil added in v0.2.0

func (as G) NotNil(args ...interface{}) (result Result)

NotNil args[-1] != nil

func (G) Open added in v0.2.0

func (hp G) Open(create bool, path ...string) (f *os.File)

Open a file. Override it if create is true. Directories will be auto-created. path will be joined with filepath.Join so that it's cross-platform

func (G) Panic added in v0.2.0

func (as G) Panic(fn func()) (result Result)

Panic fn should panic

func (G) Read added in v0.2.0

func (hp G) Read(r io.Reader) []byte

Read all from r

func (G) ReadJSON added in v0.2.0

func (hp G) ReadJSON(r io.Reader) (v interface{})

ReadJSON from r

func (G) ReadString added in v0.2.0

func (hp G) ReadString(r io.Reader) string

ReadString from r

func (G) Regex added in v0.2.0

func (as G) Regex(pattern, str string) (result Result)

Regex matches str

func (G) Req added in v0.2.0

func (hp G) Req(method, url string, body ...interface{}) *ResHelper

Req to the url

func (G) Serve added in v0.2.0

func (hp G) Serve() *Router

Serve http on a random port. The server will be auto-closed after the test.

func (G) Srand added in v0.2.0

func (hp G) Srand(l int) string

Srand generates a random string with the specified length

func (G) True added in v0.2.0

func (as G) True(a bool) (result Result)

True a == true

func (G) Write added in v0.2.0

func (hp G) Write(obj interface{}, w io.Writer)

Write obj to the w

type Only added in v0.1.2

type Only struct{}

Only run tests with it

type Options added in v0.1.0

type Options struct {
	// Dump a value to human readable string
	Dump func(interface{}) string

	// Format keywords in the assertion message.
	// Such as color it for CLI output.
	Keyword func(string) string
}

Options for Assertion

func Defaults added in v0.1.0

func Defaults() Options

Defaults for Options

type ResHelper added in v0.2.0

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

ResHelper of the request

func (*ResHelper) Bytes added in v0.2.0

func (res *ResHelper) Bytes() []byte

Bytes body

func (*ResHelper) JSON added in v0.2.0

func (res *ResHelper) JSON() (v interface{})

JSON body

func (*ResHelper) String added in v0.2.0

func (res *ResHelper) String() string

String body

type Result added in v0.1.0

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

Result helper

func (Result) Msg added in v0.1.0

func (r Result) Msg(format string, args ...interface{}) Result

Msg if fails

func (Result) Must added in v0.1.0

func (r Result) Must() Result

Must FailNow if fails

type Router added in v0.2.0

type Router struct {
	HostURL *url.URL
	Server  *http.Server
	Mux     *http.ServeMux
	// contains filtered or unexported fields
}

Router of a http server

func (*Router) Route added in v0.2.0

func (rt *Router) Route(pattern, file string, value ...interface{}) *Router

Route on the pattern.

func (*Router) URL added in v0.2.0

func (rt *Router) URL(path ...string) string

URL will prefix the path with the server's host

type Skip added in v0.1.2

type Skip struct{}

Skip current test

type Testable added in v0.0.3

type Testable interface {
	Helper()
	Fail()
	FailNow()
	Cleanup(func())
	Logf(format string, args ...interface{})
}

Testable interface

Directories

Path Synopsis
lib
benchmark Module
example Module

Jump to

Keyboard shortcuts

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