testutil

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2020 License: MIT Imports: 13 Imported by: 0

README

Test utilities

TODO

  • toc
  • example in go doc, can there be example for test package?

Condition

TODO: example of using test condition

Env

TODO: load dot env

Golden

TODO: use golden file

actually, just Read/WriteFixture would work ...

// GenGolden check if env GOLDEN or GEN_GOLDEN is set, sometimes you need to generate test fixture in test
func GenGolden() Condition {
	return Or(EnvHas("GOLDEN"), EnvHas("GEN_GOLDEN"))
}

Documentation

Overview

Package testutil defines helper functions that fails test instead of return error

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisableGenGolden added in v0.0.5

func DisableGenGolden(t *testing.T)

func DumpAsJson added in v0.0.8

func DumpAsJson(t *testing.T, v interface{})

TODO: it's dump w/ Print in pretty.go ... wrote too much and forgot ...

func DumpAsJsonTo added in v0.0.8

func DumpAsJsonTo(t *testing.T, v interface{}, w io.Writer)

func EnableGenGolden added in v0.0.5

func EnableGenGolden(t *testing.T)

func FormatJson added in v0.0.8

func FormatJson(t *testing.T, src []byte) []byte

func GetBody added in v0.0.8

func GetBody(t *testing.T, c *http.Client, url string) []byte

func LoadDotEnv added in v0.0.5

func LoadDotEnv(t *testing.T)

LoadDotEnv load .env in current directory into environment variable, line start with # are comments It is modeled after https://github.com/motdotla/dotenv

func LoadDotEnvFrom added in v0.0.5

func LoadDotEnvFrom(t *testing.T, r io.Reader)

func LoadDotEnvFromFile added in v0.0.5

func LoadDotEnvFromFile(t *testing.T, path string)

func PrintTidyJson added in v0.0.5

func PrintTidyJson(t *testing.T, data interface{})

func PrintTidyJsonTo added in v0.0.5

func PrintTidyJsonTo(t *testing.T, data interface{}, w io.Writer)

func ReadFixture added in v0.0.4

func ReadFixture(t *testing.T, path string) []byte

func ReadJsonTo added in v0.0.4

func ReadJsonTo(t *testing.T, path string, v interface{})

func ReadYAMLTo added in v0.0.5

func ReadYAMLTo(t *testing.T, path string, v interface{})

func ReadYAMLToStrict added in v0.0.5

func ReadYAMLToStrict(t *testing.T, path string, v interface{})

ReadYAMLToStrict uses strict mode when decoding, if unknown fields shows up in YAML but not in struct it will error

func RunIf added in v0.0.5

func RunIf(t *testing.T, con Condition)

func SaveAsJson added in v0.0.8

func SaveAsJson(t *testing.T, v interface{}, file string)

func SaveAsJsonf added in v0.0.8

func SaveAsJsonf(t *testing.T, v interface{}, format string, args ...interface{})

func SaveAsPrettyJson added in v0.0.8

func SaveAsPrettyJson(t *testing.T, v interface{}, file string)

func SaveAsPrettyJsonf added in v0.0.8

func SaveAsPrettyJsonf(t *testing.T, v interface{}, format string, args ...interface{})

func SaveAsYAML added in v0.0.8

func SaveAsYAML(t *testing.T, v interface{}, file string)

func SaveAsYAMLf added in v0.0.8

func SaveAsYAMLf(t *testing.T, v interface{}, format string, args ...interface{})

func SkipIf added in v0.0.5

func SkipIf(t *testing.T, con Condition)

func WriteFixture added in v0.0.5

func WriteFixture(t *testing.T, path string, data []byte)

func WriteOrCompare added in v0.0.5

func WriteOrCompare(t *testing.T, file string, data []byte)

func WriteOrCompareAsString added in v0.0.5

func WriteOrCompareAsString(t *testing.T, file string, data string)

Types

type Condition added in v0.0.5

type Condition interface {
	Eval() (res bool, msg string, err error)
	// B is used for normal if condition
	B() bool
}

func And added in v0.0.5

func And(l Condition, r Condition) Condition

func Bool added in v0.0.5

func Bool(name string, b bool) Condition

Bool checks if a bool is true

func BoolP added in v0.0.5

func BoolP(name string, b *bool) Condition

BoolP checks if value of a pointer to bool is true

func Dump added in v0.0.5

func Dump() Condition

Dump check if env DUMP or GOMMON_DUMP is set, so print detail or use go-spew to dump structs etc.

func EnvHas added in v0.0.5

func EnvHas(name string) Condition

func EnvTrue added in v0.0.5

func EnvTrue(name string) Condition

func GenGolden added in v0.0.5

func GenGolden() Condition

GenGolden check if env GOLDEN or GEN_GOLDEN is set, sometimes you need to generate test fixture in test

func GenGoldenT added in v0.0.5

func GenGoldenT(t *testing.T) Condition

GenGoldenT check if current test is manually set to generate golden file

func IsTravis added in v0.0.5

func IsTravis() Condition

IsTravis check if env TRAVIS is true

func Not added in v0.0.5

func Not(c Condition) Condition

func Or added in v0.0.5

func Or(l Condition, r Condition) Condition

Jump to

Keyboard shortcuts

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