How to use Helper method of is Package

Best Is code snippet using is.Helper

require.go

Source:require.go Github

copy

Full Screen

...10 time "time"11)12// Condition uses a Comparison to assert a complex condition.13func Condition(t TestingT, comp assert.Comparison, msgAndArgs ...interface{}) {14 if h, ok := t.(tHelper); ok {15 h.Helper()16 }17 if assert.Condition(t, comp, msgAndArgs...) {18 return19 }20 t.FailNow()21}22// Conditionf uses a Comparison to assert a complex condition.23func Conditionf(t TestingT, comp assert.Comparison, msg string, args ...interface{}) {24 if h, ok := t.(tHelper); ok {25 h.Helper()26 }27 if assert.Conditionf(t, comp, msg, args...) {28 return29 }30 t.FailNow()31}32// Contains asserts that the specified string, list(array, slice...) or map contains the33// specified substring or element.34//35// assert.Contains(t, "Hello World", "World")36// assert.Contains(t, ["Hello", "World"], "World")37// assert.Contains(t, {"Hello": "World"}, "Hello")38func Contains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) {39 if h, ok := t.(tHelper); ok {40 h.Helper()41 }42 if assert.Contains(t, s, contains, msgAndArgs...) {43 return44 }45 t.FailNow()46}47// Containsf asserts that the specified string, list(array, slice...) or map contains the48// specified substring or element.49//50// assert.Containsf(t, "Hello World", "World", "error message %s", "formatted")51// assert.Containsf(t, ["Hello", "World"], "World", "error message %s", "formatted")52// assert.Containsf(t, {"Hello": "World"}, "Hello", "error message %s", "formatted")53func Containsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) {54 if h, ok := t.(tHelper); ok {55 h.Helper()56 }57 if assert.Containsf(t, s, contains, msg, args...) {58 return59 }60 t.FailNow()61}62// DirExists checks whether a directory exists in the given path. It also fails63// if the path is a file rather a directory or there is an error checking whether it exists.64func DirExists(t TestingT, path string, msgAndArgs ...interface{}) {65 if h, ok := t.(tHelper); ok {66 h.Helper()67 }68 if assert.DirExists(t, path, msgAndArgs...) {69 return70 }71 t.FailNow()72}73// DirExistsf checks whether a directory exists in the given path. It also fails74// if the path is a file rather a directory or there is an error checking whether it exists.75func DirExistsf(t TestingT, path string, msg string, args ...interface{}) {76 if h, ok := t.(tHelper); ok {77 h.Helper()78 }79 if assert.DirExistsf(t, path, msg, args...) {80 return81 }82 t.FailNow()83}84// ElementsMatch asserts that the specified listA(array, slice...) is equal to specified85// listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,86// the number of appearances of each of them in both lists should match.87//88// assert.ElementsMatch(t, [1, 3, 2, 3], [1, 3, 3, 2])89func ElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndArgs ...interface{}) {90 if h, ok := t.(tHelper); ok {91 h.Helper()92 }93 if assert.ElementsMatch(t, listA, listB, msgAndArgs...) {94 return95 }96 t.FailNow()97}98// ElementsMatchf asserts that the specified listA(array, slice...) is equal to specified99// listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,100// the number of appearances of each of them in both lists should match.101//102// assert.ElementsMatchf(t, [1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted")103func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) {104 if h, ok := t.(tHelper); ok {105 h.Helper()106 }107 if assert.ElementsMatchf(t, listA, listB, msg, args...) {108 return109 }110 t.FailNow()111}112// Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either113// a slice or a channel with len == 0.114//115// assert.Empty(t, obj)116func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) {117 if h, ok := t.(tHelper); ok {118 h.Helper()119 }120 if assert.Empty(t, object, msgAndArgs...) {121 return122 }123 t.FailNow()124}125// Emptyf asserts that the specified object is empty. I.e. nil, "", false, 0 or either126// a slice or a channel with len == 0.127//128// assert.Emptyf(t, obj, "error message %s", "formatted")129func Emptyf(t TestingT, object interface{}, msg string, args ...interface{}) {130 if h, ok := t.(tHelper); ok {131 h.Helper()132 }133 if assert.Emptyf(t, object, msg, args...) {134 return135 }136 t.FailNow()137}138// Equal asserts that two objects are equal.139//140// assert.Equal(t, 123, 123)141//142// Pointer variable equality is determined based on the equality of the143// referenced values (as opposed to the memory addresses). Function equality144// cannot be determined and will always fail.145func Equal(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {146 if h, ok := t.(tHelper); ok {147 h.Helper()148 }149 if assert.Equal(t, expected, actual, msgAndArgs...) {150 return151 }152 t.FailNow()153}154// EqualError asserts that a function returned an error (i.e. not `nil`)155// and that it is equal to the provided error.156//157// actualObj, err := SomeFunction()158// assert.EqualError(t, err, expectedErrorString)159func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) {160 if h, ok := t.(tHelper); ok {161 h.Helper()162 }163 if assert.EqualError(t, theError, errString, msgAndArgs...) {164 return165 }166 t.FailNow()167}168// EqualErrorf asserts that a function returned an error (i.e. not `nil`)169// and that it is equal to the provided error.170//171// actualObj, err := SomeFunction()172// assert.EqualErrorf(t, err, expectedErrorString, "error message %s", "formatted")173func EqualErrorf(t TestingT, theError error, errString string, msg string, args ...interface{}) {174 if h, ok := t.(tHelper); ok {175 h.Helper()176 }177 if assert.EqualErrorf(t, theError, errString, msg, args...) {178 return179 }180 t.FailNow()181}182// EqualValues asserts that two objects are equal or convertable to the same types183// and equal.184//185// assert.EqualValues(t, uint32(123), int32(123))186func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {187 if h, ok := t.(tHelper); ok {188 h.Helper()189 }190 if assert.EqualValues(t, expected, actual, msgAndArgs...) {191 return192 }193 t.FailNow()194}195// EqualValuesf asserts that two objects are equal or convertable to the same types196// and equal.197//198// assert.EqualValuesf(t, uint32(123), int32(123), "error message %s", "formatted")199func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {200 if h, ok := t.(tHelper); ok {201 h.Helper()202 }203 if assert.EqualValuesf(t, expected, actual, msg, args...) {204 return205 }206 t.FailNow()207}208// Equalf asserts that two objects are equal.209//210// assert.Equalf(t, 123, 123, "error message %s", "formatted")211//212// Pointer variable equality is determined based on the equality of the213// referenced values (as opposed to the memory addresses). Function equality214// cannot be determined and will always fail.215func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {216 if h, ok := t.(tHelper); ok {217 h.Helper()218 }219 if assert.Equalf(t, expected, actual, msg, args...) {220 return221 }222 t.FailNow()223}224// Error asserts that a function returned an error (i.e. not `nil`).225//226// actualObj, err := SomeFunction()227// if assert.Error(t, err) {228// assert.Equal(t, expectedError, err)229// }230func Error(t TestingT, err error, msgAndArgs ...interface{}) {231 if h, ok := t.(tHelper); ok {232 h.Helper()233 }234 if assert.Error(t, err, msgAndArgs...) {235 return236 }237 t.FailNow()238}239// Errorf asserts that a function returned an error (i.e. not `nil`).240//241// actualObj, err := SomeFunction()242// if assert.Errorf(t, err, "error message %s", "formatted") {243// assert.Equal(t, expectedErrorf, err)244// }245func Errorf(t TestingT, err error, msg string, args ...interface{}) {246 if h, ok := t.(tHelper); ok {247 h.Helper()248 }249 if assert.Errorf(t, err, msg, args...) {250 return251 }252 t.FailNow()253}254// Eventually asserts that given condition will be met in waitFor time,255// periodically checking target function each tick.256//257// assert.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond)258func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) {259 if h, ok := t.(tHelper); ok {260 h.Helper()261 }262 if assert.Eventually(t, condition, waitFor, tick, msgAndArgs...) {263 return264 }265 t.FailNow()266}267// Eventuallyf asserts that given condition will be met in waitFor time,268// periodically checking target function each tick.269//270// assert.Eventuallyf(t, func() bool { return true; }, time.Second, 10*time.Millisecond, "error message %s", "formatted")271func Eventuallyf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) {272 if h, ok := t.(tHelper); ok {273 h.Helper()274 }275 if assert.Eventuallyf(t, condition, waitFor, tick, msg, args...) {276 return277 }278 t.FailNow()279}280// Exactly asserts that two objects are equal in value and type.281//282// assert.Exactly(t, int32(123), int64(123))283func Exactly(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {284 if h, ok := t.(tHelper); ok {285 h.Helper()286 }287 if assert.Exactly(t, expected, actual, msgAndArgs...) {288 return289 }290 t.FailNow()291}292// Exactlyf asserts that two objects are equal in value and type.293//294// assert.Exactlyf(t, int32(123), int64(123), "error message %s", "formatted")295func Exactlyf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {296 if h, ok := t.(tHelper); ok {297 h.Helper()298 }299 if assert.Exactlyf(t, expected, actual, msg, args...) {300 return301 }302 t.FailNow()303}304// Fail reports a failure through305func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) {306 if h, ok := t.(tHelper); ok {307 h.Helper()308 }309 if assert.Fail(t, failureMessage, msgAndArgs...) {310 return311 }312 t.FailNow()313}314// FailNow fails test315func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) {316 if h, ok := t.(tHelper); ok {317 h.Helper()318 }319 if assert.FailNow(t, failureMessage, msgAndArgs...) {320 return321 }322 t.FailNow()323}324// FailNowf fails test325func FailNowf(t TestingT, failureMessage string, msg string, args ...interface{}) {326 if h, ok := t.(tHelper); ok {327 h.Helper()328 }329 if assert.FailNowf(t, failureMessage, msg, args...) {330 return331 }332 t.FailNow()333}334// Failf reports a failure through335func Failf(t TestingT, failureMessage string, msg string, args ...interface{}) {336 if h, ok := t.(tHelper); ok {337 h.Helper()338 }339 if assert.Failf(t, failureMessage, msg, args...) {340 return341 }342 t.FailNow()343}344// False asserts that the specified value is false.345//346// assert.False(t, myBool)347func False(t TestingT, value bool, msgAndArgs ...interface{}) {348 if h, ok := t.(tHelper); ok {349 h.Helper()350 }351 if assert.False(t, value, msgAndArgs...) {352 return353 }354 t.FailNow()355}356// Falsef asserts that the specified value is false.357//358// assert.Falsef(t, myBool, "error message %s", "formatted")359func Falsef(t TestingT, value bool, msg string, args ...interface{}) {360 if h, ok := t.(tHelper); ok {361 h.Helper()362 }363 if assert.Falsef(t, value, msg, args...) {364 return365 }366 t.FailNow()367}368// FileExists checks whether a file exists in the given path. It also fails if369// the path points to a directory or there is an error when trying to check the file.370func FileExists(t TestingT, path string, msgAndArgs ...interface{}) {371 if h, ok := t.(tHelper); ok {372 h.Helper()373 }374 if assert.FileExists(t, path, msgAndArgs...) {375 return376 }377 t.FailNow()378}379// FileExistsf checks whether a file exists in the given path. It also fails if380// the path points to a directory or there is an error when trying to check the file.381func FileExistsf(t TestingT, path string, msg string, args ...interface{}) {382 if h, ok := t.(tHelper); ok {383 h.Helper()384 }385 if assert.FileExistsf(t, path, msg, args...) {386 return387 }388 t.FailNow()389}390// Greater asserts that the first element is greater than the second391//392// assert.Greater(t, 2, 1)393// assert.Greater(t, float64(2), float64(1))394// assert.Greater(t, "b", "a")395func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) {396 if h, ok := t.(tHelper); ok {397 h.Helper()398 }399 if assert.Greater(t, e1, e2, msgAndArgs...) {400 return401 }402 t.FailNow()403}404// GreaterOrEqual asserts that the first element is greater than or equal to the second405//406// assert.GreaterOrEqual(t, 2, 1)407// assert.GreaterOrEqual(t, 2, 2)408// assert.GreaterOrEqual(t, "b", "a")409// assert.GreaterOrEqual(t, "b", "b")410func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) {411 if h, ok := t.(tHelper); ok {412 h.Helper()413 }414 if assert.GreaterOrEqual(t, e1, e2, msgAndArgs...) {415 return416 }417 t.FailNow()418}419// GreaterOrEqualf asserts that the first element is greater than or equal to the second420//421// assert.GreaterOrEqualf(t, 2, 1, "error message %s", "formatted")422// assert.GreaterOrEqualf(t, 2, 2, "error message %s", "formatted")423// assert.GreaterOrEqualf(t, "b", "a", "error message %s", "formatted")424// assert.GreaterOrEqualf(t, "b", "b", "error message %s", "formatted")425func GreaterOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) {426 if h, ok := t.(tHelper); ok {427 h.Helper()428 }429 if assert.GreaterOrEqualf(t, e1, e2, msg, args...) {430 return431 }432 t.FailNow()433}434// Greaterf asserts that the first element is greater than the second435//436// assert.Greaterf(t, 2, 1, "error message %s", "formatted")437// assert.Greaterf(t, float64(2), float64(1), "error message %s", "formatted")438// assert.Greaterf(t, "b", "a", "error message %s", "formatted")439func Greaterf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) {440 if h, ok := t.(tHelper); ok {441 h.Helper()442 }443 if assert.Greaterf(t, e1, e2, msg, args...) {444 return445 }446 t.FailNow()447}448// HTTPBodyContains asserts that a specified handler returns a449// body that contains a string.450//451// assert.HTTPBodyContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")452//453// Returns whether the assertion was successful (true) or not (false).454func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) {455 if h, ok := t.(tHelper); ok {456 h.Helper()457 }458 if assert.HTTPBodyContains(t, handler, method, url, values, str, msgAndArgs...) {459 return460 }461 t.FailNow()462}463// HTTPBodyContainsf asserts that a specified handler returns a464// body that contains a string.465//466// assert.HTTPBodyContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")467//468// Returns whether the assertion was successful (true) or not (false).469func HTTPBodyContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) {470 if h, ok := t.(tHelper); ok {471 h.Helper()472 }473 if assert.HTTPBodyContainsf(t, handler, method, url, values, str, msg, args...) {474 return475 }476 t.FailNow()477}478// HTTPBodyNotContains asserts that a specified handler returns a479// body that does not contain a string.480//481// assert.HTTPBodyNotContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")482//483// Returns whether the assertion was successful (true) or not (false).484func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) {485 if h, ok := t.(tHelper); ok {486 h.Helper()487 }488 if assert.HTTPBodyNotContains(t, handler, method, url, values, str, msgAndArgs...) {489 return490 }491 t.FailNow()492}493// HTTPBodyNotContainsf asserts that a specified handler returns a494// body that does not contain a string.495//496// assert.HTTPBodyNotContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")497//498// Returns whether the assertion was successful (true) or not (false).499func HTTPBodyNotContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) {500 if h, ok := t.(tHelper); ok {501 h.Helper()502 }503 if assert.HTTPBodyNotContainsf(t, handler, method, url, values, str, msg, args...) {504 return505 }506 t.FailNow()507}508// HTTPError asserts that a specified handler returns an error status code.509//510// assert.HTTPError(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}511//512// Returns whether the assertion was successful (true) or not (false).513func HTTPError(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) {514 if h, ok := t.(tHelper); ok {515 h.Helper()516 }517 if assert.HTTPError(t, handler, method, url, values, msgAndArgs...) {518 return519 }520 t.FailNow()521}522// HTTPErrorf asserts that a specified handler returns an error status code.523//524// assert.HTTPErrorf(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}525//526// Returns whether the assertion was successful (true) or not (false).527func HTTPErrorf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) {528 if h, ok := t.(tHelper); ok {529 h.Helper()530 }531 if assert.HTTPErrorf(t, handler, method, url, values, msg, args...) {532 return533 }534 t.FailNow()535}536// HTTPRedirect asserts that a specified handler returns a redirect status code.537//538// assert.HTTPRedirect(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}539//540// Returns whether the assertion was successful (true) or not (false).541func HTTPRedirect(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) {542 if h, ok := t.(tHelper); ok {543 h.Helper()544 }545 if assert.HTTPRedirect(t, handler, method, url, values, msgAndArgs...) {546 return547 }548 t.FailNow()549}550// HTTPRedirectf asserts that a specified handler returns a redirect status code.551//552// assert.HTTPRedirectf(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}553//554// Returns whether the assertion was successful (true) or not (false).555func HTTPRedirectf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) {556 if h, ok := t.(tHelper); ok {557 h.Helper()558 }559 if assert.HTTPRedirectf(t, handler, method, url, values, msg, args...) {560 return561 }562 t.FailNow()563}564// HTTPStatusCode asserts that a specified handler returns a specified status code.565//566// assert.HTTPStatusCode(t, myHandler, "GET", "/notImplemented", nil, 501)567//568// Returns whether the assertion was successful (true) or not (false).569func HTTPStatusCode(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msgAndArgs ...interface{}) {570 if h, ok := t.(tHelper); ok {571 h.Helper()572 }573 if assert.HTTPStatusCode(t, handler, method, url, values, statuscode, msgAndArgs...) {574 return575 }576 t.FailNow()577}578// HTTPStatusCodef asserts that a specified handler returns a specified status code.579//580// assert.HTTPStatusCodef(t, myHandler, "GET", "/notImplemented", nil, 501, "error message %s", "formatted")581//582// Returns whether the assertion was successful (true) or not (false).583func HTTPStatusCodef(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msg string, args ...interface{}) {584 if h, ok := t.(tHelper); ok {585 h.Helper()586 }587 if assert.HTTPStatusCodef(t, handler, method, url, values, statuscode, msg, args...) {588 return589 }590 t.FailNow()591}592// HTTPSuccess asserts that a specified handler returns a success status code.593//594// assert.HTTPSuccess(t, myHandler, "POST", "http://www.google.com", nil)595//596// Returns whether the assertion was successful (true) or not (false).597func HTTPSuccess(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) {598 if h, ok := t.(tHelper); ok {599 h.Helper()600 }601 if assert.HTTPSuccess(t, handler, method, url, values, msgAndArgs...) {602 return603 }604 t.FailNow()605}606// HTTPSuccessf asserts that a specified handler returns a success status code.607//608// assert.HTTPSuccessf(t, myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted")609//610// Returns whether the assertion was successful (true) or not (false).611func HTTPSuccessf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) {612 if h, ok := t.(tHelper); ok {613 h.Helper()614 }615 if assert.HTTPSuccessf(t, handler, method, url, values, msg, args...) {616 return617 }618 t.FailNow()619}620// Implements asserts that an object is implemented by the specified interface.621//622// assert.Implements(t, (*MyInterface)(nil), new(MyObject))623func Implements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) {624 if h, ok := t.(tHelper); ok {625 h.Helper()626 }627 if assert.Implements(t, interfaceObject, object, msgAndArgs...) {628 return629 }630 t.FailNow()631}632// Implementsf asserts that an object is implemented by the specified interface.633//634// assert.Implementsf(t, (*MyInterface)(nil), new(MyObject), "error message %s", "formatted")635func Implementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) {636 if h, ok := t.(tHelper); ok {637 h.Helper()638 }639 if assert.Implementsf(t, interfaceObject, object, msg, args...) {640 return641 }642 t.FailNow()643}644// InDelta asserts that the two numerals are within delta of each other.645//646// assert.InDelta(t, math.Pi, 22/7.0, 0.01)647func InDelta(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {648 if h, ok := t.(tHelper); ok {649 h.Helper()650 }651 if assert.InDelta(t, expected, actual, delta, msgAndArgs...) {652 return653 }654 t.FailNow()655}656// InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.657func InDeltaMapValues(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {658 if h, ok := t.(tHelper); ok {659 h.Helper()660 }661 if assert.InDeltaMapValues(t, expected, actual, delta, msgAndArgs...) {662 return663 }664 t.FailNow()665}666// InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.667func InDeltaMapValuesf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) {668 if h, ok := t.(tHelper); ok {669 h.Helper()670 }671 if assert.InDeltaMapValuesf(t, expected, actual, delta, msg, args...) {672 return673 }674 t.FailNow()675}676// InDeltaSlice is the same as InDelta, except it compares two slices.677func InDeltaSlice(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {678 if h, ok := t.(tHelper); ok {679 h.Helper()680 }681 if assert.InDeltaSlice(t, expected, actual, delta, msgAndArgs...) {682 return683 }684 t.FailNow()685}686// InDeltaSlicef is the same as InDelta, except it compares two slices.687func InDeltaSlicef(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) {688 if h, ok := t.(tHelper); ok {689 h.Helper()690 }691 if assert.InDeltaSlicef(t, expected, actual, delta, msg, args...) {692 return693 }694 t.FailNow()695}696// InDeltaf asserts that the two numerals are within delta of each other.697//698// assert.InDeltaf(t, math.Pi, 22/7.0, 0.01, "error message %s", "formatted")699func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) {700 if h, ok := t.(tHelper); ok {701 h.Helper()702 }703 if assert.InDeltaf(t, expected, actual, delta, msg, args...) {704 return705 }706 t.FailNow()707}708// InEpsilon asserts that expected and actual have a relative error less than epsilon709func InEpsilon(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) {710 if h, ok := t.(tHelper); ok {711 h.Helper()712 }713 if assert.InEpsilon(t, expected, actual, epsilon, msgAndArgs...) {714 return715 }716 t.FailNow()717}718// InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices.719func InEpsilonSlice(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) {720 if h, ok := t.(tHelper); ok {721 h.Helper()722 }723 if assert.InEpsilonSlice(t, expected, actual, epsilon, msgAndArgs...) {724 return725 }726 t.FailNow()727}728// InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices.729func InEpsilonSlicef(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) {730 if h, ok := t.(tHelper); ok {731 h.Helper()732 }733 if assert.InEpsilonSlicef(t, expected, actual, epsilon, msg, args...) {734 return735 }736 t.FailNow()737}738// InEpsilonf asserts that expected and actual have a relative error less than epsilon739func InEpsilonf(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) {740 if h, ok := t.(tHelper); ok {741 h.Helper()742 }743 if assert.InEpsilonf(t, expected, actual, epsilon, msg, args...) {744 return745 }746 t.FailNow()747}748// IsType asserts that the specified objects are of the same type.749func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) {750 if h, ok := t.(tHelper); ok {751 h.Helper()752 }753 if assert.IsType(t, expectedType, object, msgAndArgs...) {754 return755 }756 t.FailNow()757}758// IsTypef asserts that the specified objects are of the same type.759func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, args ...interface{}) {760 if h, ok := t.(tHelper); ok {761 h.Helper()762 }763 if assert.IsTypef(t, expectedType, object, msg, args...) {764 return765 }766 t.FailNow()767}768// JSONEq asserts that two JSON strings are equivalent.769//770// assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)771func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) {772 if h, ok := t.(tHelper); ok {773 h.Helper()774 }775 if assert.JSONEq(t, expected, actual, msgAndArgs...) {776 return777 }778 t.FailNow()779}780// JSONEqf asserts that two JSON strings are equivalent.781//782// assert.JSONEqf(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted")783func JSONEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) {784 if h, ok := t.(tHelper); ok {785 h.Helper()786 }787 if assert.JSONEqf(t, expected, actual, msg, args...) {788 return789 }790 t.FailNow()791}792// Len asserts that the specified object has specific length.793// Len also fails if the object has a type that len() not accept.794//795// assert.Len(t, mySlice, 3)796func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) {797 if h, ok := t.(tHelper); ok {798 h.Helper()799 }800 if assert.Len(t, object, length, msgAndArgs...) {801 return802 }803 t.FailNow()804}805// Lenf asserts that the specified object has specific length.806// Lenf also fails if the object has a type that len() not accept.807//808// assert.Lenf(t, mySlice, 3, "error message %s", "formatted")809func Lenf(t TestingT, object interface{}, length int, msg string, args ...interface{}) {810 if h, ok := t.(tHelper); ok {811 h.Helper()812 }813 if assert.Lenf(t, object, length, msg, args...) {814 return815 }816 t.FailNow()817}818// Less asserts that the first element is less than the second819//820// assert.Less(t, 1, 2)821// assert.Less(t, float64(1), float64(2))822// assert.Less(t, "a", "b")823func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) {824 if h, ok := t.(tHelper); ok {825 h.Helper()826 }827 if assert.Less(t, e1, e2, msgAndArgs...) {828 return829 }830 t.FailNow()831}832// LessOrEqual asserts that the first element is less than or equal to the second833//834// assert.LessOrEqual(t, 1, 2)835// assert.LessOrEqual(t, 2, 2)836// assert.LessOrEqual(t, "a", "b")837// assert.LessOrEqual(t, "b", "b")838func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) {839 if h, ok := t.(tHelper); ok {840 h.Helper()841 }842 if assert.LessOrEqual(t, e1, e2, msgAndArgs...) {843 return844 }845 t.FailNow()846}847// LessOrEqualf asserts that the first element is less than or equal to the second848//849// assert.LessOrEqualf(t, 1, 2, "error message %s", "formatted")850// assert.LessOrEqualf(t, 2, 2, "error message %s", "formatted")851// assert.LessOrEqualf(t, "a", "b", "error message %s", "formatted")852// assert.LessOrEqualf(t, "b", "b", "error message %s", "formatted")853func LessOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) {854 if h, ok := t.(tHelper); ok {855 h.Helper()856 }857 if assert.LessOrEqualf(t, e1, e2, msg, args...) {858 return859 }860 t.FailNow()861}862// Lessf asserts that the first element is less than the second863//864// assert.Lessf(t, 1, 2, "error message %s", "formatted")865// assert.Lessf(t, float64(1), float64(2), "error message %s", "formatted")866// assert.Lessf(t, "a", "b", "error message %s", "formatted")867func Lessf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) {868 if h, ok := t.(tHelper); ok {869 h.Helper()870 }871 if assert.Lessf(t, e1, e2, msg, args...) {872 return873 }874 t.FailNow()875}876// Never asserts that the given condition doesn't satisfy in waitFor time,877// periodically checking the target function each tick.878//879// assert.Never(t, func() bool { return false; }, time.Second, 10*time.Millisecond)880func Never(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) {881 if h, ok := t.(tHelper); ok {882 h.Helper()883 }884 if assert.Never(t, condition, waitFor, tick, msgAndArgs...) {885 return886 }887 t.FailNow()888}889// Neverf asserts that the given condition doesn't satisfy in waitFor time,890// periodically checking the target function each tick.891//892// assert.Neverf(t, func() bool { return false; }, time.Second, 10*time.Millisecond, "error message %s", "formatted")893func Neverf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) {894 if h, ok := t.(tHelper); ok {895 h.Helper()896 }897 if assert.Neverf(t, condition, waitFor, tick, msg, args...) {898 return899 }900 t.FailNow()901}902// Nil asserts that the specified object is nil.903//904// assert.Nil(t, err)905func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) {906 if h, ok := t.(tHelper); ok {907 h.Helper()908 }909 if assert.Nil(t, object, msgAndArgs...) {910 return911 }912 t.FailNow()913}914// Nilf asserts that the specified object is nil.915//916// assert.Nilf(t, err, "error message %s", "formatted")917func Nilf(t TestingT, object interface{}, msg string, args ...interface{}) {918 if h, ok := t.(tHelper); ok {919 h.Helper()920 }921 if assert.Nilf(t, object, msg, args...) {922 return923 }924 t.FailNow()925}926// NoDirExists checks whether a directory does not exist in the given path.927// It fails if the path points to an existing _directory_ only.928func NoDirExists(t TestingT, path string, msgAndArgs ...interface{}) {929 if h, ok := t.(tHelper); ok {930 h.Helper()931 }932 if assert.NoDirExists(t, path, msgAndArgs...) {933 return934 }935 t.FailNow()936}937// NoDirExistsf checks whether a directory does not exist in the given path.938// It fails if the path points to an existing _directory_ only.939func NoDirExistsf(t TestingT, path string, msg string, args ...interface{}) {940 if h, ok := t.(tHelper); ok {941 h.Helper()942 }943 if assert.NoDirExistsf(t, path, msg, args...) {944 return945 }946 t.FailNow()947}948// NoError asserts that a function returned no error (i.e. `nil`).949//950// actualObj, err := SomeFunction()951// if assert.NoError(t, err) {952// assert.Equal(t, expectedObj, actualObj)953// }954func NoError(t TestingT, err error, msgAndArgs ...interface{}) {955 if h, ok := t.(tHelper); ok {956 h.Helper()957 }958 if assert.NoError(t, err, msgAndArgs...) {959 return960 }961 t.FailNow()962}963// NoErrorf asserts that a function returned no error (i.e. `nil`).964//965// actualObj, err := SomeFunction()966// if assert.NoErrorf(t, err, "error message %s", "formatted") {967// assert.Equal(t, expectedObj, actualObj)968// }969func NoErrorf(t TestingT, err error, msg string, args ...interface{}) {970 if h, ok := t.(tHelper); ok {971 h.Helper()972 }973 if assert.NoErrorf(t, err, msg, args...) {974 return975 }976 t.FailNow()977}978// NoFileExists checks whether a file does not exist in a given path. It fails979// if the path points to an existing _file_ only.980func NoFileExists(t TestingT, path string, msgAndArgs ...interface{}) {981 if h, ok := t.(tHelper); ok {982 h.Helper()983 }984 if assert.NoFileExists(t, path, msgAndArgs...) {985 return986 }987 t.FailNow()988}989// NoFileExistsf checks whether a file does not exist in a given path. It fails990// if the path points to an existing _file_ only.991func NoFileExistsf(t TestingT, path string, msg string, args ...interface{}) {992 if h, ok := t.(tHelper); ok {993 h.Helper()994 }995 if assert.NoFileExistsf(t, path, msg, args...) {996 return997 }998 t.FailNow()999}1000// NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the1001// specified substring or element.1002//1003// assert.NotContains(t, "Hello World", "Earth")1004// assert.NotContains(t, ["Hello", "World"], "Earth")1005// assert.NotContains(t, {"Hello": "World"}, "Earth")1006func NotContains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) {1007 if h, ok := t.(tHelper); ok {1008 h.Helper()1009 }1010 if assert.NotContains(t, s, contains, msgAndArgs...) {1011 return1012 }1013 t.FailNow()1014}1015// NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the1016// specified substring or element.1017//1018// assert.NotContainsf(t, "Hello World", "Earth", "error message %s", "formatted")1019// assert.NotContainsf(t, ["Hello", "World"], "Earth", "error message %s", "formatted")1020// assert.NotContainsf(t, {"Hello": "World"}, "Earth", "error message %s", "formatted")1021func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) {1022 if h, ok := t.(tHelper); ok {1023 h.Helper()1024 }1025 if assert.NotContainsf(t, s, contains, msg, args...) {1026 return1027 }1028 t.FailNow()1029}1030// NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either1031// a slice or a channel with len == 0.1032//1033// if assert.NotEmpty(t, obj) {1034// assert.Equal(t, "two", obj[1])1035// }1036func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) {1037 if h, ok := t.(tHelper); ok {1038 h.Helper()1039 }1040 if assert.NotEmpty(t, object, msgAndArgs...) {1041 return1042 }1043 t.FailNow()1044}1045// NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either1046// a slice or a channel with len == 0.1047//1048// if assert.NotEmptyf(t, obj, "error message %s", "formatted") {1049// assert.Equal(t, "two", obj[1])1050// }1051func NotEmptyf(t TestingT, object interface{}, msg string, args ...interface{}) {1052 if h, ok := t.(tHelper); ok {1053 h.Helper()1054 }1055 if assert.NotEmptyf(t, object, msg, args...) {1056 return1057 }1058 t.FailNow()1059}1060// NotEqual asserts that the specified values are NOT equal.1061//1062// assert.NotEqual(t, obj1, obj2)1063//1064// Pointer variable equality is determined based on the equality of the1065// referenced values (as opposed to the memory addresses).1066func NotEqual(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {1067 if h, ok := t.(tHelper); ok {1068 h.Helper()1069 }1070 if assert.NotEqual(t, expected, actual, msgAndArgs...) {1071 return1072 }1073 t.FailNow()1074}1075// NotEqualValues asserts that two objects are not equal even when converted to the same type1076//1077// assert.NotEqualValues(t, obj1, obj2)1078func NotEqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {1079 if h, ok := t.(tHelper); ok {1080 h.Helper()1081 }1082 if assert.NotEqualValues(t, expected, actual, msgAndArgs...) {1083 return1084 }1085 t.FailNow()1086}1087// NotEqualValuesf asserts that two objects are not equal even when converted to the same type1088//1089// assert.NotEqualValuesf(t, obj1, obj2, "error message %s", "formatted")1090func NotEqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {1091 if h, ok := t.(tHelper); ok {1092 h.Helper()1093 }1094 if assert.NotEqualValuesf(t, expected, actual, msg, args...) {1095 return1096 }1097 t.FailNow()1098}1099// NotEqualf asserts that the specified values are NOT equal.1100//1101// assert.NotEqualf(t, obj1, obj2, "error message %s", "formatted")1102//1103// Pointer variable equality is determined based on the equality of the1104// referenced values (as opposed to the memory addresses).1105func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {1106 if h, ok := t.(tHelper); ok {1107 h.Helper()1108 }1109 if assert.NotEqualf(t, expected, actual, msg, args...) {1110 return1111 }1112 t.FailNow()1113}1114// NotNil asserts that the specified object is not nil.1115//1116// assert.NotNil(t, err)1117func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) {1118 if h, ok := t.(tHelper); ok {1119 h.Helper()1120 }1121 if assert.NotNil(t, object, msgAndArgs...) {1122 return1123 }1124 t.FailNow()1125}1126// NotNilf asserts that the specified object is not nil.1127//1128// assert.NotNilf(t, err, "error message %s", "formatted")1129func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) {1130 if h, ok := t.(tHelper); ok {1131 h.Helper()1132 }1133 if assert.NotNilf(t, object, msg, args...) {1134 return1135 }1136 t.FailNow()1137}1138// NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.1139//1140// assert.NotPanics(t, func(){ RemainCalm() })1141func NotPanics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) {1142 if h, ok := t.(tHelper); ok {1143 h.Helper()1144 }1145 if assert.NotPanics(t, f, msgAndArgs...) {1146 return1147 }1148 t.FailNow()1149}1150// NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic.1151//1152// assert.NotPanicsf(t, func(){ RemainCalm() }, "error message %s", "formatted")1153func NotPanicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{}) {1154 if h, ok := t.(tHelper); ok {1155 h.Helper()1156 }1157 if assert.NotPanicsf(t, f, msg, args...) {1158 return1159 }1160 t.FailNow()1161}1162// NotRegexp asserts that a specified regexp does not match a string.1163//1164// assert.NotRegexp(t, regexp.MustCompile("starts"), "it's starting")1165// assert.NotRegexp(t, "^start", "it's not starting")1166func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) {1167 if h, ok := t.(tHelper); ok {1168 h.Helper()1169 }1170 if assert.NotRegexp(t, rx, str, msgAndArgs...) {1171 return1172 }1173 t.FailNow()1174}1175// NotRegexpf asserts that a specified regexp does not match a string.1176//1177// assert.NotRegexpf(t, regexp.MustCompile("starts"), "it's starting", "error message %s", "formatted")1178// assert.NotRegexpf(t, "^start", "it's not starting", "error message %s", "formatted")1179func NotRegexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) {1180 if h, ok := t.(tHelper); ok {1181 h.Helper()1182 }1183 if assert.NotRegexpf(t, rx, str, msg, args...) {1184 return1185 }1186 t.FailNow()1187}1188// NotSame asserts that two pointers do not reference the same object.1189//1190// assert.NotSame(t, ptr1, ptr2)1191//1192// Both arguments must be pointer variables. Pointer variable sameness is1193// determined based on the equality of both type and value.1194func NotSame(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {1195 if h, ok := t.(tHelper); ok {1196 h.Helper()1197 }1198 if assert.NotSame(t, expected, actual, msgAndArgs...) {1199 return1200 }1201 t.FailNow()1202}1203// NotSamef asserts that two pointers do not reference the same object.1204//1205// assert.NotSamef(t, ptr1, ptr2, "error message %s", "formatted")1206//1207// Both arguments must be pointer variables. Pointer variable sameness is1208// determined based on the equality of both type and value.1209func NotSamef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {1210 if h, ok := t.(tHelper); ok {1211 h.Helper()1212 }1213 if assert.NotSamef(t, expected, actual, msg, args...) {1214 return1215 }1216 t.FailNow()1217}1218// NotSubset asserts that the specified list(array, slice...) contains not all1219// elements given in the specified subset(array, slice...).1220//1221// assert.NotSubset(t, [1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]")1222func NotSubset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) {1223 if h, ok := t.(tHelper); ok {1224 h.Helper()1225 }1226 if assert.NotSubset(t, list, subset, msgAndArgs...) {1227 return1228 }1229 t.FailNow()1230}1231// NotSubsetf asserts that the specified list(array, slice...) contains not all1232// elements given in the specified subset(array, slice...).1233//1234// assert.NotSubsetf(t, [1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]", "error message %s", "formatted")1235func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) {1236 if h, ok := t.(tHelper); ok {1237 h.Helper()1238 }1239 if assert.NotSubsetf(t, list, subset, msg, args...) {1240 return1241 }1242 t.FailNow()1243}1244// NotZero asserts that i is not the zero value for its type.1245func NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) {1246 if h, ok := t.(tHelper); ok {1247 h.Helper()1248 }1249 if assert.NotZero(t, i, msgAndArgs...) {1250 return1251 }1252 t.FailNow()1253}1254// NotZerof asserts that i is not the zero value for its type.1255func NotZerof(t TestingT, i interface{}, msg string, args ...interface{}) {1256 if h, ok := t.(tHelper); ok {1257 h.Helper()1258 }1259 if assert.NotZerof(t, i, msg, args...) {1260 return1261 }1262 t.FailNow()1263}1264// Panics asserts that the code inside the specified PanicTestFunc panics.1265//1266// assert.Panics(t, func(){ GoCrazy() })1267func Panics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) {1268 if h, ok := t.(tHelper); ok {1269 h.Helper()1270 }1271 if assert.Panics(t, f, msgAndArgs...) {1272 return1273 }1274 t.FailNow()1275}1276// PanicsWithError asserts that the code inside the specified PanicTestFunc1277// panics, and that the recovered panic value is an error that satisfies the1278// EqualError comparison.1279//1280// assert.PanicsWithError(t, "crazy error", func(){ GoCrazy() })1281func PanicsWithError(t TestingT, errString string, f assert.PanicTestFunc, msgAndArgs ...interface{}) {1282 if h, ok := t.(tHelper); ok {1283 h.Helper()1284 }1285 if assert.PanicsWithError(t, errString, f, msgAndArgs...) {1286 return1287 }1288 t.FailNow()1289}1290// PanicsWithErrorf asserts that the code inside the specified PanicTestFunc1291// panics, and that the recovered panic value is an error that satisfies the1292// EqualError comparison.1293//1294// assert.PanicsWithErrorf(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted")1295func PanicsWithErrorf(t TestingT, errString string, f assert.PanicTestFunc, msg string, args ...interface{}) {1296 if h, ok := t.(tHelper); ok {1297 h.Helper()1298 }1299 if assert.PanicsWithErrorf(t, errString, f, msg, args...) {1300 return1301 }1302 t.FailNow()1303}1304// PanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that1305// the recovered panic value equals the expected panic value.1306//1307// assert.PanicsWithValue(t, "crazy error", func(){ GoCrazy() })1308func PanicsWithValue(t TestingT, expected interface{}, f assert.PanicTestFunc, msgAndArgs ...interface{}) {1309 if h, ok := t.(tHelper); ok {1310 h.Helper()1311 }1312 if assert.PanicsWithValue(t, expected, f, msgAndArgs...) {1313 return1314 }1315 t.FailNow()1316}1317// PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that1318// the recovered panic value equals the expected panic value.1319//1320// assert.PanicsWithValuef(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted")1321func PanicsWithValuef(t TestingT, expected interface{}, f assert.PanicTestFunc, msg string, args ...interface{}) {1322 if h, ok := t.(tHelper); ok {1323 h.Helper()1324 }1325 if assert.PanicsWithValuef(t, expected, f, msg, args...) {1326 return1327 }1328 t.FailNow()1329}1330// Panicsf asserts that the code inside the specified PanicTestFunc panics.1331//1332// assert.Panicsf(t, func(){ GoCrazy() }, "error message %s", "formatted")1333func Panicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{}) {1334 if h, ok := t.(tHelper); ok {1335 h.Helper()1336 }1337 if assert.Panicsf(t, f, msg, args...) {1338 return1339 }1340 t.FailNow()1341}1342// Regexp asserts that a specified regexp matches a string.1343//1344// assert.Regexp(t, regexp.MustCompile("start"), "it's starting")1345// assert.Regexp(t, "start...$", "it's not starting")1346func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) {1347 if h, ok := t.(tHelper); ok {1348 h.Helper()1349 }1350 if assert.Regexp(t, rx, str, msgAndArgs...) {1351 return1352 }1353 t.FailNow()1354}1355// Regexpf asserts that a specified regexp matches a string.1356//1357// assert.Regexpf(t, regexp.MustCompile("start"), "it's starting", "error message %s", "formatted")1358// assert.Regexpf(t, "start...$", "it's not starting", "error message %s", "formatted")1359func Regexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) {1360 if h, ok := t.(tHelper); ok {1361 h.Helper()1362 }1363 if assert.Regexpf(t, rx, str, msg, args...) {1364 return1365 }1366 t.FailNow()1367}1368// Same asserts that two pointers reference the same object.1369//1370// assert.Same(t, ptr1, ptr2)1371//1372// Both arguments must be pointer variables. Pointer variable sameness is1373// determined based on the equality of both type and value.1374func Same(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {1375 if h, ok := t.(tHelper); ok {1376 h.Helper()1377 }1378 if assert.Same(t, expected, actual, msgAndArgs...) {1379 return1380 }1381 t.FailNow()1382}1383// Samef asserts that two pointers reference the same object.1384//1385// assert.Samef(t, ptr1, ptr2, "error message %s", "formatted")1386//1387// Both arguments must be pointer variables. Pointer variable sameness is1388// determined based on the equality of both type and value.1389func Samef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) {1390 if h, ok := t.(tHelper); ok {1391 h.Helper()1392 }1393 if assert.Samef(t, expected, actual, msg, args...) {1394 return1395 }1396 t.FailNow()1397}1398// Subset asserts that the specified list(array, slice...) contains all1399// elements given in the specified subset(array, slice...).1400//1401// assert.Subset(t, [1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]")1402func Subset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) {1403 if h, ok := t.(tHelper); ok {1404 h.Helper()1405 }1406 if assert.Subset(t, list, subset, msgAndArgs...) {1407 return1408 }1409 t.FailNow()1410}1411// Subsetf asserts that the specified list(array, slice...) contains all1412// elements given in the specified subset(array, slice...).1413//1414// assert.Subsetf(t, [1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]", "error message %s", "formatted")1415func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) {1416 if h, ok := t.(tHelper); ok {1417 h.Helper()1418 }1419 if assert.Subsetf(t, list, subset, msg, args...) {1420 return1421 }1422 t.FailNow()1423}1424// True asserts that the specified value is true.1425//1426// assert.True(t, myBool)1427func True(t TestingT, value bool, msgAndArgs ...interface{}) {1428 if h, ok := t.(tHelper); ok {1429 h.Helper()1430 }1431 if assert.True(t, value, msgAndArgs...) {1432 return1433 }1434 t.FailNow()1435}1436// Truef asserts that the specified value is true.1437//1438// assert.Truef(t, myBool, "error message %s", "formatted")1439func Truef(t TestingT, value bool, msg string, args ...interface{}) {1440 if h, ok := t.(tHelper); ok {1441 h.Helper()1442 }1443 if assert.Truef(t, value, msg, args...) {1444 return1445 }1446 t.FailNow()1447}1448// WithinDuration asserts that the two times are within duration delta of each other.1449//1450// assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second)1451func WithinDuration(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) {1452 if h, ok := t.(tHelper); ok {1453 h.Helper()1454 }1455 if assert.WithinDuration(t, expected, actual, delta, msgAndArgs...) {1456 return1457 }1458 t.FailNow()1459}1460// WithinDurationf asserts that the two times are within duration delta of each other.1461//1462// assert.WithinDurationf(t, time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted")1463func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) {1464 if h, ok := t.(tHelper); ok {1465 h.Helper()1466 }1467 if assert.WithinDurationf(t, expected, actual, delta, msg, args...) {1468 return1469 }1470 t.FailNow()1471}1472// YAMLEq asserts that two YAML strings are equivalent.1473func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) {1474 if h, ok := t.(tHelper); ok {1475 h.Helper()1476 }1477 if assert.YAMLEq(t, expected, actual, msgAndArgs...) {1478 return1479 }1480 t.FailNow()1481}1482// YAMLEqf asserts that two YAML strings are equivalent.1483func YAMLEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) {1484 if h, ok := t.(tHelper); ok {1485 h.Helper()1486 }1487 if assert.YAMLEqf(t, expected, actual, msg, args...) {1488 return1489 }1490 t.FailNow()1491}1492// Zero asserts that i is the zero value for its type.1493func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) {1494 if h, ok := t.(tHelper); ok {1495 h.Helper()1496 }1497 if assert.Zero(t, i, msgAndArgs...) {1498 return1499 }1500 t.FailNow()1501}1502// Zerof asserts that i is the zero value for its type.1503func Zerof(t TestingT, i interface{}, msg string, args ...interface{}) {1504 if h, ok := t.(tHelper); ok {1505 h.Helper()1506 }1507 if assert.Zerof(t, i, msg, args...) {1508 return1509 }1510 t.FailNow()1511}...

Full Screen

Full Screen

assertion_forward.go

Source:assertion_forward.go Github

copy

Full Screen

...9 time "time"10)11// Condition uses a Comparison to assert a complex condition.12func (a *Assertions) Condition(comp Comparison, msgAndArgs ...interface{}) bool {13 if h, ok := a.t.(tHelper); ok {14 h.Helper()15 }16 return Condition(a.t, comp, msgAndArgs...)17}18// Conditionf uses a Comparison to assert a complex condition.19func (a *Assertions) Conditionf(comp Comparison, msg string, args ...interface{}) bool {20 if h, ok := a.t.(tHelper); ok {21 h.Helper()22 }23 return Conditionf(a.t, comp, msg, args...)24}25// Contains asserts that the specified string, list(array, slice...) or map contains the26// specified substring or element.27//28// a.Contains("Hello World", "World")29// a.Contains(["Hello", "World"], "World")30// a.Contains({"Hello": "World"}, "Hello")31func (a *Assertions) Contains(s interface{}, contains interface{}, msgAndArgs ...interface{}) bool {32 if h, ok := a.t.(tHelper); ok {33 h.Helper()34 }35 return Contains(a.t, s, contains, msgAndArgs...)36}37// Containsf asserts that the specified string, list(array, slice...) or map contains the38// specified substring or element.39//40// a.Containsf("Hello World", "World", "error message %s", "formatted")41// a.Containsf(["Hello", "World"], "World", "error message %s", "formatted")42// a.Containsf({"Hello": "World"}, "Hello", "error message %s", "formatted")43func (a *Assertions) Containsf(s interface{}, contains interface{}, msg string, args ...interface{}) bool {44 if h, ok := a.t.(tHelper); ok {45 h.Helper()46 }47 return Containsf(a.t, s, contains, msg, args...)48}49// DirExists checks whether a directory exists in the given path. It also fails50// if the path is a file rather a directory or there is an error checking whether it exists.51func (a *Assertions) DirExists(path string, msgAndArgs ...interface{}) bool {52 if h, ok := a.t.(tHelper); ok {53 h.Helper()54 }55 return DirExists(a.t, path, msgAndArgs...)56}57// DirExistsf checks whether a directory exists in the given path. It also fails58// if the path is a file rather a directory or there is an error checking whether it exists.59func (a *Assertions) DirExistsf(path string, msg string, args ...interface{}) bool {60 if h, ok := a.t.(tHelper); ok {61 h.Helper()62 }63 return DirExistsf(a.t, path, msg, args...)64}65// ElementsMatch asserts that the specified listA(array, slice...) is equal to specified66// listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,67// the number of appearances of each of them in both lists should match.68//69// a.ElementsMatch([1, 3, 2, 3], [1, 3, 3, 2])70func (a *Assertions) ElementsMatch(listA interface{}, listB interface{}, msgAndArgs ...interface{}) bool {71 if h, ok := a.t.(tHelper); ok {72 h.Helper()73 }74 return ElementsMatch(a.t, listA, listB, msgAndArgs...)75}76// ElementsMatchf asserts that the specified listA(array, slice...) is equal to specified77// listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,78// the number of appearances of each of them in both lists should match.79//80// a.ElementsMatchf([1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted")81func (a *Assertions) ElementsMatchf(listA interface{}, listB interface{}, msg string, args ...interface{}) bool {82 if h, ok := a.t.(tHelper); ok {83 h.Helper()84 }85 return ElementsMatchf(a.t, listA, listB, msg, args...)86}87// Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either88// a slice or a channel with len == 0.89//90// a.Empty(obj)91func (a *Assertions) Empty(object interface{}, msgAndArgs ...interface{}) bool {92 if h, ok := a.t.(tHelper); ok {93 h.Helper()94 }95 return Empty(a.t, object, msgAndArgs...)96}97// Emptyf asserts that the specified object is empty. I.e. nil, "", false, 0 or either98// a slice or a channel with len == 0.99//100// a.Emptyf(obj, "error message %s", "formatted")101func (a *Assertions) Emptyf(object interface{}, msg string, args ...interface{}) bool {102 if h, ok := a.t.(tHelper); ok {103 h.Helper()104 }105 return Emptyf(a.t, object, msg, args...)106}107// Equal asserts that two objects are equal.108//109// a.Equal(123, 123)110//111// Pointer variable equality is determined based on the equality of the112// referenced values (as opposed to the memory addresses). Function equality113// cannot be determined and will always fail.114func (a *Assertions) Equal(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {115 if h, ok := a.t.(tHelper); ok {116 h.Helper()117 }118 return Equal(a.t, expected, actual, msgAndArgs...)119}120// EqualError asserts that a function returned an error (i.e. not `nil`)121// and that it is equal to the provided error.122//123// actualObj, err := SomeFunction()124// a.EqualError(err, expectedErrorString)125func (a *Assertions) EqualError(theError error, errString string, msgAndArgs ...interface{}) bool {126 if h, ok := a.t.(tHelper); ok {127 h.Helper()128 }129 return EqualError(a.t, theError, errString, msgAndArgs...)130}131// EqualErrorf asserts that a function returned an error (i.e. not `nil`)132// and that it is equal to the provided error.133//134// actualObj, err := SomeFunction()135// a.EqualErrorf(err, expectedErrorString, "error message %s", "formatted")136func (a *Assertions) EqualErrorf(theError error, errString string, msg string, args ...interface{}) bool {137 if h, ok := a.t.(tHelper); ok {138 h.Helper()139 }140 return EqualErrorf(a.t, theError, errString, msg, args...)141}142// EqualValues asserts that two objects are equal or convertable to the same types143// and equal.144//145// a.EqualValues(uint32(123), int32(123))146func (a *Assertions) EqualValues(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {147 if h, ok := a.t.(tHelper); ok {148 h.Helper()149 }150 return EqualValues(a.t, expected, actual, msgAndArgs...)151}152// EqualValuesf asserts that two objects are equal or convertable to the same types153// and equal.154//155// a.EqualValuesf(uint32(123), int32(123), "error message %s", "formatted")156func (a *Assertions) EqualValuesf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool {157 if h, ok := a.t.(tHelper); ok {158 h.Helper()159 }160 return EqualValuesf(a.t, expected, actual, msg, args...)161}162// Equalf asserts that two objects are equal.163//164// a.Equalf(123, 123, "error message %s", "formatted")165//166// Pointer variable equality is determined based on the equality of the167// referenced values (as opposed to the memory addresses). Function equality168// cannot be determined and will always fail.169func (a *Assertions) Equalf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool {170 if h, ok := a.t.(tHelper); ok {171 h.Helper()172 }173 return Equalf(a.t, expected, actual, msg, args...)174}175// Error asserts that a function returned an error (i.e. not `nil`).176//177// actualObj, err := SomeFunction()178// if a.Error(err) {179// assert.Equal(t, expectedError, err)180// }181func (a *Assertions) Error(err error, msgAndArgs ...interface{}) bool {182 if h, ok := a.t.(tHelper); ok {183 h.Helper()184 }185 return Error(a.t, err, msgAndArgs...)186}187// Errorf asserts that a function returned an error (i.e. not `nil`).188//189// actualObj, err := SomeFunction()190// if a.Errorf(err, "error message %s", "formatted") {191// assert.Equal(t, expectedErrorf, err)192// }193func (a *Assertions) Errorf(err error, msg string, args ...interface{}) bool {194 if h, ok := a.t.(tHelper); ok {195 h.Helper()196 }197 return Errorf(a.t, err, msg, args...)198}199// Eventually asserts that given condition will be met in waitFor time,200// periodically checking target function each tick.201//202// a.Eventually(func() bool { return true; }, time.Second, 10*time.Millisecond)203func (a *Assertions) Eventually(condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) bool {204 if h, ok := a.t.(tHelper); ok {205 h.Helper()206 }207 return Eventually(a.t, condition, waitFor, tick, msgAndArgs...)208}209// Eventuallyf asserts that given condition will be met in waitFor time,210// periodically checking target function each tick.211//212// a.Eventuallyf(func() bool { return true; }, time.Second, 10*time.Millisecond, "error message %s", "formatted")213func (a *Assertions) Eventuallyf(condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) bool {214 if h, ok := a.t.(tHelper); ok {215 h.Helper()216 }217 return Eventuallyf(a.t, condition, waitFor, tick, msg, args...)218}219// Exactly asserts that two objects are equal in value and type.220//221// a.Exactly(int32(123), int64(123))222func (a *Assertions) Exactly(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {223 if h, ok := a.t.(tHelper); ok {224 h.Helper()225 }226 return Exactly(a.t, expected, actual, msgAndArgs...)227}228// Exactlyf asserts that two objects are equal in value and type.229//230// a.Exactlyf(int32(123), int64(123), "error message %s", "formatted")231func (a *Assertions) Exactlyf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool {232 if h, ok := a.t.(tHelper); ok {233 h.Helper()234 }235 return Exactlyf(a.t, expected, actual, msg, args...)236}237// Fail reports a failure through238func (a *Assertions) Fail(failureMessage string, msgAndArgs ...interface{}) bool {239 if h, ok := a.t.(tHelper); ok {240 h.Helper()241 }242 return Fail(a.t, failureMessage, msgAndArgs...)243}244// FailNow fails test245func (a *Assertions) FailNow(failureMessage string, msgAndArgs ...interface{}) bool {246 if h, ok := a.t.(tHelper); ok {247 h.Helper()248 }249 return FailNow(a.t, failureMessage, msgAndArgs...)250}251// FailNowf fails test252func (a *Assertions) FailNowf(failureMessage string, msg string, args ...interface{}) bool {253 if h, ok := a.t.(tHelper); ok {254 h.Helper()255 }256 return FailNowf(a.t, failureMessage, msg, args...)257}258// Failf reports a failure through259func (a *Assertions) Failf(failureMessage string, msg string, args ...interface{}) bool {260 if h, ok := a.t.(tHelper); ok {261 h.Helper()262 }263 return Failf(a.t, failureMessage, msg, args...)264}265// False asserts that the specified value is false.266//267// a.False(myBool)268func (a *Assertions) False(value bool, msgAndArgs ...interface{}) bool {269 if h, ok := a.t.(tHelper); ok {270 h.Helper()271 }272 return False(a.t, value, msgAndArgs...)273}274// Falsef asserts that the specified value is false.275//276// a.Falsef(myBool, "error message %s", "formatted")277func (a *Assertions) Falsef(value bool, msg string, args ...interface{}) bool {278 if h, ok := a.t.(tHelper); ok {279 h.Helper()280 }281 return Falsef(a.t, value, msg, args...)282}283// FileExists checks whether a file exists in the given path. It also fails if284// the path points to a directory or there is an error when trying to check the file.285func (a *Assertions) FileExists(path string, msgAndArgs ...interface{}) bool {286 if h, ok := a.t.(tHelper); ok {287 h.Helper()288 }289 return FileExists(a.t, path, msgAndArgs...)290}291// FileExistsf checks whether a file exists in the given path. It also fails if292// the path points to a directory or there is an error when trying to check the file.293func (a *Assertions) FileExistsf(path string, msg string, args ...interface{}) bool {294 if h, ok := a.t.(tHelper); ok {295 h.Helper()296 }297 return FileExistsf(a.t, path, msg, args...)298}299// Greater asserts that the first element is greater than the second300//301// a.Greater(2, 1)302// a.Greater(float64(2), float64(1))303// a.Greater("b", "a")304func (a *Assertions) Greater(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool {305 if h, ok := a.t.(tHelper); ok {306 h.Helper()307 }308 return Greater(a.t, e1, e2, msgAndArgs...)309}310// GreaterOrEqual asserts that the first element is greater than or equal to the second311//312// a.GreaterOrEqual(2, 1)313// a.GreaterOrEqual(2, 2)314// a.GreaterOrEqual("b", "a")315// a.GreaterOrEqual("b", "b")316func (a *Assertions) GreaterOrEqual(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool {317 if h, ok := a.t.(tHelper); ok {318 h.Helper()319 }320 return GreaterOrEqual(a.t, e1, e2, msgAndArgs...)321}322// GreaterOrEqualf asserts that the first element is greater than or equal to the second323//324// a.GreaterOrEqualf(2, 1, "error message %s", "formatted")325// a.GreaterOrEqualf(2, 2, "error message %s", "formatted")326// a.GreaterOrEqualf("b", "a", "error message %s", "formatted")327// a.GreaterOrEqualf("b", "b", "error message %s", "formatted")328func (a *Assertions) GreaterOrEqualf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool {329 if h, ok := a.t.(tHelper); ok {330 h.Helper()331 }332 return GreaterOrEqualf(a.t, e1, e2, msg, args...)333}334// Greaterf asserts that the first element is greater than the second335//336// a.Greaterf(2, 1, "error message %s", "formatted")337// a.Greaterf(float64(2), float64(1), "error message %s", "formatted")338// a.Greaterf("b", "a", "error message %s", "formatted")339func (a *Assertions) Greaterf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool {340 if h, ok := a.t.(tHelper); ok {341 h.Helper()342 }343 return Greaterf(a.t, e1, e2, msg, args...)344}345// HTTPBodyContains asserts that a specified handler returns a346// body that contains a string.347//348// a.HTTPBodyContains(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")349//350// Returns whether the assertion was successful (true) or not (false).351func (a *Assertions) HTTPBodyContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) bool {352 if h, ok := a.t.(tHelper); ok {353 h.Helper()354 }355 return HTTPBodyContains(a.t, handler, method, url, values, str, msgAndArgs...)356}357// HTTPBodyContainsf asserts that a specified handler returns a358// body that contains a string.359//360// a.HTTPBodyContainsf(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")361//362// Returns whether the assertion was successful (true) or not (false).363func (a *Assertions) HTTPBodyContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) bool {364 if h, ok := a.t.(tHelper); ok {365 h.Helper()366 }367 return HTTPBodyContainsf(a.t, handler, method, url, values, str, msg, args...)368}369// HTTPBodyNotContains asserts that a specified handler returns a370// body that does not contain a string.371//372// a.HTTPBodyNotContains(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")373//374// Returns whether the assertion was successful (true) or not (false).375func (a *Assertions) HTTPBodyNotContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) bool {376 if h, ok := a.t.(tHelper); ok {377 h.Helper()378 }379 return HTTPBodyNotContains(a.t, handler, method, url, values, str, msgAndArgs...)380}381// HTTPBodyNotContainsf asserts that a specified handler returns a382// body that does not contain a string.383//384// a.HTTPBodyNotContainsf(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")385//386// Returns whether the assertion was successful (true) or not (false).387func (a *Assertions) HTTPBodyNotContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) bool {388 if h, ok := a.t.(tHelper); ok {389 h.Helper()390 }391 return HTTPBodyNotContainsf(a.t, handler, method, url, values, str, msg, args...)392}393// HTTPError asserts that a specified handler returns an error status code.394//395// a.HTTPError(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}396//397// Returns whether the assertion was successful (true) or not (false).398func (a *Assertions) HTTPError(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) bool {399 if h, ok := a.t.(tHelper); ok {400 h.Helper()401 }402 return HTTPError(a.t, handler, method, url, values, msgAndArgs...)403}404// HTTPErrorf asserts that a specified handler returns an error status code.405//406// a.HTTPErrorf(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}407//408// Returns whether the assertion was successful (true) or not (false).409func (a *Assertions) HTTPErrorf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool {410 if h, ok := a.t.(tHelper); ok {411 h.Helper()412 }413 return HTTPErrorf(a.t, handler, method, url, values, msg, args...)414}415// HTTPRedirect asserts that a specified handler returns a redirect status code.416//417// a.HTTPRedirect(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}418//419// Returns whether the assertion was successful (true) or not (false).420func (a *Assertions) HTTPRedirect(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) bool {421 if h, ok := a.t.(tHelper); ok {422 h.Helper()423 }424 return HTTPRedirect(a.t, handler, method, url, values, msgAndArgs...)425}426// HTTPRedirectf asserts that a specified handler returns a redirect status code.427//428// a.HTTPRedirectf(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}429//430// Returns whether the assertion was successful (true) or not (false).431func (a *Assertions) HTTPRedirectf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool {432 if h, ok := a.t.(tHelper); ok {433 h.Helper()434 }435 return HTTPRedirectf(a.t, handler, method, url, values, msg, args...)436}437// HTTPStatusCode asserts that a specified handler returns a specified status code.438//439// a.HTTPStatusCode(myHandler, "GET", "/notImplemented", nil, 501)440//441// Returns whether the assertion was successful (true) or not (false).442func (a *Assertions) HTTPStatusCode(handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msgAndArgs ...interface{}) bool {443 if h, ok := a.t.(tHelper); ok {444 h.Helper()445 }446 return HTTPStatusCode(a.t, handler, method, url, values, statuscode, msgAndArgs...)447}448// HTTPStatusCodef asserts that a specified handler returns a specified status code.449//450// a.HTTPStatusCodef(myHandler, "GET", "/notImplemented", nil, 501, "error message %s", "formatted")451//452// Returns whether the assertion was successful (true) or not (false).453func (a *Assertions) HTTPStatusCodef(handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msg string, args ...interface{}) bool {454 if h, ok := a.t.(tHelper); ok {455 h.Helper()456 }457 return HTTPStatusCodef(a.t, handler, method, url, values, statuscode, msg, args...)458}459// HTTPSuccess asserts that a specified handler returns a success status code.460//461// a.HTTPSuccess(myHandler, "POST", "http://www.google.com", nil)462//463// Returns whether the assertion was successful (true) or not (false).464func (a *Assertions) HTTPSuccess(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) bool {465 if h, ok := a.t.(tHelper); ok {466 h.Helper()467 }468 return HTTPSuccess(a.t, handler, method, url, values, msgAndArgs...)469}470// HTTPSuccessf asserts that a specified handler returns a success status code.471//472// a.HTTPSuccessf(myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted")473//474// Returns whether the assertion was successful (true) or not (false).475func (a *Assertions) HTTPSuccessf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool {476 if h, ok := a.t.(tHelper); ok {477 h.Helper()478 }479 return HTTPSuccessf(a.t, handler, method, url, values, msg, args...)480}481// Implements asserts that an object is implemented by the specified interface.482//483// a.Implements((*MyInterface)(nil), new(MyObject))484func (a *Assertions) Implements(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) bool {485 if h, ok := a.t.(tHelper); ok {486 h.Helper()487 }488 return Implements(a.t, interfaceObject, object, msgAndArgs...)489}490// Implementsf asserts that an object is implemented by the specified interface.491//492// a.Implementsf((*MyInterface)(nil), new(MyObject), "error message %s", "formatted")493func (a *Assertions) Implementsf(interfaceObject interface{}, object interface{}, msg string, args ...interface{}) bool {494 if h, ok := a.t.(tHelper); ok {495 h.Helper()496 }497 return Implementsf(a.t, interfaceObject, object, msg, args...)498}499// InDelta asserts that the two numerals are within delta of each other.500//501// a.InDelta(math.Pi, 22/7.0, 0.01)502func (a *Assertions) InDelta(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {503 if h, ok := a.t.(tHelper); ok {504 h.Helper()505 }506 return InDelta(a.t, expected, actual, delta, msgAndArgs...)507}508// InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.509func (a *Assertions) InDeltaMapValues(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {510 if h, ok := a.t.(tHelper); ok {511 h.Helper()512 }513 return InDeltaMapValues(a.t, expected, actual, delta, msgAndArgs...)514}515// InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.516func (a *Assertions) InDeltaMapValuesf(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool {517 if h, ok := a.t.(tHelper); ok {518 h.Helper()519 }520 return InDeltaMapValuesf(a.t, expected, actual, delta, msg, args...)521}522// InDeltaSlice is the same as InDelta, except it compares two slices.523func (a *Assertions) InDeltaSlice(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {524 if h, ok := a.t.(tHelper); ok {525 h.Helper()526 }527 return InDeltaSlice(a.t, expected, actual, delta, msgAndArgs...)528}529// InDeltaSlicef is the same as InDelta, except it compares two slices.530func (a *Assertions) InDeltaSlicef(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool {531 if h, ok := a.t.(tHelper); ok {532 h.Helper()533 }534 return InDeltaSlicef(a.t, expected, actual, delta, msg, args...)535}536// InDeltaf asserts that the two numerals are within delta of each other.537//538// a.InDeltaf(math.Pi, 22/7.0, 0.01, "error message %s", "formatted")539func (a *Assertions) InDeltaf(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool {540 if h, ok := a.t.(tHelper); ok {541 h.Helper()542 }543 return InDeltaf(a.t, expected, actual, delta, msg, args...)544}545// InEpsilon asserts that expected and actual have a relative error less than epsilon546func (a *Assertions) InEpsilon(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool {547 if h, ok := a.t.(tHelper); ok {548 h.Helper()549 }550 return InEpsilon(a.t, expected, actual, epsilon, msgAndArgs...)551}552// InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices.553func (a *Assertions) InEpsilonSlice(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool {554 if h, ok := a.t.(tHelper); ok {555 h.Helper()556 }557 return InEpsilonSlice(a.t, expected, actual, epsilon, msgAndArgs...)558}559// InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices.560func (a *Assertions) InEpsilonSlicef(expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) bool {561 if h, ok := a.t.(tHelper); ok {562 h.Helper()563 }564 return InEpsilonSlicef(a.t, expected, actual, epsilon, msg, args...)565}566// InEpsilonf asserts that expected and actual have a relative error less than epsilon567func (a *Assertions) InEpsilonf(expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) bool {568 if h, ok := a.t.(tHelper); ok {569 h.Helper()570 }571 return InEpsilonf(a.t, expected, actual, epsilon, msg, args...)572}573// IsType asserts that the specified objects are of the same type.574func (a *Assertions) IsType(expectedType interface{}, object interface{}, msgAndArgs ...interface{}) bool {575 if h, ok := a.t.(tHelper); ok {576 h.Helper()577 }578 return IsType(a.t, expectedType, object, msgAndArgs...)579}580// IsTypef asserts that the specified objects are of the same type.581func (a *Assertions) IsTypef(expectedType interface{}, object interface{}, msg string, args ...interface{}) bool {582 if h, ok := a.t.(tHelper); ok {583 h.Helper()584 }585 return IsTypef(a.t, expectedType, object, msg, args...)586}587// JSONEq asserts that two JSON strings are equivalent.588//589// a.JSONEq(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)590func (a *Assertions) JSONEq(expected string, actual string, msgAndArgs ...interface{}) bool {591 if h, ok := a.t.(tHelper); ok {592 h.Helper()593 }594 return JSONEq(a.t, expected, actual, msgAndArgs...)595}596// JSONEqf asserts that two JSON strings are equivalent.597//598// a.JSONEqf(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted")599func (a *Assertions) JSONEqf(expected string, actual string, msg string, args ...interface{}) bool {600 if h, ok := a.t.(tHelper); ok {601 h.Helper()602 }603 return JSONEqf(a.t, expected, actual, msg, args...)604}605// Len asserts that the specified object has specific length.606// Len also fails if the object has a type that len() not accept.607//608// a.Len(mySlice, 3)609func (a *Assertions) Len(object interface{}, length int, msgAndArgs ...interface{}) bool {610 if h, ok := a.t.(tHelper); ok {611 h.Helper()612 }613 return Len(a.t, object, length, msgAndArgs...)614}615// Lenf asserts that the specified object has specific length.616// Lenf also fails if the object has a type that len() not accept.617//618// a.Lenf(mySlice, 3, "error message %s", "formatted")619func (a *Assertions) Lenf(object interface{}, length int, msg string, args ...interface{}) bool {620 if h, ok := a.t.(tHelper); ok {621 h.Helper()622 }623 return Lenf(a.t, object, length, msg, args...)624}625// Less asserts that the first element is less than the second626//627// a.Less(1, 2)628// a.Less(float64(1), float64(2))629// a.Less("a", "b")630func (a *Assertions) Less(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool {631 if h, ok := a.t.(tHelper); ok {632 h.Helper()633 }634 return Less(a.t, e1, e2, msgAndArgs...)635}636// LessOrEqual asserts that the first element is less than or equal to the second637//638// a.LessOrEqual(1, 2)639// a.LessOrEqual(2, 2)640// a.LessOrEqual("a", "b")641// a.LessOrEqual("b", "b")642func (a *Assertions) LessOrEqual(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool {643 if h, ok := a.t.(tHelper); ok {644 h.Helper()645 }646 return LessOrEqual(a.t, e1, e2, msgAndArgs...)647}648// LessOrEqualf asserts that the first element is less than or equal to the second649//650// a.LessOrEqualf(1, 2, "error message %s", "formatted")651// a.LessOrEqualf(2, 2, "error message %s", "formatted")652// a.LessOrEqualf("a", "b", "error message %s", "formatted")653// a.LessOrEqualf("b", "b", "error message %s", "formatted")654func (a *Assertions) LessOrEqualf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool {655 if h, ok := a.t.(tHelper); ok {656 h.Helper()657 }658 return LessOrEqualf(a.t, e1, e2, msg, args...)659}660// Lessf asserts that the first element is less than the second661//662// a.Lessf(1, 2, "error message %s", "formatted")663// a.Lessf(float64(1), float64(2), "error message %s", "formatted")664// a.Lessf("a", "b", "error message %s", "formatted")665func (a *Assertions) Lessf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool {666 if h, ok := a.t.(tHelper); ok {667 h.Helper()668 }669 return Lessf(a.t, e1, e2, msg, args...)670}671// Never asserts that the given condition doesn't satisfy in waitFor time,672// periodically checking the target function each tick.673//674// a.Never(func() bool { return false; }, time.Second, 10*time.Millisecond)675func (a *Assertions) Never(condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) bool {676 if h, ok := a.t.(tHelper); ok {677 h.Helper()678 }679 return Never(a.t, condition, waitFor, tick, msgAndArgs...)680}681// Neverf asserts that the given condition doesn't satisfy in waitFor time,682// periodically checking the target function each tick.683//684// a.Neverf(func() bool { return false; }, time.Second, 10*time.Millisecond, "error message %s", "formatted")685func (a *Assertions) Neverf(condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) bool {686 if h, ok := a.t.(tHelper); ok {687 h.Helper()688 }689 return Neverf(a.t, condition, waitFor, tick, msg, args...)690}691// Nil asserts that the specified object is nil.692//693// a.Nil(err)694func (a *Assertions) Nil(object interface{}, msgAndArgs ...interface{}) bool {695 if h, ok := a.t.(tHelper); ok {696 h.Helper()697 }698 return Nil(a.t, object, msgAndArgs...)699}700// Nilf asserts that the specified object is nil.701//702// a.Nilf(err, "error message %s", "formatted")703func (a *Assertions) Nilf(object interface{}, msg string, args ...interface{}) bool {704 if h, ok := a.t.(tHelper); ok {705 h.Helper()706 }707 return Nilf(a.t, object, msg, args...)708}709// NoDirExists checks whether a directory does not exist in the given path.710// It fails if the path points to an existing _directory_ only.711func (a *Assertions) NoDirExists(path string, msgAndArgs ...interface{}) bool {712 if h, ok := a.t.(tHelper); ok {713 h.Helper()714 }715 return NoDirExists(a.t, path, msgAndArgs...)716}717// NoDirExistsf checks whether a directory does not exist in the given path.718// It fails if the path points to an existing _directory_ only.719func (a *Assertions) NoDirExistsf(path string, msg string, args ...interface{}) bool {720 if h, ok := a.t.(tHelper); ok {721 h.Helper()722 }723 return NoDirExistsf(a.t, path, msg, args...)724}725// NoError asserts that a function returned no error (i.e. `nil`).726//727// actualObj, err := SomeFunction()728// if a.NoError(err) {729// assert.Equal(t, expectedObj, actualObj)730// }731func (a *Assertions) NoError(err error, msgAndArgs ...interface{}) bool {732 if h, ok := a.t.(tHelper); ok {733 h.Helper()734 }735 return NoError(a.t, err, msgAndArgs...)736}737// NoErrorf asserts that a function returned no error (i.e. `nil`).738//739// actualObj, err := SomeFunction()740// if a.NoErrorf(err, "error message %s", "formatted") {741// assert.Equal(t, expectedObj, actualObj)742// }743func (a *Assertions) NoErrorf(err error, msg string, args ...interface{}) bool {744 if h, ok := a.t.(tHelper); ok {745 h.Helper()746 }747 return NoErrorf(a.t, err, msg, args...)748}749// NoFileExists checks whether a file does not exist in a given path. It fails750// if the path points to an existing _file_ only.751func (a *Assertions) NoFileExists(path string, msgAndArgs ...interface{}) bool {752 if h, ok := a.t.(tHelper); ok {753 h.Helper()754 }755 return NoFileExists(a.t, path, msgAndArgs...)756}757// NoFileExistsf checks whether a file does not exist in a given path. It fails758// if the path points to an existing _file_ only.759func (a *Assertions) NoFileExistsf(path string, msg string, args ...interface{}) bool {760 if h, ok := a.t.(tHelper); ok {761 h.Helper()762 }763 return NoFileExistsf(a.t, path, msg, args...)764}765// NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the766// specified substring or element.767//768// a.NotContains("Hello World", "Earth")769// a.NotContains(["Hello", "World"], "Earth")770// a.NotContains({"Hello": "World"}, "Earth")771func (a *Assertions) NotContains(s interface{}, contains interface{}, msgAndArgs ...interface{}) bool {772 if h, ok := a.t.(tHelper); ok {773 h.Helper()774 }775 return NotContains(a.t, s, contains, msgAndArgs...)776}777// NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the778// specified substring or element.779//780// a.NotContainsf("Hello World", "Earth", "error message %s", "formatted")781// a.NotContainsf(["Hello", "World"], "Earth", "error message %s", "formatted")782// a.NotContainsf({"Hello": "World"}, "Earth", "error message %s", "formatted")783func (a *Assertions) NotContainsf(s interface{}, contains interface{}, msg string, args ...interface{}) bool {784 if h, ok := a.t.(tHelper); ok {785 h.Helper()786 }787 return NotContainsf(a.t, s, contains, msg, args...)788}789// NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either790// a slice or a channel with len == 0.791//792// if a.NotEmpty(obj) {793// assert.Equal(t, "two", obj[1])794// }795func (a *Assertions) NotEmpty(object interface{}, msgAndArgs ...interface{}) bool {796 if h, ok := a.t.(tHelper); ok {797 h.Helper()798 }799 return NotEmpty(a.t, object, msgAndArgs...)800}801// NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either802// a slice or a channel with len == 0.803//804// if a.NotEmptyf(obj, "error message %s", "formatted") {805// assert.Equal(t, "two", obj[1])806// }807func (a *Assertions) NotEmptyf(object interface{}, msg string, args ...interface{}) bool {808 if h, ok := a.t.(tHelper); ok {809 h.Helper()810 }811 return NotEmptyf(a.t, object, msg, args...)812}813// NotEqual asserts that the specified values are NOT equal.814//815// a.NotEqual(obj1, obj2)816//817// Pointer variable equality is determined based on the equality of the818// referenced values (as opposed to the memory addresses).819func (a *Assertions) NotEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {820 if h, ok := a.t.(tHelper); ok {821 h.Helper()822 }823 return NotEqual(a.t, expected, actual, msgAndArgs...)824}825// NotEqualValues asserts that two objects are not equal even when converted to the same type826//827// a.NotEqualValues(obj1, obj2)828func (a *Assertions) NotEqualValues(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {829 if h, ok := a.t.(tHelper); ok {830 h.Helper()831 }832 return NotEqualValues(a.t, expected, actual, msgAndArgs...)833}834// NotEqualValuesf asserts that two objects are not equal even when converted to the same type835//836// a.NotEqualValuesf(obj1, obj2, "error message %s", "formatted")837func (a *Assertions) NotEqualValuesf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool {838 if h, ok := a.t.(tHelper); ok {839 h.Helper()840 }841 return NotEqualValuesf(a.t, expected, actual, msg, args...)842}843// NotEqualf asserts that the specified values are NOT equal.844//845// a.NotEqualf(obj1, obj2, "error message %s", "formatted")846//847// Pointer variable equality is determined based on the equality of the848// referenced values (as opposed to the memory addresses).849func (a *Assertions) NotEqualf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool {850 if h, ok := a.t.(tHelper); ok {851 h.Helper()852 }853 return NotEqualf(a.t, expected, actual, msg, args...)854}855// NotNil asserts that the specified object is not nil.856//857// a.NotNil(err)858func (a *Assertions) NotNil(object interface{}, msgAndArgs ...interface{}) bool {859 if h, ok := a.t.(tHelper); ok {860 h.Helper()861 }862 return NotNil(a.t, object, msgAndArgs...)863}864// NotNilf asserts that the specified object is not nil.865//866// a.NotNilf(err, "error message %s", "formatted")867func (a *Assertions) NotNilf(object interface{}, msg string, args ...interface{}) bool {868 if h, ok := a.t.(tHelper); ok {869 h.Helper()870 }871 return NotNilf(a.t, object, msg, args...)872}873// NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.874//875// a.NotPanics(func(){ RemainCalm() })876func (a *Assertions) NotPanics(f PanicTestFunc, msgAndArgs ...interface{}) bool {877 if h, ok := a.t.(tHelper); ok {878 h.Helper()879 }880 return NotPanics(a.t, f, msgAndArgs...)881}882// NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic.883//884// a.NotPanicsf(func(){ RemainCalm() }, "error message %s", "formatted")885func (a *Assertions) NotPanicsf(f PanicTestFunc, msg string, args ...interface{}) bool {886 if h, ok := a.t.(tHelper); ok {887 h.Helper()888 }889 return NotPanicsf(a.t, f, msg, args...)890}891// NotRegexp asserts that a specified regexp does not match a string.892//893// a.NotRegexp(regexp.MustCompile("starts"), "it's starting")894// a.NotRegexp("^start", "it's not starting")895func (a *Assertions) NotRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool {896 if h, ok := a.t.(tHelper); ok {897 h.Helper()898 }899 return NotRegexp(a.t, rx, str, msgAndArgs...)900}901// NotRegexpf asserts that a specified regexp does not match a string.902//903// a.NotRegexpf(regexp.MustCompile("starts"), "it's starting", "error message %s", "formatted")904// a.NotRegexpf("^start", "it's not starting", "error message %s", "formatted")905func (a *Assertions) NotRegexpf(rx interface{}, str interface{}, msg string, args ...interface{}) bool {906 if h, ok := a.t.(tHelper); ok {907 h.Helper()908 }909 return NotRegexpf(a.t, rx, str, msg, args...)910}911// NotSame asserts that two pointers do not reference the same object.912//913// a.NotSame(ptr1, ptr2)914//915// Both arguments must be pointer variables. Pointer variable sameness is916// determined based on the equality of both type and value.917func (a *Assertions) NotSame(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {918 if h, ok := a.t.(tHelper); ok {919 h.Helper()920 }921 return NotSame(a.t, expected, actual, msgAndArgs...)922}923// NotSamef asserts that two pointers do not reference the same object.924//925// a.NotSamef(ptr1, ptr2, "error message %s", "formatted")926//927// Both arguments must be pointer variables. Pointer variable sameness is928// determined based on the equality of both type and value.929func (a *Assertions) NotSamef(expected interface{}, actual interface{}, msg string, args ...interface{}) bool {930 if h, ok := a.t.(tHelper); ok {931 h.Helper()932 }933 return NotSamef(a.t, expected, actual, msg, args...)934}935// NotSubset asserts that the specified list(array, slice...) contains not all936// elements given in the specified subset(array, slice...).937//938// a.NotSubset([1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]")939func (a *Assertions) NotSubset(list interface{}, subset interface{}, msgAndArgs ...interface{}) bool {940 if h, ok := a.t.(tHelper); ok {941 h.Helper()942 }943 return NotSubset(a.t, list, subset, msgAndArgs...)944}945// NotSubsetf asserts that the specified list(array, slice...) contains not all946// elements given in the specified subset(array, slice...).947//948// a.NotSubsetf([1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]", "error message %s", "formatted")949func (a *Assertions) NotSubsetf(list interface{}, subset interface{}, msg string, args ...interface{}) bool {950 if h, ok := a.t.(tHelper); ok {951 h.Helper()952 }953 return NotSubsetf(a.t, list, subset, msg, args...)954}955// NotZero asserts that i is not the zero value for its type.956func (a *Assertions) NotZero(i interface{}, msgAndArgs ...interface{}) bool {957 if h, ok := a.t.(tHelper); ok {958 h.Helper()959 }960 return NotZero(a.t, i, msgAndArgs...)961}962// NotZerof asserts that i is not the zero value for its type.963func (a *Assertions) NotZerof(i interface{}, msg string, args ...interface{}) bool {964 if h, ok := a.t.(tHelper); ok {965 h.Helper()966 }967 return NotZerof(a.t, i, msg, args...)968}969// Panics asserts that the code inside the specified PanicTestFunc panics.970//971// a.Panics(func(){ GoCrazy() })972func (a *Assertions) Panics(f PanicTestFunc, msgAndArgs ...interface{}) bool {973 if h, ok := a.t.(tHelper); ok {974 h.Helper()975 }976 return Panics(a.t, f, msgAndArgs...)977}978// PanicsWithError asserts that the code inside the specified PanicTestFunc979// panics, and that the recovered panic value is an error that satisfies the980// EqualError comparison.981//982// a.PanicsWithError("crazy error", func(){ GoCrazy() })983func (a *Assertions) PanicsWithError(errString string, f PanicTestFunc, msgAndArgs ...interface{}) bool {984 if h, ok := a.t.(tHelper); ok {985 h.Helper()986 }987 return PanicsWithError(a.t, errString, f, msgAndArgs...)988}989// PanicsWithErrorf asserts that the code inside the specified PanicTestFunc990// panics, and that the recovered panic value is an error that satisfies the991// EqualError comparison.992//993// a.PanicsWithErrorf("crazy error", func(){ GoCrazy() }, "error message %s", "formatted")994func (a *Assertions) PanicsWithErrorf(errString string, f PanicTestFunc, msg string, args ...interface{}) bool {995 if h, ok := a.t.(tHelper); ok {996 h.Helper()997 }998 return PanicsWithErrorf(a.t, errString, f, msg, args...)999}1000// PanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that1001// the recovered panic value equals the expected panic value.1002//1003// a.PanicsWithValue("crazy error", func(){ GoCrazy() })1004func (a *Assertions) PanicsWithValue(expected interface{}, f PanicTestFunc, msgAndArgs ...interface{}) bool {1005 if h, ok := a.t.(tHelper); ok {1006 h.Helper()1007 }1008 return PanicsWithValue(a.t, expected, f, msgAndArgs...)1009}1010// PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that1011// the recovered panic value equals the expected panic value.1012//1013// a.PanicsWithValuef("crazy error", func(){ GoCrazy() }, "error message %s", "formatted")1014func (a *Assertions) PanicsWithValuef(expected interface{}, f PanicTestFunc, msg string, args ...interface{}) bool {1015 if h, ok := a.t.(tHelper); ok {1016 h.Helper()1017 }1018 return PanicsWithValuef(a.t, expected, f, msg, args...)1019}1020// Panicsf asserts that the code inside the specified PanicTestFunc panics.1021//1022// a.Panicsf(func(){ GoCrazy() }, "error message %s", "formatted")1023func (a *Assertions) Panicsf(f PanicTestFunc, msg string, args ...interface{}) bool {1024 if h, ok := a.t.(tHelper); ok {1025 h.Helper()1026 }1027 return Panicsf(a.t, f, msg, args...)1028}1029// Regexp asserts that a specified regexp matches a string.1030//1031// a.Regexp(regexp.MustCompile("start"), "it's starting")1032// a.Regexp("start...$", "it's not starting")1033func (a *Assertions) Regexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool {1034 if h, ok := a.t.(tHelper); ok {1035 h.Helper()1036 }1037 return Regexp(a.t, rx, str, msgAndArgs...)1038}1039// Regexpf asserts that a specified regexp matches a string.1040//1041// a.Regexpf(regexp.MustCompile("start"), "it's starting", "error message %s", "formatted")1042// a.Regexpf("start...$", "it's not starting", "error message %s", "formatted")1043func (a *Assertions) Regexpf(rx interface{}, str interface{}, msg string, args ...interface{}) bool {1044 if h, ok := a.t.(tHelper); ok {1045 h.Helper()1046 }1047 return Regexpf(a.t, rx, str, msg, args...)1048}1049// Same asserts that two pointers reference the same object.1050//1051// a.Same(ptr1, ptr2)1052//1053// Both arguments must be pointer variables. Pointer variable sameness is1054// determined based on the equality of both type and value.1055func (a *Assertions) Same(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {1056 if h, ok := a.t.(tHelper); ok {1057 h.Helper()1058 }1059 return Same(a.t, expected, actual, msgAndArgs...)1060}1061// Samef asserts that two pointers reference the same object.1062//1063// a.Samef(ptr1, ptr2, "error message %s", "formatted")1064//1065// Both arguments must be pointer variables. Pointer variable sameness is1066// determined based on the equality of both type and value.1067func (a *Assertions) Samef(expected interface{}, actual interface{}, msg string, args ...interface{}) bool {1068 if h, ok := a.t.(tHelper); ok {1069 h.Helper()1070 }1071 return Samef(a.t, expected, actual, msg, args...)1072}1073// Subset asserts that the specified list(array, slice...) contains all1074// elements given in the specified subset(array, slice...).1075//1076// a.Subset([1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]")1077func (a *Assertions) Subset(list interface{}, subset interface{}, msgAndArgs ...interface{}) bool {1078 if h, ok := a.t.(tHelper); ok {1079 h.Helper()1080 }1081 return Subset(a.t, list, subset, msgAndArgs...)1082}1083// Subsetf asserts that the specified list(array, slice...) contains all1084// elements given in the specified subset(array, slice...).1085//1086// a.Subsetf([1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]", "error message %s", "formatted")1087func (a *Assertions) Subsetf(list interface{}, subset interface{}, msg string, args ...interface{}) bool {1088 if h, ok := a.t.(tHelper); ok {1089 h.Helper()1090 }1091 return Subsetf(a.t, list, subset, msg, args...)1092}1093// True asserts that the specified value is true.1094//1095// a.True(myBool)1096func (a *Assertions) True(value bool, msgAndArgs ...interface{}) bool {1097 if h, ok := a.t.(tHelper); ok {1098 h.Helper()1099 }1100 return True(a.t, value, msgAndArgs...)1101}1102// Truef asserts that the specified value is true.1103//1104// a.Truef(myBool, "error message %s", "formatted")1105func (a *Assertions) Truef(value bool, msg string, args ...interface{}) bool {1106 if h, ok := a.t.(tHelper); ok {1107 h.Helper()1108 }1109 return Truef(a.t, value, msg, args...)1110}1111// WithinDuration asserts that the two times are within duration delta of each other.1112//1113// a.WithinDuration(time.Now(), time.Now(), 10*time.Second)1114func (a *Assertions) WithinDuration(expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) bool {1115 if h, ok := a.t.(tHelper); ok {1116 h.Helper()1117 }1118 return WithinDuration(a.t, expected, actual, delta, msgAndArgs...)1119}1120// WithinDurationf asserts that the two times are within duration delta of each other.1121//1122// a.WithinDurationf(time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted")1123func (a *Assertions) WithinDurationf(expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) bool {1124 if h, ok := a.t.(tHelper); ok {1125 h.Helper()1126 }1127 return WithinDurationf(a.t, expected, actual, delta, msg, args...)1128}1129// YAMLEq asserts that two YAML strings are equivalent.1130func (a *Assertions) YAMLEq(expected string, actual string, msgAndArgs ...interface{}) bool {1131 if h, ok := a.t.(tHelper); ok {1132 h.Helper()1133 }1134 return YAMLEq(a.t, expected, actual, msgAndArgs...)1135}1136// YAMLEqf asserts that two YAML strings are equivalent.1137func (a *Assertions) YAMLEqf(expected string, actual string, msg string, args ...interface{}) bool {1138 if h, ok := a.t.(tHelper); ok {1139 h.Helper()1140 }1141 return YAMLEqf(a.t, expected, actual, msg, args...)1142}1143// Zero asserts that i is the zero value for its type.1144func (a *Assertions) Zero(i interface{}, msgAndArgs ...interface{}) bool {1145 if h, ok := a.t.(tHelper); ok {1146 h.Helper()1147 }1148 return Zero(a.t, i, msgAndArgs...)1149}1150// Zerof asserts that i is the zero value for its type.1151func (a *Assertions) Zerof(i interface{}, msg string, args ...interface{}) bool {1152 if h, ok := a.t.(tHelper); ok {1153 h.Helper()1154 }1155 return Zerof(a.t, i, msg, args...)1156}...

Full Screen

Full Screen

require_forward.go

Source:require_forward.go Github

copy

Full Screen

...10 time "time"11)12// Condition uses a Comparison to assert a complex condition.13func (a *Assertions) Condition(comp assert.Comparison, msgAndArgs ...interface{}) {14 if h, ok := a.t.(tHelper); ok {15 h.Helper()16 }17 Condition(a.t, comp, msgAndArgs...)18}19// Conditionf uses a Comparison to assert a complex condition.20func (a *Assertions) Conditionf(comp assert.Comparison, msg string, args ...interface{}) {21 if h, ok := a.t.(tHelper); ok {22 h.Helper()23 }24 Conditionf(a.t, comp, msg, args...)25}26// Contains asserts that the specified string, list(array, slice...) or map contains the27// specified substring or element.28//29// a.Contains("Hello World", "World")30// a.Contains(["Hello", "World"], "World")31// a.Contains({"Hello": "World"}, "Hello")32func (a *Assertions) Contains(s interface{}, contains interface{}, msgAndArgs ...interface{}) {33 if h, ok := a.t.(tHelper); ok {34 h.Helper()35 }36 Contains(a.t, s, contains, msgAndArgs...)37}38// Containsf asserts that the specified string, list(array, slice...) or map contains the39// specified substring or element.40//41// a.Containsf("Hello World", "World", "error message %s", "formatted")42// a.Containsf(["Hello", "World"], "World", "error message %s", "formatted")43// a.Containsf({"Hello": "World"}, "Hello", "error message %s", "formatted")44func (a *Assertions) Containsf(s interface{}, contains interface{}, msg string, args ...interface{}) {45 if h, ok := a.t.(tHelper); ok {46 h.Helper()47 }48 Containsf(a.t, s, contains, msg, args...)49}50// DirExists checks whether a directory exists in the given path. It also fails51// if the path is a file rather a directory or there is an error checking whether it exists.52func (a *Assertions) DirExists(path string, msgAndArgs ...interface{}) {53 if h, ok := a.t.(tHelper); ok {54 h.Helper()55 }56 DirExists(a.t, path, msgAndArgs...)57}58// DirExistsf checks whether a directory exists in the given path. It also fails59// if the path is a file rather a directory or there is an error checking whether it exists.60func (a *Assertions) DirExistsf(path string, msg string, args ...interface{}) {61 if h, ok := a.t.(tHelper); ok {62 h.Helper()63 }64 DirExistsf(a.t, path, msg, args...)65}66// ElementsMatch asserts that the specified listA(array, slice...) is equal to specified67// listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,68// the number of appearances of each of them in both lists should match.69//70// a.ElementsMatch([1, 3, 2, 3], [1, 3, 3, 2])71func (a *Assertions) ElementsMatch(listA interface{}, listB interface{}, msgAndArgs ...interface{}) {72 if h, ok := a.t.(tHelper); ok {73 h.Helper()74 }75 ElementsMatch(a.t, listA, listB, msgAndArgs...)76}77// ElementsMatchf asserts that the specified listA(array, slice...) is equal to specified78// listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,79// the number of appearances of each of them in both lists should match.80//81// a.ElementsMatchf([1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted")82func (a *Assertions) ElementsMatchf(listA interface{}, listB interface{}, msg string, args ...interface{}) {83 if h, ok := a.t.(tHelper); ok {84 h.Helper()85 }86 ElementsMatchf(a.t, listA, listB, msg, args...)87}88// Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either89// a slice or a channel with len == 0.90//91// a.Empty(obj)92func (a *Assertions) Empty(object interface{}, msgAndArgs ...interface{}) {93 if h, ok := a.t.(tHelper); ok {94 h.Helper()95 }96 Empty(a.t, object, msgAndArgs...)97}98// Emptyf asserts that the specified object is empty. I.e. nil, "", false, 0 or either99// a slice or a channel with len == 0.100//101// a.Emptyf(obj, "error message %s", "formatted")102func (a *Assertions) Emptyf(object interface{}, msg string, args ...interface{}) {103 if h, ok := a.t.(tHelper); ok {104 h.Helper()105 }106 Emptyf(a.t, object, msg, args...)107}108// Equal asserts that two objects are equal.109//110// a.Equal(123, 123)111//112// Pointer variable equality is determined based on the equality of the113// referenced values (as opposed to the memory addresses). Function equality114// cannot be determined and will always fail.115func (a *Assertions) Equal(expected interface{}, actual interface{}, msgAndArgs ...interface{}) {116 if h, ok := a.t.(tHelper); ok {117 h.Helper()118 }119 Equal(a.t, expected, actual, msgAndArgs...)120}121// EqualError asserts that a function returned an error (i.e. not `nil`)122// and that it is equal to the provided error.123//124// actualObj, err := SomeFunction()125// a.EqualError(err, expectedErrorString)126func (a *Assertions) EqualError(theError error, errString string, msgAndArgs ...interface{}) {127 if h, ok := a.t.(tHelper); ok {128 h.Helper()129 }130 EqualError(a.t, theError, errString, msgAndArgs...)131}132// EqualErrorf asserts that a function returned an error (i.e. not `nil`)133// and that it is equal to the provided error.134//135// actualObj, err := SomeFunction()136// a.EqualErrorf(err, expectedErrorString, "error message %s", "formatted")137func (a *Assertions) EqualErrorf(theError error, errString string, msg string, args ...interface{}) {138 if h, ok := a.t.(tHelper); ok {139 h.Helper()140 }141 EqualErrorf(a.t, theError, errString, msg, args...)142}143// EqualValues asserts that two objects are equal or convertable to the same types144// and equal.145//146// a.EqualValues(uint32(123), int32(123))147func (a *Assertions) EqualValues(expected interface{}, actual interface{}, msgAndArgs ...interface{}) {148 if h, ok := a.t.(tHelper); ok {149 h.Helper()150 }151 EqualValues(a.t, expected, actual, msgAndArgs...)152}153// EqualValuesf asserts that two objects are equal or convertable to the same types154// and equal.155//156// a.EqualValuesf(uint32(123), int32(123), "error message %s", "formatted")157func (a *Assertions) EqualValuesf(expected interface{}, actual interface{}, msg string, args ...interface{}) {158 if h, ok := a.t.(tHelper); ok {159 h.Helper()160 }161 EqualValuesf(a.t, expected, actual, msg, args...)162}163// Equalf asserts that two objects are equal.164//165// a.Equalf(123, 123, "error message %s", "formatted")166//167// Pointer variable equality is determined based on the equality of the168// referenced values (as opposed to the memory addresses). Function equality169// cannot be determined and will always fail.170func (a *Assertions) Equalf(expected interface{}, actual interface{}, msg string, args ...interface{}) {171 if h, ok := a.t.(tHelper); ok {172 h.Helper()173 }174 Equalf(a.t, expected, actual, msg, args...)175}176// Error asserts that a function returned an error (i.e. not `nil`).177//178// actualObj, err := SomeFunction()179// if a.Error(err) {180// assert.Equal(t, expectedError, err)181// }182func (a *Assertions) Error(err error, msgAndArgs ...interface{}) {183 if h, ok := a.t.(tHelper); ok {184 h.Helper()185 }186 Error(a.t, err, msgAndArgs...)187}188// Errorf asserts that a function returned an error (i.e. not `nil`).189//190// actualObj, err := SomeFunction()191// if a.Errorf(err, "error message %s", "formatted") {192// assert.Equal(t, expectedErrorf, err)193// }194func (a *Assertions) Errorf(err error, msg string, args ...interface{}) {195 if h, ok := a.t.(tHelper); ok {196 h.Helper()197 }198 Errorf(a.t, err, msg, args...)199}200// Eventually asserts that given condition will be met in waitFor time,201// periodically checking target function each tick.202//203// a.Eventually(func() bool { return true; }, time.Second, 10*time.Millisecond)204func (a *Assertions) Eventually(condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) {205 if h, ok := a.t.(tHelper); ok {206 h.Helper()207 }208 Eventually(a.t, condition, waitFor, tick, msgAndArgs...)209}210// Eventuallyf asserts that given condition will be met in waitFor time,211// periodically checking target function each tick.212//213// a.Eventuallyf(func() bool { return true; }, time.Second, 10*time.Millisecond, "error message %s", "formatted")214func (a *Assertions) Eventuallyf(condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) {215 if h, ok := a.t.(tHelper); ok {216 h.Helper()217 }218 Eventuallyf(a.t, condition, waitFor, tick, msg, args...)219}220// Exactly asserts that two objects are equal in value and type.221//222// a.Exactly(int32(123), int64(123))223func (a *Assertions) Exactly(expected interface{}, actual interface{}, msgAndArgs ...interface{}) {224 if h, ok := a.t.(tHelper); ok {225 h.Helper()226 }227 Exactly(a.t, expected, actual, msgAndArgs...)228}229// Exactlyf asserts that two objects are equal in value and type.230//231// a.Exactlyf(int32(123), int64(123), "error message %s", "formatted")232func (a *Assertions) Exactlyf(expected interface{}, actual interface{}, msg string, args ...interface{}) {233 if h, ok := a.t.(tHelper); ok {234 h.Helper()235 }236 Exactlyf(a.t, expected, actual, msg, args...)237}238// Fail reports a failure through239func (a *Assertions) Fail(failureMessage string, msgAndArgs ...interface{}) {240 if h, ok := a.t.(tHelper); ok {241 h.Helper()242 }243 Fail(a.t, failureMessage, msgAndArgs...)244}245// FailNow fails test246func (a *Assertions) FailNow(failureMessage string, msgAndArgs ...interface{}) {247 if h, ok := a.t.(tHelper); ok {248 h.Helper()249 }250 FailNow(a.t, failureMessage, msgAndArgs...)251}252// FailNowf fails test253func (a *Assertions) FailNowf(failureMessage string, msg string, args ...interface{}) {254 if h, ok := a.t.(tHelper); ok {255 h.Helper()256 }257 FailNowf(a.t, failureMessage, msg, args...)258}259// Failf reports a failure through260func (a *Assertions) Failf(failureMessage string, msg string, args ...interface{}) {261 if h, ok := a.t.(tHelper); ok {262 h.Helper()263 }264 Failf(a.t, failureMessage, msg, args...)265}266// False asserts that the specified value is false.267//268// a.False(myBool)269func (a *Assertions) False(value bool, msgAndArgs ...interface{}) {270 if h, ok := a.t.(tHelper); ok {271 h.Helper()272 }273 False(a.t, value, msgAndArgs...)274}275// Falsef asserts that the specified value is false.276//277// a.Falsef(myBool, "error message %s", "formatted")278func (a *Assertions) Falsef(value bool, msg string, args ...interface{}) {279 if h, ok := a.t.(tHelper); ok {280 h.Helper()281 }282 Falsef(a.t, value, msg, args...)283}284// FileExists checks whether a file exists in the given path. It also fails if285// the path points to a directory or there is an error when trying to check the file.286func (a *Assertions) FileExists(path string, msgAndArgs ...interface{}) {287 if h, ok := a.t.(tHelper); ok {288 h.Helper()289 }290 FileExists(a.t, path, msgAndArgs...)291}292// FileExistsf checks whether a file exists in the given path. It also fails if293// the path points to a directory or there is an error when trying to check the file.294func (a *Assertions) FileExistsf(path string, msg string, args ...interface{}) {295 if h, ok := a.t.(tHelper); ok {296 h.Helper()297 }298 FileExistsf(a.t, path, msg, args...)299}300// Greater asserts that the first element is greater than the second301//302// a.Greater(2, 1)303// a.Greater(float64(2), float64(1))304// a.Greater("b", "a")305func (a *Assertions) Greater(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) {306 if h, ok := a.t.(tHelper); ok {307 h.Helper()308 }309 Greater(a.t, e1, e2, msgAndArgs...)310}311// GreaterOrEqual asserts that the first element is greater than or equal to the second312//313// a.GreaterOrEqual(2, 1)314// a.GreaterOrEqual(2, 2)315// a.GreaterOrEqual("b", "a")316// a.GreaterOrEqual("b", "b")317func (a *Assertions) GreaterOrEqual(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) {318 if h, ok := a.t.(tHelper); ok {319 h.Helper()320 }321 GreaterOrEqual(a.t, e1, e2, msgAndArgs...)322}323// GreaterOrEqualf asserts that the first element is greater than or equal to the second324//325// a.GreaterOrEqualf(2, 1, "error message %s", "formatted")326// a.GreaterOrEqualf(2, 2, "error message %s", "formatted")327// a.GreaterOrEqualf("b", "a", "error message %s", "formatted")328// a.GreaterOrEqualf("b", "b", "error message %s", "formatted")329func (a *Assertions) GreaterOrEqualf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) {330 if h, ok := a.t.(tHelper); ok {331 h.Helper()332 }333 GreaterOrEqualf(a.t, e1, e2, msg, args...)334}335// Greaterf asserts that the first element is greater than the second336//337// a.Greaterf(2, 1, "error message %s", "formatted")338// a.Greaterf(float64(2), float64(1), "error message %s", "formatted")339// a.Greaterf("b", "a", "error message %s", "formatted")340func (a *Assertions) Greaterf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) {341 if h, ok := a.t.(tHelper); ok {342 h.Helper()343 }344 Greaterf(a.t, e1, e2, msg, args...)345}346// HTTPBodyContains asserts that a specified handler returns a347// body that contains a string.348//349// a.HTTPBodyContains(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")350//351// Returns whether the assertion was successful (true) or not (false).352func (a *Assertions) HTTPBodyContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) {353 if h, ok := a.t.(tHelper); ok {354 h.Helper()355 }356 HTTPBodyContains(a.t, handler, method, url, values, str, msgAndArgs...)357}358// HTTPBodyContainsf asserts that a specified handler returns a359// body that contains a string.360//361// a.HTTPBodyContainsf(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")362//363// Returns whether the assertion was successful (true) or not (false).364func (a *Assertions) HTTPBodyContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) {365 if h, ok := a.t.(tHelper); ok {366 h.Helper()367 }368 HTTPBodyContainsf(a.t, handler, method, url, values, str, msg, args...)369}370// HTTPBodyNotContains asserts that a specified handler returns a371// body that does not contain a string.372//373// a.HTTPBodyNotContains(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")374//375// Returns whether the assertion was successful (true) or not (false).376func (a *Assertions) HTTPBodyNotContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) {377 if h, ok := a.t.(tHelper); ok {378 h.Helper()379 }380 HTTPBodyNotContains(a.t, handler, method, url, values, str, msgAndArgs...)381}382// HTTPBodyNotContainsf asserts that a specified handler returns a383// body that does not contain a string.384//385// a.HTTPBodyNotContainsf(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")386//387// Returns whether the assertion was successful (true) or not (false).388func (a *Assertions) HTTPBodyNotContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) {389 if h, ok := a.t.(tHelper); ok {390 h.Helper()391 }392 HTTPBodyNotContainsf(a.t, handler, method, url, values, str, msg, args...)393}394// HTTPError asserts that a specified handler returns an error status code.395//396// a.HTTPError(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}397//398// Returns whether the assertion was successful (true) or not (false).399func (a *Assertions) HTTPError(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) {400 if h, ok := a.t.(tHelper); ok {401 h.Helper()402 }403 HTTPError(a.t, handler, method, url, values, msgAndArgs...)404}405// HTTPErrorf asserts that a specified handler returns an error status code.406//407// a.HTTPErrorf(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}408//409// Returns whether the assertion was successful (true) or not (false).410func (a *Assertions) HTTPErrorf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) {411 if h, ok := a.t.(tHelper); ok {412 h.Helper()413 }414 HTTPErrorf(a.t, handler, method, url, values, msg, args...)415}416// HTTPRedirect asserts that a specified handler returns a redirect status code.417//418// a.HTTPRedirect(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}419//420// Returns whether the assertion was successful (true) or not (false).421func (a *Assertions) HTTPRedirect(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) {422 if h, ok := a.t.(tHelper); ok {423 h.Helper()424 }425 HTTPRedirect(a.t, handler, method, url, values, msgAndArgs...)426}427// HTTPRedirectf asserts that a specified handler returns a redirect status code.428//429// a.HTTPRedirectf(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}430//431// Returns whether the assertion was successful (true) or not (false).432func (a *Assertions) HTTPRedirectf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) {433 if h, ok := a.t.(tHelper); ok {434 h.Helper()435 }436 HTTPRedirectf(a.t, handler, method, url, values, msg, args...)437}438// HTTPStatusCode asserts that a specified handler returns a specified status code.439//440// a.HTTPStatusCode(myHandler, "GET", "/notImplemented", nil, 501)441//442// Returns whether the assertion was successful (true) or not (false).443func (a *Assertions) HTTPStatusCode(handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msgAndArgs ...interface{}) {444 if h, ok := a.t.(tHelper); ok {445 h.Helper()446 }447 HTTPStatusCode(a.t, handler, method, url, values, statuscode, msgAndArgs...)448}449// HTTPStatusCodef asserts that a specified handler returns a specified status code.450//451// a.HTTPStatusCodef(myHandler, "GET", "/notImplemented", nil, 501, "error message %s", "formatted")452//453// Returns whether the assertion was successful (true) or not (false).454func (a *Assertions) HTTPStatusCodef(handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msg string, args ...interface{}) {455 if h, ok := a.t.(tHelper); ok {456 h.Helper()457 }458 HTTPStatusCodef(a.t, handler, method, url, values, statuscode, msg, args...)459}460// HTTPSuccess asserts that a specified handler returns a success status code.461//462// a.HTTPSuccess(myHandler, "POST", "http://www.google.com", nil)463//464// Returns whether the assertion was successful (true) or not (false).465func (a *Assertions) HTTPSuccess(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) {466 if h, ok := a.t.(tHelper); ok {467 h.Helper()468 }469 HTTPSuccess(a.t, handler, method, url, values, msgAndArgs...)470}471// HTTPSuccessf asserts that a specified handler returns a success status code.472//473// a.HTTPSuccessf(myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted")474//475// Returns whether the assertion was successful (true) or not (false).476func (a *Assertions) HTTPSuccessf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) {477 if h, ok := a.t.(tHelper); ok {478 h.Helper()479 }480 HTTPSuccessf(a.t, handler, method, url, values, msg, args...)481}482// Implements asserts that an object is implemented by the specified interface.483//484// a.Implements((*MyInterface)(nil), new(MyObject))485func (a *Assertions) Implements(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) {486 if h, ok := a.t.(tHelper); ok {487 h.Helper()488 }489 Implements(a.t, interfaceObject, object, msgAndArgs...)490}491// Implementsf asserts that an object is implemented by the specified interface.492//493// a.Implementsf((*MyInterface)(nil), new(MyObject), "error message %s", "formatted")494func (a *Assertions) Implementsf(interfaceObject interface{}, object interface{}, msg string, args ...interface{}) {495 if h, ok := a.t.(tHelper); ok {496 h.Helper()497 }498 Implementsf(a.t, interfaceObject, object, msg, args...)499}500// InDelta asserts that the two numerals are within delta of each other.501//502// a.InDelta(math.Pi, 22/7.0, 0.01)503func (a *Assertions) InDelta(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {504 if h, ok := a.t.(tHelper); ok {505 h.Helper()506 }507 InDelta(a.t, expected, actual, delta, msgAndArgs...)508}509// InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.510func (a *Assertions) InDeltaMapValues(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {511 if h, ok := a.t.(tHelper); ok {512 h.Helper()513 }514 InDeltaMapValues(a.t, expected, actual, delta, msgAndArgs...)515}516// InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.517func (a *Assertions) InDeltaMapValuesf(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) {518 if h, ok := a.t.(tHelper); ok {519 h.Helper()520 }521 InDeltaMapValuesf(a.t, expected, actual, delta, msg, args...)522}523// InDeltaSlice is the same as InDelta, except it compares two slices.524func (a *Assertions) InDeltaSlice(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {525 if h, ok := a.t.(tHelper); ok {526 h.Helper()527 }528 InDeltaSlice(a.t, expected, actual, delta, msgAndArgs...)529}530// InDeltaSlicef is the same as InDelta, except it compares two slices.531func (a *Assertions) InDeltaSlicef(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) {532 if h, ok := a.t.(tHelper); ok {533 h.Helper()534 }535 InDeltaSlicef(a.t, expected, actual, delta, msg, args...)536}537// InDeltaf asserts that the two numerals are within delta of each other.538//539// a.InDeltaf(math.Pi, 22/7.0, 0.01, "error message %s", "formatted")540func (a *Assertions) InDeltaf(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) {541 if h, ok := a.t.(tHelper); ok {542 h.Helper()543 }544 InDeltaf(a.t, expected, actual, delta, msg, args...)545}546// InEpsilon asserts that expected and actual have a relative error less than epsilon547func (a *Assertions) InEpsilon(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) {548 if h, ok := a.t.(tHelper); ok {549 h.Helper()550 }551 InEpsilon(a.t, expected, actual, epsilon, msgAndArgs...)552}553// InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices.554func (a *Assertions) InEpsilonSlice(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) {555 if h, ok := a.t.(tHelper); ok {556 h.Helper()557 }558 InEpsilonSlice(a.t, expected, actual, epsilon, msgAndArgs...)559}560// InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices.561func (a *Assertions) InEpsilonSlicef(expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) {562 if h, ok := a.t.(tHelper); ok {563 h.Helper()564 }565 InEpsilonSlicef(a.t, expected, actual, epsilon, msg, args...)566}567// InEpsilonf asserts that expected and actual have a relative error less than epsilon568func (a *Assertions) InEpsilonf(expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) {569 if h, ok := a.t.(tHelper); ok {570 h.Helper()571 }572 InEpsilonf(a.t, expected, actual, epsilon, msg, args...)573}574// IsType asserts that the specified objects are of the same type.575func (a *Assertions) IsType(expectedType interface{}, object interface{}, msgAndArgs ...interface{}) {576 if h, ok := a.t.(tHelper); ok {577 h.Helper()578 }579 IsType(a.t, expectedType, object, msgAndArgs...)580}581// IsTypef asserts that the specified objects are of the same type.582func (a *Assertions) IsTypef(expectedType interface{}, object interface{}, msg string, args ...interface{}) {583 if h, ok := a.t.(tHelper); ok {584 h.Helper()585 }586 IsTypef(a.t, expectedType, object, msg, args...)587}588// JSONEq asserts that two JSON strings are equivalent.589//590// a.JSONEq(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)591func (a *Assertions) JSONEq(expected string, actual string, msgAndArgs ...interface{}) {592 if h, ok := a.t.(tHelper); ok {593 h.Helper()594 }595 JSONEq(a.t, expected, actual, msgAndArgs...)596}597// JSONEqf asserts that two JSON strings are equivalent.598//599// a.JSONEqf(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted")600func (a *Assertions) JSONEqf(expected string, actual string, msg string, args ...interface{}) {601 if h, ok := a.t.(tHelper); ok {602 h.Helper()603 }604 JSONEqf(a.t, expected, actual, msg, args...)605}606// Len asserts that the specified object has specific length.607// Len also fails if the object has a type that len() not accept.608//609// a.Len(mySlice, 3)610func (a *Assertions) Len(object interface{}, length int, msgAndArgs ...interface{}) {611 if h, ok := a.t.(tHelper); ok {612 h.Helper()613 }614 Len(a.t, object, length, msgAndArgs...)615}616// Lenf asserts that the specified object has specific length.617// Lenf also fails if the object has a type that len() not accept.618//619// a.Lenf(mySlice, 3, "error message %s", "formatted")620func (a *Assertions) Lenf(object interface{}, length int, msg string, args ...interface{}) {621 if h, ok := a.t.(tHelper); ok {622 h.Helper()623 }624 Lenf(a.t, object, length, msg, args...)625}626// Less asserts that the first element is less than the second627//628// a.Less(1, 2)629// a.Less(float64(1), float64(2))630// a.Less("a", "b")631func (a *Assertions) Less(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) {632 if h, ok := a.t.(tHelper); ok {633 h.Helper()634 }635 Less(a.t, e1, e2, msgAndArgs...)636}637// LessOrEqual asserts that the first element is less than or equal to the second638//639// a.LessOrEqual(1, 2)640// a.LessOrEqual(2, 2)641// a.LessOrEqual("a", "b")642// a.LessOrEqual("b", "b")643func (a *Assertions) LessOrEqual(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) {644 if h, ok := a.t.(tHelper); ok {645 h.Helper()646 }647 LessOrEqual(a.t, e1, e2, msgAndArgs...)648}649// LessOrEqualf asserts that the first element is less than or equal to the second650//651// a.LessOrEqualf(1, 2, "error message %s", "formatted")652// a.LessOrEqualf(2, 2, "error message %s", "formatted")653// a.LessOrEqualf("a", "b", "error message %s", "formatted")654// a.LessOrEqualf("b", "b", "error message %s", "formatted")655func (a *Assertions) LessOrEqualf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) {656 if h, ok := a.t.(tHelper); ok {657 h.Helper()658 }659 LessOrEqualf(a.t, e1, e2, msg, args...)660}661// Lessf asserts that the first element is less than the second662//663// a.Lessf(1, 2, "error message %s", "formatted")664// a.Lessf(float64(1), float64(2), "error message %s", "formatted")665// a.Lessf("a", "b", "error message %s", "formatted")666func (a *Assertions) Lessf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) {667 if h, ok := a.t.(tHelper); ok {668 h.Helper()669 }670 Lessf(a.t, e1, e2, msg, args...)671}672// Never asserts that the given condition doesn't satisfy in waitFor time,673// periodically checking the target function each tick.674//675// a.Never(func() bool { return false; }, time.Second, 10*time.Millisecond)676func (a *Assertions) Never(condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) {677 if h, ok := a.t.(tHelper); ok {678 h.Helper()679 }680 Never(a.t, condition, waitFor, tick, msgAndArgs...)681}682// Neverf asserts that the given condition doesn't satisfy in waitFor time,683// periodically checking the target function each tick.684//685// a.Neverf(func() bool { return false; }, time.Second, 10*time.Millisecond, "error message %s", "formatted")686func (a *Assertions) Neverf(condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) {687 if h, ok := a.t.(tHelper); ok {688 h.Helper()689 }690 Neverf(a.t, condition, waitFor, tick, msg, args...)691}692// Nil asserts that the specified object is nil.693//694// a.Nil(err)695func (a *Assertions) Nil(object interface{}, msgAndArgs ...interface{}) {696 if h, ok := a.t.(tHelper); ok {697 h.Helper()698 }699 Nil(a.t, object, msgAndArgs...)700}701// Nilf asserts that the specified object is nil.702//703// a.Nilf(err, "error message %s", "formatted")704func (a *Assertions) Nilf(object interface{}, msg string, args ...interface{}) {705 if h, ok := a.t.(tHelper); ok {706 h.Helper()707 }708 Nilf(a.t, object, msg, args...)709}710// NoDirExists checks whether a directory does not exist in the given path.711// It fails if the path points to an existing _directory_ only.712func (a *Assertions) NoDirExists(path string, msgAndArgs ...interface{}) {713 if h, ok := a.t.(tHelper); ok {714 h.Helper()715 }716 NoDirExists(a.t, path, msgAndArgs...)717}718// NoDirExistsf checks whether a directory does not exist in the given path.719// It fails if the path points to an existing _directory_ only.720func (a *Assertions) NoDirExistsf(path string, msg string, args ...interface{}) {721 if h, ok := a.t.(tHelper); ok {722 h.Helper()723 }724 NoDirExistsf(a.t, path, msg, args...)725}726// NoError asserts that a function returned no error (i.e. `nil`).727//728// actualObj, err := SomeFunction()729// if a.NoError(err) {730// assert.Equal(t, expectedObj, actualObj)731// }732func (a *Assertions) NoError(err error, msgAndArgs ...interface{}) {733 if h, ok := a.t.(tHelper); ok {734 h.Helper()735 }736 NoError(a.t, err, msgAndArgs...)737}738// NoErrorf asserts that a function returned no error (i.e. `nil`).739//740// actualObj, err := SomeFunction()741// if a.NoErrorf(err, "error message %s", "formatted") {742// assert.Equal(t, expectedObj, actualObj)743// }744func (a *Assertions) NoErrorf(err error, msg string, args ...interface{}) {745 if h, ok := a.t.(tHelper); ok {746 h.Helper()747 }748 NoErrorf(a.t, err, msg, args...)749}750// NoFileExists checks whether a file does not exist in a given path. It fails751// if the path points to an existing _file_ only.752func (a *Assertions) NoFileExists(path string, msgAndArgs ...interface{}) {753 if h, ok := a.t.(tHelper); ok {754 h.Helper()755 }756 NoFileExists(a.t, path, msgAndArgs...)757}758// NoFileExistsf checks whether a file does not exist in a given path. It fails759// if the path points to an existing _file_ only.760func (a *Assertions) NoFileExistsf(path string, msg string, args ...interface{}) {761 if h, ok := a.t.(tHelper); ok {762 h.Helper()763 }764 NoFileExistsf(a.t, path, msg, args...)765}766// NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the767// specified substring or element.768//769// a.NotContains("Hello World", "Earth")770// a.NotContains(["Hello", "World"], "Earth")771// a.NotContains({"Hello": "World"}, "Earth")772func (a *Assertions) NotContains(s interface{}, contains interface{}, msgAndArgs ...interface{}) {773 if h, ok := a.t.(tHelper); ok {774 h.Helper()775 }776 NotContains(a.t, s, contains, msgAndArgs...)777}778// NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the779// specified substring or element.780//781// a.NotContainsf("Hello World", "Earth", "error message %s", "formatted")782// a.NotContainsf(["Hello", "World"], "Earth", "error message %s", "formatted")783// a.NotContainsf({"Hello": "World"}, "Earth", "error message %s", "formatted")784func (a *Assertions) NotContainsf(s interface{}, contains interface{}, msg string, args ...interface{}) {785 if h, ok := a.t.(tHelper); ok {786 h.Helper()787 }788 NotContainsf(a.t, s, contains, msg, args...)789}790// NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either791// a slice or a channel with len == 0.792//793// if a.NotEmpty(obj) {794// assert.Equal(t, "two", obj[1])795// }796func (a *Assertions) NotEmpty(object interface{}, msgAndArgs ...interface{}) {797 if h, ok := a.t.(tHelper); ok {798 h.Helper()799 }800 NotEmpty(a.t, object, msgAndArgs...)801}802// NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either803// a slice or a channel with len == 0.804//805// if a.NotEmptyf(obj, "error message %s", "formatted") {806// assert.Equal(t, "two", obj[1])807// }808func (a *Assertions) NotEmptyf(object interface{}, msg string, args ...interface{}) {809 if h, ok := a.t.(tHelper); ok {810 h.Helper()811 }812 NotEmptyf(a.t, object, msg, args...)813}814// NotEqual asserts that the specified values are NOT equal.815//816// a.NotEqual(obj1, obj2)817//818// Pointer variable equality is determined based on the equality of the819// referenced values (as opposed to the memory addresses).820func (a *Assertions) NotEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) {821 if h, ok := a.t.(tHelper); ok {822 h.Helper()823 }824 NotEqual(a.t, expected, actual, msgAndArgs...)825}826// NotEqualValues asserts that two objects are not equal even when converted to the same type827//828// a.NotEqualValues(obj1, obj2)829func (a *Assertions) NotEqualValues(expected interface{}, actual interface{}, msgAndArgs ...interface{}) {830 if h, ok := a.t.(tHelper); ok {831 h.Helper()832 }833 NotEqualValues(a.t, expected, actual, msgAndArgs...)834}835// NotEqualValuesf asserts that two objects are not equal even when converted to the same type836//837// a.NotEqualValuesf(obj1, obj2, "error message %s", "formatted")838func (a *Assertions) NotEqualValuesf(expected interface{}, actual interface{}, msg string, args ...interface{}) {839 if h, ok := a.t.(tHelper); ok {840 h.Helper()841 }842 NotEqualValuesf(a.t, expected, actual, msg, args...)843}844// NotEqualf asserts that the specified values are NOT equal.845//846// a.NotEqualf(obj1, obj2, "error message %s", "formatted")847//848// Pointer variable equality is determined based on the equality of the849// referenced values (as opposed to the memory addresses).850func (a *Assertions) NotEqualf(expected interface{}, actual interface{}, msg string, args ...interface{}) {851 if h, ok := a.t.(tHelper); ok {852 h.Helper()853 }854 NotEqualf(a.t, expected, actual, msg, args...)855}856// NotNil asserts that the specified object is not nil.857//858// a.NotNil(err)859func (a *Assertions) NotNil(object interface{}, msgAndArgs ...interface{}) {860 if h, ok := a.t.(tHelper); ok {861 h.Helper()862 }863 NotNil(a.t, object, msgAndArgs...)864}865// NotNilf asserts that the specified object is not nil.866//867// a.NotNilf(err, "error message %s", "formatted")868func (a *Assertions) NotNilf(object interface{}, msg string, args ...interface{}) {869 if h, ok := a.t.(tHelper); ok {870 h.Helper()871 }872 NotNilf(a.t, object, msg, args...)873}874// NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.875//876// a.NotPanics(func(){ RemainCalm() })877func (a *Assertions) NotPanics(f assert.PanicTestFunc, msgAndArgs ...interface{}) {878 if h, ok := a.t.(tHelper); ok {879 h.Helper()880 }881 NotPanics(a.t, f, msgAndArgs...)882}883// NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic.884//885// a.NotPanicsf(func(){ RemainCalm() }, "error message %s", "formatted")886func (a *Assertions) NotPanicsf(f assert.PanicTestFunc, msg string, args ...interface{}) {887 if h, ok := a.t.(tHelper); ok {888 h.Helper()889 }890 NotPanicsf(a.t, f, msg, args...)891}892// NotRegexp asserts that a specified regexp does not match a string.893//894// a.NotRegexp(regexp.MustCompile("starts"), "it's starting")895// a.NotRegexp("^start", "it's not starting")896func (a *Assertions) NotRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) {897 if h, ok := a.t.(tHelper); ok {898 h.Helper()899 }900 NotRegexp(a.t, rx, str, msgAndArgs...)901}902// NotRegexpf asserts that a specified regexp does not match a string.903//904// a.NotRegexpf(regexp.MustCompile("starts"), "it's starting", "error message %s", "formatted")905// a.NotRegexpf("^start", "it's not starting", "error message %s", "formatted")906func (a *Assertions) NotRegexpf(rx interface{}, str interface{}, msg string, args ...interface{}) {907 if h, ok := a.t.(tHelper); ok {908 h.Helper()909 }910 NotRegexpf(a.t, rx, str, msg, args...)911}912// NotSame asserts that two pointers do not reference the same object.913//914// a.NotSame(ptr1, ptr2)915//916// Both arguments must be pointer variables. Pointer variable sameness is917// determined based on the equality of both type and value.918func (a *Assertions) NotSame(expected interface{}, actual interface{}, msgAndArgs ...interface{}) {919 if h, ok := a.t.(tHelper); ok {920 h.Helper()921 }922 NotSame(a.t, expected, actual, msgAndArgs...)923}924// NotSamef asserts that two pointers do not reference the same object.925//926// a.NotSamef(ptr1, ptr2, "error message %s", "formatted")927//928// Both arguments must be pointer variables. Pointer variable sameness is929// determined based on the equality of both type and value.930func (a *Assertions) NotSamef(expected interface{}, actual interface{}, msg string, args ...interface{}) {931 if h, ok := a.t.(tHelper); ok {932 h.Helper()933 }934 NotSamef(a.t, expected, actual, msg, args...)935}936// NotSubset asserts that the specified list(array, slice...) contains not all937// elements given in the specified subset(array, slice...).938//939// a.NotSubset([1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]")940func (a *Assertions) NotSubset(list interface{}, subset interface{}, msgAndArgs ...interface{}) {941 if h, ok := a.t.(tHelper); ok {942 h.Helper()943 }944 NotSubset(a.t, list, subset, msgAndArgs...)945}946// NotSubsetf asserts that the specified list(array, slice...) contains not all947// elements given in the specified subset(array, slice...).948//949// a.NotSubsetf([1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]", "error message %s", "formatted")950func (a *Assertions) NotSubsetf(list interface{}, subset interface{}, msg string, args ...interface{}) {951 if h, ok := a.t.(tHelper); ok {952 h.Helper()953 }954 NotSubsetf(a.t, list, subset, msg, args...)955}956// NotZero asserts that i is not the zero value for its type.957func (a *Assertions) NotZero(i interface{}, msgAndArgs ...interface{}) {958 if h, ok := a.t.(tHelper); ok {959 h.Helper()960 }961 NotZero(a.t, i, msgAndArgs...)962}963// NotZerof asserts that i is not the zero value for its type.964func (a *Assertions) NotZerof(i interface{}, msg string, args ...interface{}) {965 if h, ok := a.t.(tHelper); ok {966 h.Helper()967 }968 NotZerof(a.t, i, msg, args...)969}970// Panics asserts that the code inside the specified PanicTestFunc panics.971//972// a.Panics(func(){ GoCrazy() })973func (a *Assertions) Panics(f assert.PanicTestFunc, msgAndArgs ...interface{}) {974 if h, ok := a.t.(tHelper); ok {975 h.Helper()976 }977 Panics(a.t, f, msgAndArgs...)978}979// PanicsWithError asserts that the code inside the specified PanicTestFunc980// panics, and that the recovered panic value is an error that satisfies the981// EqualError comparison.982//983// a.PanicsWithError("crazy error", func(){ GoCrazy() })984func (a *Assertions) PanicsWithError(errString string, f assert.PanicTestFunc, msgAndArgs ...interface{}) {985 if h, ok := a.t.(tHelper); ok {986 h.Helper()987 }988 PanicsWithError(a.t, errString, f, msgAndArgs...)989}990// PanicsWithErrorf asserts that the code inside the specified PanicTestFunc991// panics, and that the recovered panic value is an error that satisfies the992// EqualError comparison.993//994// a.PanicsWithErrorf("crazy error", func(){ GoCrazy() }, "error message %s", "formatted")995func (a *Assertions) PanicsWithErrorf(errString string, f assert.PanicTestFunc, msg string, args ...interface{}) {996 if h, ok := a.t.(tHelper); ok {997 h.Helper()998 }999 PanicsWithErrorf(a.t, errString, f, msg, args...)1000}1001// PanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that1002// the recovered panic value equals the expected panic value.1003//1004// a.PanicsWithValue("crazy error", func(){ GoCrazy() })1005func (a *Assertions) PanicsWithValue(expected interface{}, f assert.PanicTestFunc, msgAndArgs ...interface{}) {1006 if h, ok := a.t.(tHelper); ok {1007 h.Helper()1008 }1009 PanicsWithValue(a.t, expected, f, msgAndArgs...)1010}1011// PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that1012// the recovered panic value equals the expected panic value.1013//1014// a.PanicsWithValuef("crazy error", func(){ GoCrazy() }, "error message %s", "formatted")1015func (a *Assertions) PanicsWithValuef(expected interface{}, f assert.PanicTestFunc, msg string, args ...interface{}) {1016 if h, ok := a.t.(tHelper); ok {1017 h.Helper()1018 }1019 PanicsWithValuef(a.t, expected, f, msg, args...)1020}1021// Panicsf asserts that the code inside the specified PanicTestFunc panics.1022//1023// a.Panicsf(func(){ GoCrazy() }, "error message %s", "formatted")1024func (a *Assertions) Panicsf(f assert.PanicTestFunc, msg string, args ...interface{}) {1025 if h, ok := a.t.(tHelper); ok {1026 h.Helper()1027 }1028 Panicsf(a.t, f, msg, args...)1029}1030// Regexp asserts that a specified regexp matches a string.1031//1032// a.Regexp(regexp.MustCompile("start"), "it's starting")1033// a.Regexp("start...$", "it's not starting")1034func (a *Assertions) Regexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) {1035 if h, ok := a.t.(tHelper); ok {1036 h.Helper()1037 }1038 Regexp(a.t, rx, str, msgAndArgs...)1039}1040// Regexpf asserts that a specified regexp matches a string.1041//1042// a.Regexpf(regexp.MustCompile("start"), "it's starting", "error message %s", "formatted")1043// a.Regexpf("start...$", "it's not starting", "error message %s", "formatted")1044func (a *Assertions) Regexpf(rx interface{}, str interface{}, msg string, args ...interface{}) {1045 if h, ok := a.t.(tHelper); ok {1046 h.Helper()1047 }1048 Regexpf(a.t, rx, str, msg, args...)1049}1050// Same asserts that two pointers reference the same object.1051//1052// a.Same(ptr1, ptr2)1053//1054// Both arguments must be pointer variables. Pointer variable sameness is1055// determined based on the equality of both type and value.1056func (a *Assertions) Same(expected interface{}, actual interface{}, msgAndArgs ...interface{}) {1057 if h, ok := a.t.(tHelper); ok {1058 h.Helper()1059 }1060 Same(a.t, expected, actual, msgAndArgs...)1061}1062// Samef asserts that two pointers reference the same object.1063//1064// a.Samef(ptr1, ptr2, "error message %s", "formatted")1065//1066// Both arguments must be pointer variables. Pointer variable sameness is1067// determined based on the equality of both type and value.1068func (a *Assertions) Samef(expected interface{}, actual interface{}, msg string, args ...interface{}) {1069 if h, ok := a.t.(tHelper); ok {1070 h.Helper()1071 }1072 Samef(a.t, expected, actual, msg, args...)1073}1074// Subset asserts that the specified list(array, slice...) contains all1075// elements given in the specified subset(array, slice...).1076//1077// a.Subset([1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]")1078func (a *Assertions) Subset(list interface{}, subset interface{}, msgAndArgs ...interface{}) {1079 if h, ok := a.t.(tHelper); ok {1080 h.Helper()1081 }1082 Subset(a.t, list, subset, msgAndArgs...)1083}1084// Subsetf asserts that the specified list(array, slice...) contains all1085// elements given in the specified subset(array, slice...).1086//1087// a.Subsetf([1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]", "error message %s", "formatted")1088func (a *Assertions) Subsetf(list interface{}, subset interface{}, msg string, args ...interface{}) {1089 if h, ok := a.t.(tHelper); ok {1090 h.Helper()1091 }1092 Subsetf(a.t, list, subset, msg, args...)1093}1094// True asserts that the specified value is true.1095//1096// a.True(myBool)1097func (a *Assertions) True(value bool, msgAndArgs ...interface{}) {1098 if h, ok := a.t.(tHelper); ok {1099 h.Helper()1100 }1101 True(a.t, value, msgAndArgs...)1102}1103// Truef asserts that the specified value is true.1104//1105// a.Truef(myBool, "error message %s", "formatted")1106func (a *Assertions) Truef(value bool, msg string, args ...interface{}) {1107 if h, ok := a.t.(tHelper); ok {1108 h.Helper()1109 }1110 Truef(a.t, value, msg, args...)1111}1112// WithinDuration asserts that the two times are within duration delta of each other.1113//1114// a.WithinDuration(time.Now(), time.Now(), 10*time.Second)1115func (a *Assertions) WithinDuration(expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) {1116 if h, ok := a.t.(tHelper); ok {1117 h.Helper()1118 }1119 WithinDuration(a.t, expected, actual, delta, msgAndArgs...)1120}1121// WithinDurationf asserts that the two times are within duration delta of each other.1122//1123// a.WithinDurationf(time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted")1124func (a *Assertions) WithinDurationf(expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) {1125 if h, ok := a.t.(tHelper); ok {1126 h.Helper()1127 }1128 WithinDurationf(a.t, expected, actual, delta, msg, args...)1129}1130// YAMLEq asserts that two YAML strings are equivalent.1131func (a *Assertions) YAMLEq(expected string, actual string, msgAndArgs ...interface{}) {1132 if h, ok := a.t.(tHelper); ok {1133 h.Helper()1134 }1135 YAMLEq(a.t, expected, actual, msgAndArgs...)1136}1137// YAMLEqf asserts that two YAML strings are equivalent.1138func (a *Assertions) YAMLEqf(expected string, actual string, msg string, args ...interface{}) {1139 if h, ok := a.t.(tHelper); ok {1140 h.Helper()1141 }1142 YAMLEqf(a.t, expected, actual, msg, args...)1143}1144// Zero asserts that i is the zero value for its type.1145func (a *Assertions) Zero(i interface{}, msgAndArgs ...interface{}) {1146 if h, ok := a.t.(tHelper); ok {1147 h.Helper()1148 }1149 Zero(a.t, i, msgAndArgs...)1150}1151// Zerof asserts that i is the zero value for its type.1152func (a *Assertions) Zerof(i interface{}, msg string, args ...interface{}) {1153 if h, ok := a.t.(tHelper); ok {1154 h.Helper()1155 }1156 Zerof(a.t, i, msg, args...)1157}...

Full Screen

Full Screen

Helper

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World")4}5import (6func main() {7 fmt.Println("Hello World")8}9import (10func main() {11 fmt.Println("Hello World")12}13import (14func main() {15 fmt.Println("Hello World")16}17import (18func main() {19 fmt.Println("Hello World")20}21import (22func main() {23 fmt.Println("Hello World")24}

Full Screen

Full Screen

Helper

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 h.HelperMethod()4}5import (6func main() {7 h.HelperMethod()8}9import (10func main() {11 h.HelperMethod()12}13import (14func main() {15 h.HelperMethod()16}17import (18func main() {19 h.HelperMethod()20}21import (22func main() {23 h.HelperMethod()24}25import (26func main() {27 h.HelperMethod()28}29import (30func main() {31 h.HelperMethod()32}33import (34func main() {35 h.HelperMethod()36}37import (38func main() {39 h.HelperMethod()40}41import (42func main() {43 h.HelperMethod()44}45import (46func main() {47 h.HelperMethod()48}49import (50func main() {51 h.HelperMethod()52}

Full Screen

Full Screen

Helper

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, playground")4 h := Helper{}5 h.HelperMethod()6}7import "fmt"8type Helper struct {9}10func (h *Helper) HelperMethod() {11 fmt.Println("Hello, playground")12}13cannot use h (type Helper) as type helper.Helper in argument to helper.HelperMethod14h := helper.Helper{}15h.HelperMethod()16cannot use h (type Helper) as type helper.Helper in argument to helper.HelperMethod17import "fmt"18import "helper"19func main() {20 fmt.Println("Hello, playground")21 h := Helper{}22 h.HelperMethod()23}24import "fmt"25type Helper struct {26}27func (h *Helper) HelperMethod() {28 fmt.Println("Hello, playground")29}30h := helper.Helper{}31h.HelperMethod()32import "fmt"33import "helper"34func main() {35 fmt.Println("Hello, playground")36 h := Helper{}37 h.HelperMethod()38}39import "fmt"40type Helper struct {41}42func (h *Helper) HelperMethod() {43 fmt.Println("Hello, playground")44}45h := helper.Helper{}46h.HelperMethod()47cannot use h (type Helper) as type helper.Helper

Full Screen

Full Screen

Helper

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 h := Helper{}5 h.HelperMethod()6}7import (8func main() {9 fmt.Println("Hello, playground")10 h := Helper{}11 h.HelperMethod()12}13import (14func main() {15 fmt.Println("Hello, playground")16 h := Helper{}17 h.HelperMethod()18}19import (20func main() {21 fmt.Println("Hello, playground")22 h := Helper{}23 h.HelperMethod()24}25import (26func main() {27 fmt.Println("Hello, playground")28 h := Helper{}29 h.HelperMethod()30}31import (32func main() {33 fmt.Println("Hello, playground")34 h := Helper{}35 h.HelperMethod()36}37import (38func main() {39 fmt.Println("Hello, playground")40 h := Helper{}41 h.HelperMethod()42}43import (44func main() {45 fmt.Println("Hello, playground")46 h := Helper{}47 h.HelperMethod()48}49import (50func main() {51 fmt.Println("Hello, playground")52 h := Helper{}53 h.HelperMethod()54}55import (56func main() {57 fmt.Println("Hello, playground")58 h := Helper{}59 h.HelperMethod()60}61import (62func main() {63 fmt.Println("Hello, playground")64 h := Helper{}65 h.HelperMethod()66}

Full Screen

Full Screen

Helper

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 k = max(i, j)4 fmt.Printf("Max value is : %d5}6func max(num1, num2 int) int {7 if (num1 > num2) {8 } else {9 }10}11func function_name( [parameter list] ) [return_types] {12}13import "fmt"14func main() {15 a, b := swap("Mahesh", "Kumar")16 fmt.Println(a, b)17}18func swap(x, y string) (string, string) {19}20func function_name( [parameter list] ) [return_types] {21}22import "fmt"23func main() {24 a, b := swap("Mahesh", "Kumar")25 fmt.Println(a, b)26}27func swap(x, y string) (a, b string) {28}29In the above program, we have created two functions named swap() and main(). The swap() function takes two string parameters and

Full Screen

Full Screen

Helper

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 h.Helper()5 h.Helper2()6}7import (8type Helper struct {9}10func (h Helper) Helper() {11 fmt.Println("Helper")12}13func (h Helper) Helper2() {14 fmt.Println("Helper2")15}16import (17type Helper struct {18}19func (h Helper) Helper() {20 fmt.Println("Helper")21}22func (h Helper) Helper2() {23 fmt.Println("Helper2")24}

Full Screen

Full Screen

Helper

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 var s1 = Student{"Ravi", 1}5 s1.Helper()6}7import (8func main() {9 fmt.Println("Hello, playground")10 var s1 = Student{"Ravi", 1}11 s1.Helper()12}13import (14func main() {15 fmt.Println("Hello, playground")16 var s1 = Student{"Ravi", 1}17 s1.Helper()18}19import (20func main() {21 fmt.Println("Hello, playground")22 var s1 = Student{"Ravi", 1}23 s1.Helper()24}25import (26func main() {27 fmt.Println("Hello, playground")28 var s1 = Student{"Ravi", 1}29 s1.Helper()30}31import (32func main() {33 fmt.Println("Hello, playground")34 var s1 = Student{"Ravi", 1}35 s1.Helper()36}37import (38func main() {39 fmt.Println("Hello, playground")40 var s1 = Student{"Ravi", 1}41 s1.Helper()42}43import (44func main() {45 fmt.Println("Hello, playground")46 var s1 = Student{"Ravi", 1}47 s1.Helper()48}49import (50func main() {51 fmt.Println("Hello, playground")52 var s1 = Student{"Ravi", 1}53 s1.Helper()54}55import (56func main()

Full Screen

Full Screen

Helper

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 var c = Car{"Audi", 2019}4 fmt.Println(c)5 c.Helper()6}7import "fmt"8func main() {9 var c = Car{"Audi", 2019}10 fmt.Println(c)11 c.Helper()12}

Full Screen

Full Screen

Helper

Using AI Code Generation

copy

Full Screen

1cannot use is (type *is) as type is in field value:2 *is does not implement is (missing Helper method)3import "fmt"4type is interface {5}6type Helper interface {7 Helper()8}9type is struct {10}11func (i *is) Helper() {12 fmt.Println("code to use Helper method of is class")13}14func main() {15 i := is{}16 i.Helper()17}18import "fmt"19type is interface {20}21type Helper interface {22 Helper()23}24type is struct {25}26func (i *is) Helper() {27 fmt.Println("code to use Helper method of is class")28}29func main() {30 i := is{}31 i.Helper()32}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful