{"modulePath":"github.com/windhooked/pkg","version":"v0.0.0-20210530195812-02de94908f4f","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package assert\n\nPackage assert provides a set of comprehensive testing tools for use with the normal Go testing system.\n\n### Example Usage {#hdr-Example_Usage}\n\nThe following is a complete example using assert in a standard test function:\n\n\timport (\n\t  \"testing\"\n\t  \"github.com/corestoreio/pkg/util/assert\"\n\t)\n\n\tfunc TestSomething(t *testing.T) {\n\n\t  var a string = \"Hello\"\n\t  var b string = \"Hello\"\n\n\t  assert.Equal(t, a, b, \"The two words should be the same.\")\n\n\t}\n\nif you assert many times, use the format below:\n\n\timport (\n\t  \"testing\"\n\t  \"github.com/corestoreio/pkg/util/assert\"\n\t)\n\n\tfunc TestSomething(t *testing.T) {\n\t  assert := assert.New(t)\n\n\t  var a string = \"Hello\"\n\t  var b string = \"Hello\"\n\n\t  assert.Equal(a, b, \"The two words should be the same.\")\n\t}\n\n### Assertions {#hdr-Assertions}\n\nAssertions allow you to easily write test code, and are global funcs in the \\`assert\\` package. All assertion functions take, as the first argument, the \\`\\*testing.T\\` object provided by the testing framework. This allows the assertion funcs to write the failings and other details to the correct place.\n\nEvery assertion function also takes an optional string message as the final argument, allowing custom error messages to be appended to the message the assertion method outputs.\n\nTo enable HTTP assertions you must compile with build tag \\`csall\\` or \\`http\\`.\n\n## Variables\n\n```go\nvar AnError = errors.New(\"assert.AnError general error for testing\")\n```\nAnError is an error instance useful for testing.  If the code does not care about error specifics, and only needs to return the error for example, this error should be used to make the test code more readable.\n\n## Functions\n\n```go\nfunc CallerInfo() []string\n```\nCallerInfo returns an array of strings containing the file and line number of each stack frame leading from the current test to the assert call that failed.\n\n```go\nfunc Condition(t TestingT, comp Comparison, msgAndArgs ...interface{})\n```\nCondition uses a Comparison to assert a complex condition.\n\n```go\nfunc Contains(t TestingT, s, contains interface{}, msgAndArgs ...interface{})\n```\nContains asserts that the specified string, list(array, slice...) or map contains the specified substring or element.\n\n\tassert.Contains(t, \"Hello World\", \"World\")\n\tassert.Contains(t, [\"Hello\", \"World\"], \"World\")\n\tassert.Contains(t, {\"Hello\": \"World\"}, \"Hello\")\n\n```go\nfunc DiffValues(a, b interface{}) string\n```\n\n```go\nfunc DiffValuesDefault(a, b interface{}) string\n```\n\n```go\nfunc DirExists(t TestingT, path string, msgAndArgs ...interface{}) bool\n```\nDirExists checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists.\n\n```go\nfunc ElementsMatch(t TestingT, listA, listB interface{}, msgAndArgs ...interface{})\n```\nElementsMatch asserts that the specified listA(array, slice...) is equal to specified listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, the number of appearances of each of them in both lists should match.\n\nassert.ElementsMatch(t, \\[1, 3, 2, 3], \\[1, 3, 3, 2])\n\n```go\nfunc Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) bool\n```\nEmpty asserts that the specified object is empty.  I.e. nil, \"\", false, 0 or either a slice or a channel with len == 0.\n\n\tassert.Empty(t, obj)\n\n```go\nfunc Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{})\n```\nEqual asserts that two objects are equal.\n\n\tassert.Equal(t, 123, 123)\n\nPointer variable equality is determined based on the equality of the referenced values (as opposed to the memory addresses). Function equality cannot be determined and will always fail.\n\n```go\nfunc EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) bool\n```\nEqualError asserts that a function returned an error (i.e. not \\`nil\\`) and that it is equal to the provided error.\n\n\tactualObj, err := SomeFunction()\n\tassert.EqualError(t, err,  expectedErrorString)\n\n```go\nfunc EqualValues(t TestingT, expected, actual interface{}, msgAndArgs ...interface{})\n```\nEqualValues asserts that two objects are equal or convertable to the same types and equal.\n\n\tassert.EqualValues(t, uint32(123), int32(123))\n\n```go\nfunc Error(t TestingT, err error, msgAndArgs ...interface{}) bool\n```\nError asserts that a function returned an error (i.e. not \\`nil\\`).\n\n\t  actualObj, err := SomeFunction()\n\t  if assert.Error(t, err) {\n\t\t   assert.Equal(t, expectedError, err)\n\t  }\n\n```go\nfunc ErrorIsKind(t TestingT, expected errors.Kind, err error, msgAndArgs ...interface{})\n```\nErrorIsKind asserts that an error matches the expected Kind.\n\n```go\nfunc Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{})\n```\nEventually asserts that given condition will be met in waitFor time, periodically checking target function each tick.\n\n\tassert.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond)\n\n```go\nfunc Exactly(t TestingT, expected, actual interface{}, msgAndArgs ...interface{})\n```\nExactly asserts that two objects are equal in value and type.\n\n\tassert.Exactly(t, int32(123), int64(123))\n\n```go\nfunc ExactlyLength(t TestingT, maxLength int, ptrExpected, ptrActual interface{}, msgAndArgs ...interface{})\n```\nExactlyLength asserts that two objects with maximum length of their string fields are equal in value and type.\n\n\tassert.ExactlyLength(t,2, \"aa\", \"aaa\")\n\nShorts aaa to aa and checks if aa is equal to aa. This function is needed when writing random strings to the database table with short column length.\n\n```go\nfunc Fail(t TestingT, failureMessage string, msgAndArgs ...interface{})\n```\nFail reports a failure through\n\n```go\nfunc False(t TestingT, value bool, msgAndArgs ...interface{})\n```\nFalse asserts that the specified value is false.\n\n\tassert.False(t, myBool)\n\n```go\nfunc FileExists(t TestingT, path string, msgAndArgs ...interface{}) bool\n```\nFileExists checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file.\n\n```go\nfunc Implements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{})\n```\nImplements asserts that an object is implemented by the specified interface.\n\n\tassert.Implements(t, (*MyInterface)(nil), new(MyObject))\n\n```go\nfunc InDelta(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{})\n```\nInDelta asserts that the two numerals are within delta of each other.\n\n\tassert.InDelta(t, math.Pi, 22/7.0, 0.01)\n\n```go\nfunc InDeltaMapValues(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{})\n```\nInDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.\n\n```go\nfunc InDeltaSlice(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{})\n```\nInDeltaSlice is the same as InDelta, except it compares two slices.\n\n```go\nfunc InEpsilon(t TestingT, expected, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool\n```\nInEpsilon asserts that expected and actual have a relative error less than epsilon\n\n```go\nfunc InEpsilonSlice(t TestingT, expected, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool\n```\nInEpsilonSlice is the same as InEpsilon, except it compares each value from two slices.\n\n```go\nfunc IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{})\n```\nIsType asserts that the specified objects are of the same type.\n\n```go\nfunc JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{})\n```\nJSONEq asserts that two JSON strings are equivalent.\n\n\tassert.JSONEq(t, `{\"hello\": \"world\", \"foo\": \"bar\"}`, `{\"foo\": \"bar\", \"hello\": \"world\"}`)\n\n```go\nfunc Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{})\n```\nLen asserts that the specified object has specific length. Len also fails if the object has a type that len() not accept.\n\n\tassert.Len(t, mySlice, 3)\n\n```go\nfunc LenBetween(t TestingT, object interface{}, min, maxLength int, msgAndArgs ...interface{})\n```\nLenBetween asserts that the specified object has a length between a lower and an upper bound. LenBetween also fails if the object has a type that len() not accept.\n\n\tassert.MaxLen(t, mySlice, 3, \"The size of slice is not 3\")\n\tassert.MaxLen(t, myInt, 5, \"The value of myInt is not smaller or equal to 5\")\n\nReturns whether the assertion was successful (true) or not (false).\n\n```go\nfunc MatchesGolden(t TestingT, pathGoldenFile string, haveData []byte, updateGolden bool, msgAndArgs ...interface{}) bool\n```\nMatchesGolden compares haveData with the file content of pathGoldenFile.\n\n```go\nfunc Never(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{})\n```\nNever asserts that the given condition doesn't satisfy in waitFor time, periodically checking the target function each tick.\n\n\tassert.Never(t, func() bool { return false; }, time.Second, 10*time.Millisecond)\n\n```go\nfunc Nil(t TestingT, object interface{}, msgAndArgs ...interface{})\n```\nNil asserts that the specified object is nil.\n\n\tassert.Nil(t, err)\n\n```go\nfunc NoDirExists(t TestingT, path string, msgAndArgs ...interface{}) bool\n```\nNoDirExists checks whether a directory does not exist in the given path. It fails if the path points to an existing \\_directory\\_ only.\n\n```go\nfunc NoError(t TestingT, err error, msgAndArgs ...interface{}) bool\n```\nNoError asserts that a function returned no error (i.e. \\`nil\\`).\n\n\t  actualObj, err := SomeFunction()\n\t  if assert.NoError(t, err) {\n\t\t   assert.Equal(t, expectedObj, actualObj)\n\t  }\n\n```go\nfunc NoFileExists(t TestingT, path string, msgAndArgs ...interface{})\n```\nNoFileExists checks whether a file does not exist in a given path. It fails if the path points to an existing \\_file\\_ only.\n\n```go\nfunc NotContains(t TestingT, s, contains interface{}, msgAndArgs ...interface{})\n```\nNotContains asserts that the specified string, list(array, slice...) or map does NOT contain the specified substring or element.\n\n\tassert.NotContains(t, \"Hello World\", \"Earth\")\n\tassert.NotContains(t, [\"Hello\", \"World\"], \"Earth\")\n\tassert.NotContains(t, {\"Hello\": \"World\"}, \"Earth\")\n\n```go\nfunc NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) bool\n```\nNotEmpty asserts that the specified object is NOT empty.  I.e. not nil, \"\", false, 0 or either a slice or a channel with len == 0.\n\n\tif assert.NotEmpty(t, obj) {\n\t  assert.Equal(t, \"two\", obj[1])\n\t}\n\n```go\nfunc NotEqual(t TestingT, expected, actual interface{}, msgAndArgs ...interface{})\n```\nNotEqual asserts that the specified values are NOT equal.\n\n\tassert.NotEqual(t, obj1, obj2)\n\nPointer variable equality is determined based on the equality of the referenced values (as opposed to the memory addresses).\n\n```go\nfunc NotNil(t TestingT, object interface{}, msgAndArgs ...interface{})\n```\nNotNil asserts that the specified object is not nil.\n\n\tassert.NotNil(t, err)\n\n```go\nfunc NotPanics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{})\n```\nNotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.\n\n\tassert.NotPanics(t, func(){ RemainCalm() })\n\n```go\nfunc NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) bool\n```\nNotRegexp asserts that a specified regexp does not match a string.\n\n\tassert.NotRegexp(t, regexp.MustCompile(\"starts\"), \"it's starting\")\n\tassert.NotRegexp(t, \"^start\", \"it's not starting\")\n\n```go\nfunc NotSame(t TestingT, expected, actual interface{}, msgAndArgs ...interface{})\n```\nNotSame asserts that two pointers do not reference the same object.\n\n\tassert.NotSame(t, ptr1, ptr2)\n\nBoth arguments must be pointer variables. Pointer variable sameness is determined based on the equality of both type and value.\n\n```go\nfunc NotSubset(t TestingT, list, subset interface{}, msgAndArgs ...interface{})\n```\nNotSubset asserts that the specified list(array, slice...) contains not all elements given in the specified subset(array, slice...).\n\n\tassert.NotSubset(t, [1, 3, 4], [1, 2], \"But [1, 3, 4] does not contain [1, 2]\")\n\n```go\nfunc NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) bool\n```\nNotZero asserts that i is not the zero value for its type.\n\n```go\nfunc ObjectsAreEqual(expected, actual interface{}) bool\n```\nObjectsAreEqual determines if two objects are considered equal.\n\nThis function does no assertion of any kind.\n\n```go\nfunc ObjectsAreEqualValues(expected, actual interface{}) bool\n```\nObjectsAreEqualValues gets whether two objects are equal, or if their values are equal.\n\n```go\nfunc Panics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{})\n```\nPanics asserts that the code inside the specified PanicTestFunc panics.\n\n\tassert.Panics(t, func(){ GoCrazy() })\n\n```go\nfunc PanicsWithError(t TestingT, errString string, f PanicTestFunc, msgAndArgs ...interface{})\n```\nPanicsWithError asserts that the code inside the specified PanicTestFunc panics, and that the recovered panic value is an error that satisfies the EqualError comparison.\n\n\tassert.PanicsWithError(t, \"crazy error\", func(){ GoCrazy() })\n\n```go\nfunc PanicsWithValue(t TestingT, expected interface{}, f PanicTestFunc, msgAndArgs ...interface{})\n```\nPanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that the recovered panic value equals the expected panic value.\n\n\tassert.PanicsWithValue(t, \"crazy error\", func(){ GoCrazy() })\n\n```go\nfunc Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) bool\n```\nRegexp asserts that a specified regexp matches a string.\n\n\tassert.Regexp(t, regexp.MustCompile(\"start\"), \"it's starting\")\n\tassert.Regexp(t, \"start...$\", \"it's not starting\")\n\n```go\nfunc Same(t TestingT, expected, actual interface{}, msgAndArgs ...interface{})\n```\nSame asserts that two pointers reference the same object.\n\n\tassert.Same(t, ptr1, ptr2)\n\nBoth arguments must be pointer variables. Pointer variable sameness is determined based on the equality of both type and value.\n\n```go\nfunc Subset(t TestingT, list, subset interface{}, msgAndArgs ...interface{})\n```\nSubset asserts that the specified list(array, slice...) contains all elements given in the specified subset(array, slice...).\n\n\tassert.Subset(t, [1, 2, 3], [1, 2], \"But [1, 2, 3] does contain [1, 2]\")\n\n```go\nfunc True(t TestingT, value bool, msgAndArgs ...interface{})\n```\nTrue asserts that the specified value is true.\n\n\tassert.True(t, myBool)\n\n```go\nfunc WithinDuration(t TestingT, expected, actual time.Time, delta time.Duration, msgAndArgs ...interface{})\n```\nWithinDuration asserts that the two times are within duration delta of each other.\n\n\tassert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second)\n\n```go\nfunc Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) bool\n```\nZero asserts that i is the zero value for its type.\n\n## Types\n\n```go\ntype Comparison func() (success bool)\n```\nComparison a custom function that returns true on success and false on failure\n\n```go\ntype PanicTestFunc func()\n```\nPanicTestFunc defines a func that should be passed to the assert.Panics and assert.NotPanics methods, and represents a simple func that takes no arguments, and returns nothing.\n\n```go\ntype TestingT interface {\n\tErrorf(format string, args ...interface{})\n\tFailNow()\n}\n```\nTestingT is an interface wrapper around \\*testing.T\n\n","path":"github.com/windhooked/pkg/util/assert","name":"assert","synopsis":"Package assert provides a set of comprehensive testing tools for use with the normal Go testing system.","isRedistributable":true}
