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