testutil

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertContains

func AssertContains(t *testing.T, expected string, actual string)

AssertContains checks if the actual string contains the expected string.

func AssertGoldenOutput

func AssertGoldenOutput(t *testing.T, testName string, goldenFile string, output string)

AssertGoldenOutput reads the expected output of a test from goldenFile and checks that the actual ouput matches.

func DeleteTempDir

func DeleteTempDir(dir string)

DeleteTempDir deteles the temporary directory and all its content.

func Dt

func Dt(s string) time.Time

Dt parses a date string (02.01.2006) into a Time at 00:00 Local time.

func DtUtc

func DtUtc(s string) time.Time

DtUtc parses a date string (02.01.2006) into a Time at 00:00 UTC.

func Dts

func Dts(t time.Time) string

Dts formats a Time into a date string (02.01.2006)

func Dtt

func Dtt(s string) time.Time

Dtt parses a date and time string (02.01.2006 15:04) into a Time.

func Dtts

func Dtts(t time.Time) string

Dtts formats a Time into a date and time string (02.01.2006 15:04)

func FullTestdataPath

func FullTestdataPath(filenameOrPartialPath string) string

FullTestdataPath returns the full path of a testdata file, given a partial path (usually just the filename). E.g.: GetTestdataFile('my_testdata.txt') -> testdata/my_testdata.txt

func MakeTempDir

func MakeTempDir(dirName string) string

MakeTempDir creates a temporary directory with name dirName. Don't forget to call defer DeleteTempDir to get rid of it at the end of the test.

func MockSimpleJSONResponse

func MockSimpleJSONResponse(response string) *httptest.Server

MockSimpleJSONResponse sets up a test http server which responds with the passed JSON response for all requests.

func ReadTestdata

func ReadTestdata(t *testing.T, testName string, path string) string

ReadTestdata reads a file from the current package's testdata/ folder.

func ToJSON

func ToJSON(any interface{}) string

ToJSON pretty prints the passed object as JSON.

func Tts

func Tts(t time.Time) string

Tts formats a Time into a time string (15:04:05)

func WriteTestdata

func WriteTestdata(t *testing.T, testName string, path string, data string)

WriteTestdata wrotes a file to the current package's testdata/ folder.

Types

This section is empty.

Jump to

Keyboard shortcuts

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