require.go (63049B)
1 // Code generated with github.com/stretchr/testify/_codegen; DO NOT EDIT. 2 3 package require 4 5 import ( 6 assert "github.com/stretchr/testify/assert" 7 http "net/http" 8 url "net/url" 9 time "time" 10 ) 11 12 // Condition uses a Comparison to assert a complex condition. 13 func 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 return 19 } 20 t.FailNow() 21 } 22 23 // Conditionf uses a Comparison to assert a complex condition. 24 func Conditionf(t TestingT, comp assert.Comparison, msg string, args ...interface{}) { 25 if h, ok := t.(tHelper); ok { 26 h.Helper() 27 } 28 if assert.Conditionf(t, comp, msg, args...) { 29 return 30 } 31 t.FailNow() 32 } 33 34 // Contains asserts that the specified string, list(array, slice...) or map contains the 35 // specified substring or element. 36 // 37 // assert.Contains(t, "Hello World", "World") 38 // assert.Contains(t, ["Hello", "World"], "World") 39 // assert.Contains(t, {"Hello": "World"}, "Hello") 40 func Contains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) { 41 if h, ok := t.(tHelper); ok { 42 h.Helper() 43 } 44 if assert.Contains(t, s, contains, msgAndArgs...) { 45 return 46 } 47 t.FailNow() 48 } 49 50 // Containsf asserts that the specified string, list(array, slice...) or map contains the 51 // specified substring or element. 52 // 53 // assert.Containsf(t, "Hello World", "World", "error message %s", "formatted") 54 // assert.Containsf(t, ["Hello", "World"], "World", "error message %s", "formatted") 55 // assert.Containsf(t, {"Hello": "World"}, "Hello", "error message %s", "formatted") 56 func Containsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) { 57 if h, ok := t.(tHelper); ok { 58 h.Helper() 59 } 60 if assert.Containsf(t, s, contains, msg, args...) { 61 return 62 } 63 t.FailNow() 64 } 65 66 // DirExists checks whether a directory exists in the given path. It also fails 67 // if the path is a file rather a directory or there is an error checking whether it exists. 68 func DirExists(t TestingT, path string, msgAndArgs ...interface{}) { 69 if h, ok := t.(tHelper); ok { 70 h.Helper() 71 } 72 if assert.DirExists(t, path, msgAndArgs...) { 73 return 74 } 75 t.FailNow() 76 } 77 78 // DirExistsf checks whether a directory exists in the given path. It also fails 79 // if the path is a file rather a directory or there is an error checking whether it exists. 80 func DirExistsf(t TestingT, path string, msg string, args ...interface{}) { 81 if h, ok := t.(tHelper); ok { 82 h.Helper() 83 } 84 if assert.DirExistsf(t, path, msg, args...) { 85 return 86 } 87 t.FailNow() 88 } 89 90 // ElementsMatch asserts that the specified listA(array, slice...) is equal to specified 91 // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, 92 // the number of appearances of each of them in both lists should match. 93 // 94 // assert.ElementsMatch(t, [1, 3, 2, 3], [1, 3, 3, 2]) 95 func ElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndArgs ...interface{}) { 96 if h, ok := t.(tHelper); ok { 97 h.Helper() 98 } 99 if assert.ElementsMatch(t, listA, listB, msgAndArgs...) { 100 return 101 } 102 t.FailNow() 103 } 104 105 // ElementsMatchf asserts that the specified listA(array, slice...) is equal to specified 106 // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, 107 // the number of appearances of each of them in both lists should match. 108 // 109 // assert.ElementsMatchf(t, [1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted") 110 func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) { 111 if h, ok := t.(tHelper); ok { 112 h.Helper() 113 } 114 if assert.ElementsMatchf(t, listA, listB, msg, args...) { 115 return 116 } 117 t.FailNow() 118 } 119 120 // Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either 121 // a slice or a channel with len == 0. 122 // 123 // assert.Empty(t, obj) 124 func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) { 125 if h, ok := t.(tHelper); ok { 126 h.Helper() 127 } 128 if assert.Empty(t, object, msgAndArgs...) { 129 return 130 } 131 t.FailNow() 132 } 133 134 // Emptyf asserts that the specified object is empty. I.e. nil, "", false, 0 or either 135 // a slice or a channel with len == 0. 136 // 137 // assert.Emptyf(t, obj, "error message %s", "formatted") 138 func Emptyf(t TestingT, object interface{}, msg string, args ...interface{}) { 139 if h, ok := t.(tHelper); ok { 140 h.Helper() 141 } 142 if assert.Emptyf(t, object, msg, args...) { 143 return 144 } 145 t.FailNow() 146 } 147 148 // Equal asserts that two objects are equal. 149 // 150 // assert.Equal(t, 123, 123) 151 // 152 // Pointer variable equality is determined based on the equality of the 153 // referenced values (as opposed to the memory addresses). Function equality 154 // cannot be determined and will always fail. 155 func Equal(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { 156 if h, ok := t.(tHelper); ok { 157 h.Helper() 158 } 159 if assert.Equal(t, expected, actual, msgAndArgs...) { 160 return 161 } 162 t.FailNow() 163 } 164 165 // EqualError asserts that a function returned an error (i.e. not `nil`) 166 // and that it is equal to the provided error. 167 // 168 // actualObj, err := SomeFunction() 169 // assert.EqualError(t, err, expectedErrorString) 170 func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) { 171 if h, ok := t.(tHelper); ok { 172 h.Helper() 173 } 174 if assert.EqualError(t, theError, errString, msgAndArgs...) { 175 return 176 } 177 t.FailNow() 178 } 179 180 // EqualErrorf asserts that a function returned an error (i.e. not `nil`) 181 // and that it is equal to the provided error. 182 // 183 // actualObj, err := SomeFunction() 184 // assert.EqualErrorf(t, err, expectedErrorString, "error message %s", "formatted") 185 func EqualErrorf(t TestingT, theError error, errString string, msg string, args ...interface{}) { 186 if h, ok := t.(tHelper); ok { 187 h.Helper() 188 } 189 if assert.EqualErrorf(t, theError, errString, msg, args...) { 190 return 191 } 192 t.FailNow() 193 } 194 195 // EqualExportedValues asserts that the types of two objects are equal and their public 196 // fields are also equal. This is useful for comparing structs that have private fields 197 // that could potentially differ. 198 // 199 // type S struct { 200 // Exported int 201 // notExported int 202 // } 203 // assert.EqualExportedValues(t, S{1, 2}, S{1, 3}) => true 204 // assert.EqualExportedValues(t, S{1, 2}, S{2, 3}) => false 205 func EqualExportedValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { 206 if h, ok := t.(tHelper); ok { 207 h.Helper() 208 } 209 if assert.EqualExportedValues(t, expected, actual, msgAndArgs...) { 210 return 211 } 212 t.FailNow() 213 } 214 215 // EqualExportedValuesf asserts that the types of two objects are equal and their public 216 // fields are also equal. This is useful for comparing structs that have private fields 217 // that could potentially differ. 218 // 219 // type S struct { 220 // Exported int 221 // notExported int 222 // } 223 // assert.EqualExportedValuesf(t, S{1, 2}, S{1, 3}, "error message %s", "formatted") => true 224 // assert.EqualExportedValuesf(t, S{1, 2}, S{2, 3}, "error message %s", "formatted") => false 225 func EqualExportedValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { 226 if h, ok := t.(tHelper); ok { 227 h.Helper() 228 } 229 if assert.EqualExportedValuesf(t, expected, actual, msg, args...) { 230 return 231 } 232 t.FailNow() 233 } 234 235 // EqualValues asserts that two objects are equal or convertible to the same types 236 // and equal. 237 // 238 // assert.EqualValues(t, uint32(123), int32(123)) 239 func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { 240 if h, ok := t.(tHelper); ok { 241 h.Helper() 242 } 243 if assert.EqualValues(t, expected, actual, msgAndArgs...) { 244 return 245 } 246 t.FailNow() 247 } 248 249 // EqualValuesf asserts that two objects are equal or convertible to the same types 250 // and equal. 251 // 252 // assert.EqualValuesf(t, uint32(123), int32(123), "error message %s", "formatted") 253 func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { 254 if h, ok := t.(tHelper); ok { 255 h.Helper() 256 } 257 if assert.EqualValuesf(t, expected, actual, msg, args...) { 258 return 259 } 260 t.FailNow() 261 } 262 263 // Equalf asserts that two objects are equal. 264 // 265 // assert.Equalf(t, 123, 123, "error message %s", "formatted") 266 // 267 // Pointer variable equality is determined based on the equality of the 268 // referenced values (as opposed to the memory addresses). Function equality 269 // cannot be determined and will always fail. 270 func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { 271 if h, ok := t.(tHelper); ok { 272 h.Helper() 273 } 274 if assert.Equalf(t, expected, actual, msg, args...) { 275 return 276 } 277 t.FailNow() 278 } 279 280 // Error asserts that a function returned an error (i.e. not `nil`). 281 // 282 // actualObj, err := SomeFunction() 283 // if assert.Error(t, err) { 284 // assert.Equal(t, expectedError, err) 285 // } 286 func Error(t TestingT, err error, msgAndArgs ...interface{}) { 287 if h, ok := t.(tHelper); ok { 288 h.Helper() 289 } 290 if assert.Error(t, err, msgAndArgs...) { 291 return 292 } 293 t.FailNow() 294 } 295 296 // ErrorAs asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value. 297 // This is a wrapper for errors.As. 298 func ErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{}) { 299 if h, ok := t.(tHelper); ok { 300 h.Helper() 301 } 302 if assert.ErrorAs(t, err, target, msgAndArgs...) { 303 return 304 } 305 t.FailNow() 306 } 307 308 // ErrorAsf asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value. 309 // This is a wrapper for errors.As. 310 func ErrorAsf(t TestingT, err error, target interface{}, msg string, args ...interface{}) { 311 if h, ok := t.(tHelper); ok { 312 h.Helper() 313 } 314 if assert.ErrorAsf(t, err, target, msg, args...) { 315 return 316 } 317 t.FailNow() 318 } 319 320 // ErrorContains asserts that a function returned an error (i.e. not `nil`) 321 // and that the error contains the specified substring. 322 // 323 // actualObj, err := SomeFunction() 324 // assert.ErrorContains(t, err, expectedErrorSubString) 325 func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...interface{}) { 326 if h, ok := t.(tHelper); ok { 327 h.Helper() 328 } 329 if assert.ErrorContains(t, theError, contains, msgAndArgs...) { 330 return 331 } 332 t.FailNow() 333 } 334 335 // ErrorContainsf asserts that a function returned an error (i.e. not `nil`) 336 // and that the error contains the specified substring. 337 // 338 // actualObj, err := SomeFunction() 339 // assert.ErrorContainsf(t, err, expectedErrorSubString, "error message %s", "formatted") 340 func ErrorContainsf(t TestingT, theError error, contains string, msg string, args ...interface{}) { 341 if h, ok := t.(tHelper); ok { 342 h.Helper() 343 } 344 if assert.ErrorContainsf(t, theError, contains, msg, args...) { 345 return 346 } 347 t.FailNow() 348 } 349 350 // ErrorIs asserts that at least one of the errors in err's chain matches target. 351 // This is a wrapper for errors.Is. 352 func ErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) { 353 if h, ok := t.(tHelper); ok { 354 h.Helper() 355 } 356 if assert.ErrorIs(t, err, target, msgAndArgs...) { 357 return 358 } 359 t.FailNow() 360 } 361 362 // ErrorIsf asserts that at least one of the errors in err's chain matches target. 363 // This is a wrapper for errors.Is. 364 func ErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) { 365 if h, ok := t.(tHelper); ok { 366 h.Helper() 367 } 368 if assert.ErrorIsf(t, err, target, msg, args...) { 369 return 370 } 371 t.FailNow() 372 } 373 374 // Errorf asserts that a function returned an error (i.e. not `nil`). 375 // 376 // actualObj, err := SomeFunction() 377 // if assert.Errorf(t, err, "error message %s", "formatted") { 378 // assert.Equal(t, expectedErrorf, err) 379 // } 380 func Errorf(t TestingT, err error, msg string, args ...interface{}) { 381 if h, ok := t.(tHelper); ok { 382 h.Helper() 383 } 384 if assert.Errorf(t, err, msg, args...) { 385 return 386 } 387 t.FailNow() 388 } 389 390 // Eventually asserts that given condition will be met in waitFor time, 391 // periodically checking target function each tick. 392 // 393 // assert.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond) 394 func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) { 395 if h, ok := t.(tHelper); ok { 396 h.Helper() 397 } 398 if assert.Eventually(t, condition, waitFor, tick, msgAndArgs...) { 399 return 400 } 401 t.FailNow() 402 } 403 404 // EventuallyWithT asserts that given condition will be met in waitFor time, 405 // periodically checking target function each tick. In contrast to Eventually, 406 // it supplies a CollectT to the condition function, so that the condition 407 // function can use the CollectT to call other assertions. 408 // The condition is considered "met" if no errors are raised in a tick. 409 // The supplied CollectT collects all errors from one tick (if there are any). 410 // If the condition is not met before waitFor, the collected errors of 411 // the last tick are copied to t. 412 // 413 // externalValue := false 414 // go func() { 415 // time.Sleep(8*time.Second) 416 // externalValue = true 417 // }() 418 // assert.EventuallyWithT(t, func(c *assert.CollectT) { 419 // // add assertions as needed; any assertion failure will fail the current tick 420 // assert.True(c, externalValue, "expected 'externalValue' to be true") 421 // }, 1*time.Second, 10*time.Second, "external state has not changed to 'true'; still false") 422 func EventuallyWithT(t TestingT, condition func(collect *assert.CollectT), waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) { 423 if h, ok := t.(tHelper); ok { 424 h.Helper() 425 } 426 if assert.EventuallyWithT(t, condition, waitFor, tick, msgAndArgs...) { 427 return 428 } 429 t.FailNow() 430 } 431 432 // EventuallyWithTf asserts that given condition will be met in waitFor time, 433 // periodically checking target function each tick. In contrast to Eventually, 434 // it supplies a CollectT to the condition function, so that the condition 435 // function can use the CollectT to call other assertions. 436 // The condition is considered "met" if no errors are raised in a tick. 437 // The supplied CollectT collects all errors from one tick (if there are any). 438 // If the condition is not met before waitFor, the collected errors of 439 // the last tick are copied to t. 440 // 441 // externalValue := false 442 // go func() { 443 // time.Sleep(8*time.Second) 444 // externalValue = true 445 // }() 446 // assert.EventuallyWithTf(t, func(c *assert.CollectT, "error message %s", "formatted") { 447 // // add assertions as needed; any assertion failure will fail the current tick 448 // assert.True(c, externalValue, "expected 'externalValue' to be true") 449 // }, 1*time.Second, 10*time.Second, "external state has not changed to 'true'; still false") 450 func EventuallyWithTf(t TestingT, condition func(collect *assert.CollectT), waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) { 451 if h, ok := t.(tHelper); ok { 452 h.Helper() 453 } 454 if assert.EventuallyWithTf(t, condition, waitFor, tick, msg, args...) { 455 return 456 } 457 t.FailNow() 458 } 459 460 // Eventuallyf asserts that given condition will be met in waitFor time, 461 // periodically checking target function each tick. 462 // 463 // assert.Eventuallyf(t, func() bool { return true; }, time.Second, 10*time.Millisecond, "error message %s", "formatted") 464 func Eventuallyf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) { 465 if h, ok := t.(tHelper); ok { 466 h.Helper() 467 } 468 if assert.Eventuallyf(t, condition, waitFor, tick, msg, args...) { 469 return 470 } 471 t.FailNow() 472 } 473 474 // Exactly asserts that two objects are equal in value and type. 475 // 476 // assert.Exactly(t, int32(123), int64(123)) 477 func Exactly(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { 478 if h, ok := t.(tHelper); ok { 479 h.Helper() 480 } 481 if assert.Exactly(t, expected, actual, msgAndArgs...) { 482 return 483 } 484 t.FailNow() 485 } 486 487 // Exactlyf asserts that two objects are equal in value and type. 488 // 489 // assert.Exactlyf(t, int32(123), int64(123), "error message %s", "formatted") 490 func Exactlyf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { 491 if h, ok := t.(tHelper); ok { 492 h.Helper() 493 } 494 if assert.Exactlyf(t, expected, actual, msg, args...) { 495 return 496 } 497 t.FailNow() 498 } 499 500 // Fail reports a failure through 501 func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) { 502 if h, ok := t.(tHelper); ok { 503 h.Helper() 504 } 505 if assert.Fail(t, failureMessage, msgAndArgs...) { 506 return 507 } 508 t.FailNow() 509 } 510 511 // FailNow fails test 512 func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) { 513 if h, ok := t.(tHelper); ok { 514 h.Helper() 515 } 516 if assert.FailNow(t, failureMessage, msgAndArgs...) { 517 return 518 } 519 t.FailNow() 520 } 521 522 // FailNowf fails test 523 func FailNowf(t TestingT, failureMessage string, msg string, args ...interface{}) { 524 if h, ok := t.(tHelper); ok { 525 h.Helper() 526 } 527 if assert.FailNowf(t, failureMessage, msg, args...) { 528 return 529 } 530 t.FailNow() 531 } 532 533 // Failf reports a failure through 534 func Failf(t TestingT, failureMessage string, msg string, args ...interface{}) { 535 if h, ok := t.(tHelper); ok { 536 h.Helper() 537 } 538 if assert.Failf(t, failureMessage, msg, args...) { 539 return 540 } 541 t.FailNow() 542 } 543 544 // False asserts that the specified value is false. 545 // 546 // assert.False(t, myBool) 547 func False(t TestingT, value bool, msgAndArgs ...interface{}) { 548 if h, ok := t.(tHelper); ok { 549 h.Helper() 550 } 551 if assert.False(t, value, msgAndArgs...) { 552 return 553 } 554 t.FailNow() 555 } 556 557 // Falsef asserts that the specified value is false. 558 // 559 // assert.Falsef(t, myBool, "error message %s", "formatted") 560 func Falsef(t TestingT, value bool, msg string, args ...interface{}) { 561 if h, ok := t.(tHelper); ok { 562 h.Helper() 563 } 564 if assert.Falsef(t, value, msg, args...) { 565 return 566 } 567 t.FailNow() 568 } 569 570 // FileExists checks whether a file exists in the given path. It also fails if 571 // the path points to a directory or there is an error when trying to check the file. 572 func FileExists(t TestingT, path string, msgAndArgs ...interface{}) { 573 if h, ok := t.(tHelper); ok { 574 h.Helper() 575 } 576 if assert.FileExists(t, path, msgAndArgs...) { 577 return 578 } 579 t.FailNow() 580 } 581 582 // FileExistsf checks whether a file exists in the given path. It also fails if 583 // the path points to a directory or there is an error when trying to check the file. 584 func FileExistsf(t TestingT, path string, msg string, args ...interface{}) { 585 if h, ok := t.(tHelper); ok { 586 h.Helper() 587 } 588 if assert.FileExistsf(t, path, msg, args...) { 589 return 590 } 591 t.FailNow() 592 } 593 594 // Greater asserts that the first element is greater than the second 595 // 596 // assert.Greater(t, 2, 1) 597 // assert.Greater(t, float64(2), float64(1)) 598 // assert.Greater(t, "b", "a") 599 func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { 600 if h, ok := t.(tHelper); ok { 601 h.Helper() 602 } 603 if assert.Greater(t, e1, e2, msgAndArgs...) { 604 return 605 } 606 t.FailNow() 607 } 608 609 // GreaterOrEqual asserts that the first element is greater than or equal to the second 610 // 611 // assert.GreaterOrEqual(t, 2, 1) 612 // assert.GreaterOrEqual(t, 2, 2) 613 // assert.GreaterOrEqual(t, "b", "a") 614 // assert.GreaterOrEqual(t, "b", "b") 615 func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { 616 if h, ok := t.(tHelper); ok { 617 h.Helper() 618 } 619 if assert.GreaterOrEqual(t, e1, e2, msgAndArgs...) { 620 return 621 } 622 t.FailNow() 623 } 624 625 // GreaterOrEqualf asserts that the first element is greater than or equal to the second 626 // 627 // assert.GreaterOrEqualf(t, 2, 1, "error message %s", "formatted") 628 // assert.GreaterOrEqualf(t, 2, 2, "error message %s", "formatted") 629 // assert.GreaterOrEqualf(t, "b", "a", "error message %s", "formatted") 630 // assert.GreaterOrEqualf(t, "b", "b", "error message %s", "formatted") 631 func GreaterOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) { 632 if h, ok := t.(tHelper); ok { 633 h.Helper() 634 } 635 if assert.GreaterOrEqualf(t, e1, e2, msg, args...) { 636 return 637 } 638 t.FailNow() 639 } 640 641 // Greaterf asserts that the first element is greater than the second 642 // 643 // assert.Greaterf(t, 2, 1, "error message %s", "formatted") 644 // assert.Greaterf(t, float64(2), float64(1), "error message %s", "formatted") 645 // assert.Greaterf(t, "b", "a", "error message %s", "formatted") 646 func Greaterf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) { 647 if h, ok := t.(tHelper); ok { 648 h.Helper() 649 } 650 if assert.Greaterf(t, e1, e2, msg, args...) { 651 return 652 } 653 t.FailNow() 654 } 655 656 // HTTPBodyContains asserts that a specified handler returns a 657 // body that contains a string. 658 // 659 // assert.HTTPBodyContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") 660 // 661 // Returns whether the assertion was successful (true) or not (false). 662 func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) { 663 if h, ok := t.(tHelper); ok { 664 h.Helper() 665 } 666 if assert.HTTPBodyContains(t, handler, method, url, values, str, msgAndArgs...) { 667 return 668 } 669 t.FailNow() 670 } 671 672 // HTTPBodyContainsf asserts that a specified handler returns a 673 // body that contains a string. 674 // 675 // assert.HTTPBodyContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") 676 // 677 // Returns whether the assertion was successful (true) or not (false). 678 func HTTPBodyContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) { 679 if h, ok := t.(tHelper); ok { 680 h.Helper() 681 } 682 if assert.HTTPBodyContainsf(t, handler, method, url, values, str, msg, args...) { 683 return 684 } 685 t.FailNow() 686 } 687 688 // HTTPBodyNotContains asserts that a specified handler returns a 689 // body that does not contain a string. 690 // 691 // assert.HTTPBodyNotContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") 692 // 693 // Returns whether the assertion was successful (true) or not (false). 694 func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) { 695 if h, ok := t.(tHelper); ok { 696 h.Helper() 697 } 698 if assert.HTTPBodyNotContains(t, handler, method, url, values, str, msgAndArgs...) { 699 return 700 } 701 t.FailNow() 702 } 703 704 // HTTPBodyNotContainsf asserts that a specified handler returns a 705 // body that does not contain a string. 706 // 707 // assert.HTTPBodyNotContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") 708 // 709 // Returns whether the assertion was successful (true) or not (false). 710 func HTTPBodyNotContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) { 711 if h, ok := t.(tHelper); ok { 712 h.Helper() 713 } 714 if assert.HTTPBodyNotContainsf(t, handler, method, url, values, str, msg, args...) { 715 return 716 } 717 t.FailNow() 718 } 719 720 // HTTPError asserts that a specified handler returns an error status code. 721 // 722 // assert.HTTPError(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} 723 // 724 // Returns whether the assertion was successful (true) or not (false). 725 func HTTPError(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { 726 if h, ok := t.(tHelper); ok { 727 h.Helper() 728 } 729 if assert.HTTPError(t, handler, method, url, values, msgAndArgs...) { 730 return 731 } 732 t.FailNow() 733 } 734 735 // HTTPErrorf asserts that a specified handler returns an error status code. 736 // 737 // assert.HTTPErrorf(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} 738 // 739 // Returns whether the assertion was successful (true) or not (false). 740 func HTTPErrorf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { 741 if h, ok := t.(tHelper); ok { 742 h.Helper() 743 } 744 if assert.HTTPErrorf(t, handler, method, url, values, msg, args...) { 745 return 746 } 747 t.FailNow() 748 } 749 750 // HTTPRedirect asserts that a specified handler returns a redirect status code. 751 // 752 // assert.HTTPRedirect(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} 753 // 754 // Returns whether the assertion was successful (true) or not (false). 755 func HTTPRedirect(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { 756 if h, ok := t.(tHelper); ok { 757 h.Helper() 758 } 759 if assert.HTTPRedirect(t, handler, method, url, values, msgAndArgs...) { 760 return 761 } 762 t.FailNow() 763 } 764 765 // HTTPRedirectf asserts that a specified handler returns a redirect status code. 766 // 767 // assert.HTTPRedirectf(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} 768 // 769 // Returns whether the assertion was successful (true) or not (false). 770 func HTTPRedirectf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { 771 if h, ok := t.(tHelper); ok { 772 h.Helper() 773 } 774 if assert.HTTPRedirectf(t, handler, method, url, values, msg, args...) { 775 return 776 } 777 t.FailNow() 778 } 779 780 // HTTPStatusCode asserts that a specified handler returns a specified status code. 781 // 782 // assert.HTTPStatusCode(t, myHandler, "GET", "/notImplemented", nil, 501) 783 // 784 // Returns whether the assertion was successful (true) or not (false). 785 func HTTPStatusCode(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msgAndArgs ...interface{}) { 786 if h, ok := t.(tHelper); ok { 787 h.Helper() 788 } 789 if assert.HTTPStatusCode(t, handler, method, url, values, statuscode, msgAndArgs...) { 790 return 791 } 792 t.FailNow() 793 } 794 795 // HTTPStatusCodef asserts that a specified handler returns a specified status code. 796 // 797 // assert.HTTPStatusCodef(t, myHandler, "GET", "/notImplemented", nil, 501, "error message %s", "formatted") 798 // 799 // Returns whether the assertion was successful (true) or not (false). 800 func HTTPStatusCodef(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msg string, args ...interface{}) { 801 if h, ok := t.(tHelper); ok { 802 h.Helper() 803 } 804 if assert.HTTPStatusCodef(t, handler, method, url, values, statuscode, msg, args...) { 805 return 806 } 807 t.FailNow() 808 } 809 810 // HTTPSuccess asserts that a specified handler returns a success status code. 811 // 812 // assert.HTTPSuccess(t, myHandler, "POST", "http://www.google.com", nil) 813 // 814 // Returns whether the assertion was successful (true) or not (false). 815 func HTTPSuccess(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { 816 if h, ok := t.(tHelper); ok { 817 h.Helper() 818 } 819 if assert.HTTPSuccess(t, handler, method, url, values, msgAndArgs...) { 820 return 821 } 822 t.FailNow() 823 } 824 825 // HTTPSuccessf asserts that a specified handler returns a success status code. 826 // 827 // assert.HTTPSuccessf(t, myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted") 828 // 829 // Returns whether the assertion was successful (true) or not (false). 830 func HTTPSuccessf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { 831 if h, ok := t.(tHelper); ok { 832 h.Helper() 833 } 834 if assert.HTTPSuccessf(t, handler, method, url, values, msg, args...) { 835 return 836 } 837 t.FailNow() 838 } 839 840 // Implements asserts that an object is implemented by the specified interface. 841 // 842 // assert.Implements(t, (*MyInterface)(nil), new(MyObject)) 843 func Implements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) { 844 if h, ok := t.(tHelper); ok { 845 h.Helper() 846 } 847 if assert.Implements(t, interfaceObject, object, msgAndArgs...) { 848 return 849 } 850 t.FailNow() 851 } 852 853 // Implementsf asserts that an object is implemented by the specified interface. 854 // 855 // assert.Implementsf(t, (*MyInterface)(nil), new(MyObject), "error message %s", "formatted") 856 func Implementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) { 857 if h, ok := t.(tHelper); ok { 858 h.Helper() 859 } 860 if assert.Implementsf(t, interfaceObject, object, msg, args...) { 861 return 862 } 863 t.FailNow() 864 } 865 866 // InDelta asserts that the two numerals are within delta of each other. 867 // 868 // assert.InDelta(t, math.Pi, 22/7.0, 0.01) 869 func InDelta(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { 870 if h, ok := t.(tHelper); ok { 871 h.Helper() 872 } 873 if assert.InDelta(t, expected, actual, delta, msgAndArgs...) { 874 return 875 } 876 t.FailNow() 877 } 878 879 // InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys. 880 func InDeltaMapValues(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { 881 if h, ok := t.(tHelper); ok { 882 h.Helper() 883 } 884 if assert.InDeltaMapValues(t, expected, actual, delta, msgAndArgs...) { 885 return 886 } 887 t.FailNow() 888 } 889 890 // InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys. 891 func InDeltaMapValuesf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) { 892 if h, ok := t.(tHelper); ok { 893 h.Helper() 894 } 895 if assert.InDeltaMapValuesf(t, expected, actual, delta, msg, args...) { 896 return 897 } 898 t.FailNow() 899 } 900 901 // InDeltaSlice is the same as InDelta, except it compares two slices. 902 func InDeltaSlice(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { 903 if h, ok := t.(tHelper); ok { 904 h.Helper() 905 } 906 if assert.InDeltaSlice(t, expected, actual, delta, msgAndArgs...) { 907 return 908 } 909 t.FailNow() 910 } 911 912 // InDeltaSlicef is the same as InDelta, except it compares two slices. 913 func InDeltaSlicef(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) { 914 if h, ok := t.(tHelper); ok { 915 h.Helper() 916 } 917 if assert.InDeltaSlicef(t, expected, actual, delta, msg, args...) { 918 return 919 } 920 t.FailNow() 921 } 922 923 // InDeltaf asserts that the two numerals are within delta of each other. 924 // 925 // assert.InDeltaf(t, math.Pi, 22/7.0, 0.01, "error message %s", "formatted") 926 func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) { 927 if h, ok := t.(tHelper); ok { 928 h.Helper() 929 } 930 if assert.InDeltaf(t, expected, actual, delta, msg, args...) { 931 return 932 } 933 t.FailNow() 934 } 935 936 // InEpsilon asserts that expected and actual have a relative error less than epsilon 937 func InEpsilon(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) { 938 if h, ok := t.(tHelper); ok { 939 h.Helper() 940 } 941 if assert.InEpsilon(t, expected, actual, epsilon, msgAndArgs...) { 942 return 943 } 944 t.FailNow() 945 } 946 947 // InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices. 948 func InEpsilonSlice(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) { 949 if h, ok := t.(tHelper); ok { 950 h.Helper() 951 } 952 if assert.InEpsilonSlice(t, expected, actual, epsilon, msgAndArgs...) { 953 return 954 } 955 t.FailNow() 956 } 957 958 // InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices. 959 func InEpsilonSlicef(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) { 960 if h, ok := t.(tHelper); ok { 961 h.Helper() 962 } 963 if assert.InEpsilonSlicef(t, expected, actual, epsilon, msg, args...) { 964 return 965 } 966 t.FailNow() 967 } 968 969 // InEpsilonf asserts that expected and actual have a relative error less than epsilon 970 func InEpsilonf(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) { 971 if h, ok := t.(tHelper); ok { 972 h.Helper() 973 } 974 if assert.InEpsilonf(t, expected, actual, epsilon, msg, args...) { 975 return 976 } 977 t.FailNow() 978 } 979 980 // IsDecreasing asserts that the collection is decreasing 981 // 982 // assert.IsDecreasing(t, []int{2, 1, 0}) 983 // assert.IsDecreasing(t, []float{2, 1}) 984 // assert.IsDecreasing(t, []string{"b", "a"}) 985 func IsDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { 986 if h, ok := t.(tHelper); ok { 987 h.Helper() 988 } 989 if assert.IsDecreasing(t, object, msgAndArgs...) { 990 return 991 } 992 t.FailNow() 993 } 994 995 // IsDecreasingf asserts that the collection is decreasing 996 // 997 // assert.IsDecreasingf(t, []int{2, 1, 0}, "error message %s", "formatted") 998 // assert.IsDecreasingf(t, []float{2, 1}, "error message %s", "formatted") 999 // assert.IsDecreasingf(t, []string{"b", "a"}, "error message %s", "formatted") 1000 func IsDecreasingf(t TestingT, object interface{}, msg string, args ...interface{}) { 1001 if h, ok := t.(tHelper); ok { 1002 h.Helper() 1003 } 1004 if assert.IsDecreasingf(t, object, msg, args...) { 1005 return 1006 } 1007 t.FailNow() 1008 } 1009 1010 // IsIncreasing asserts that the collection is increasing 1011 // 1012 // assert.IsIncreasing(t, []int{1, 2, 3}) 1013 // assert.IsIncreasing(t, []float{1, 2}) 1014 // assert.IsIncreasing(t, []string{"a", "b"}) 1015 func IsIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { 1016 if h, ok := t.(tHelper); ok { 1017 h.Helper() 1018 } 1019 if assert.IsIncreasing(t, object, msgAndArgs...) { 1020 return 1021 } 1022 t.FailNow() 1023 } 1024 1025 // IsIncreasingf asserts that the collection is increasing 1026 // 1027 // assert.IsIncreasingf(t, []int{1, 2, 3}, "error message %s", "formatted") 1028 // assert.IsIncreasingf(t, []float{1, 2}, "error message %s", "formatted") 1029 // assert.IsIncreasingf(t, []string{"a", "b"}, "error message %s", "formatted") 1030 func IsIncreasingf(t TestingT, object interface{}, msg string, args ...interface{}) { 1031 if h, ok := t.(tHelper); ok { 1032 h.Helper() 1033 } 1034 if assert.IsIncreasingf(t, object, msg, args...) { 1035 return 1036 } 1037 t.FailNow() 1038 } 1039 1040 // IsNonDecreasing asserts that the collection is not decreasing 1041 // 1042 // assert.IsNonDecreasing(t, []int{1, 1, 2}) 1043 // assert.IsNonDecreasing(t, []float{1, 2}) 1044 // assert.IsNonDecreasing(t, []string{"a", "b"}) 1045 func IsNonDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { 1046 if h, ok := t.(tHelper); ok { 1047 h.Helper() 1048 } 1049 if assert.IsNonDecreasing(t, object, msgAndArgs...) { 1050 return 1051 } 1052 t.FailNow() 1053 } 1054 1055 // IsNonDecreasingf asserts that the collection is not decreasing 1056 // 1057 // assert.IsNonDecreasingf(t, []int{1, 1, 2}, "error message %s", "formatted") 1058 // assert.IsNonDecreasingf(t, []float{1, 2}, "error message %s", "formatted") 1059 // assert.IsNonDecreasingf(t, []string{"a", "b"}, "error message %s", "formatted") 1060 func IsNonDecreasingf(t TestingT, object interface{}, msg string, args ...interface{}) { 1061 if h, ok := t.(tHelper); ok { 1062 h.Helper() 1063 } 1064 if assert.IsNonDecreasingf(t, object, msg, args...) { 1065 return 1066 } 1067 t.FailNow() 1068 } 1069 1070 // IsNonIncreasing asserts that the collection is not increasing 1071 // 1072 // assert.IsNonIncreasing(t, []int{2, 1, 1}) 1073 // assert.IsNonIncreasing(t, []float{2, 1}) 1074 // assert.IsNonIncreasing(t, []string{"b", "a"}) 1075 func IsNonIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) { 1076 if h, ok := t.(tHelper); ok { 1077 h.Helper() 1078 } 1079 if assert.IsNonIncreasing(t, object, msgAndArgs...) { 1080 return 1081 } 1082 t.FailNow() 1083 } 1084 1085 // IsNonIncreasingf asserts that the collection is not increasing 1086 // 1087 // assert.IsNonIncreasingf(t, []int{2, 1, 1}, "error message %s", "formatted") 1088 // assert.IsNonIncreasingf(t, []float{2, 1}, "error message %s", "formatted") 1089 // assert.IsNonIncreasingf(t, []string{"b", "a"}, "error message %s", "formatted") 1090 func IsNonIncreasingf(t TestingT, object interface{}, msg string, args ...interface{}) { 1091 if h, ok := t.(tHelper); ok { 1092 h.Helper() 1093 } 1094 if assert.IsNonIncreasingf(t, object, msg, args...) { 1095 return 1096 } 1097 t.FailNow() 1098 } 1099 1100 // IsType asserts that the specified objects are of the same type. 1101 func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) { 1102 if h, ok := t.(tHelper); ok { 1103 h.Helper() 1104 } 1105 if assert.IsType(t, expectedType, object, msgAndArgs...) { 1106 return 1107 } 1108 t.FailNow() 1109 } 1110 1111 // IsTypef asserts that the specified objects are of the same type. 1112 func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, args ...interface{}) { 1113 if h, ok := t.(tHelper); ok { 1114 h.Helper() 1115 } 1116 if assert.IsTypef(t, expectedType, object, msg, args...) { 1117 return 1118 } 1119 t.FailNow() 1120 } 1121 1122 // JSONEq asserts that two JSON strings are equivalent. 1123 // 1124 // assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`) 1125 func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) { 1126 if h, ok := t.(tHelper); ok { 1127 h.Helper() 1128 } 1129 if assert.JSONEq(t, expected, actual, msgAndArgs...) { 1130 return 1131 } 1132 t.FailNow() 1133 } 1134 1135 // JSONEqf asserts that two JSON strings are equivalent. 1136 // 1137 // assert.JSONEqf(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted") 1138 func JSONEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) { 1139 if h, ok := t.(tHelper); ok { 1140 h.Helper() 1141 } 1142 if assert.JSONEqf(t, expected, actual, msg, args...) { 1143 return 1144 } 1145 t.FailNow() 1146 } 1147 1148 // Len asserts that the specified object has specific length. 1149 // Len also fails if the object has a type that len() not accept. 1150 // 1151 // assert.Len(t, mySlice, 3) 1152 func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) { 1153 if h, ok := t.(tHelper); ok { 1154 h.Helper() 1155 } 1156 if assert.Len(t, object, length, msgAndArgs...) { 1157 return 1158 } 1159 t.FailNow() 1160 } 1161 1162 // Lenf asserts that the specified object has specific length. 1163 // Lenf also fails if the object has a type that len() not accept. 1164 // 1165 // assert.Lenf(t, mySlice, 3, "error message %s", "formatted") 1166 func Lenf(t TestingT, object interface{}, length int, msg string, args ...interface{}) { 1167 if h, ok := t.(tHelper); ok { 1168 h.Helper() 1169 } 1170 if assert.Lenf(t, object, length, msg, args...) { 1171 return 1172 } 1173 t.FailNow() 1174 } 1175 1176 // Less asserts that the first element is less than the second 1177 // 1178 // assert.Less(t, 1, 2) 1179 // assert.Less(t, float64(1), float64(2)) 1180 // assert.Less(t, "a", "b") 1181 func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { 1182 if h, ok := t.(tHelper); ok { 1183 h.Helper() 1184 } 1185 if assert.Less(t, e1, e2, msgAndArgs...) { 1186 return 1187 } 1188 t.FailNow() 1189 } 1190 1191 // LessOrEqual asserts that the first element is less than or equal to the second 1192 // 1193 // assert.LessOrEqual(t, 1, 2) 1194 // assert.LessOrEqual(t, 2, 2) 1195 // assert.LessOrEqual(t, "a", "b") 1196 // assert.LessOrEqual(t, "b", "b") 1197 func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { 1198 if h, ok := t.(tHelper); ok { 1199 h.Helper() 1200 } 1201 if assert.LessOrEqual(t, e1, e2, msgAndArgs...) { 1202 return 1203 } 1204 t.FailNow() 1205 } 1206 1207 // LessOrEqualf asserts that the first element is less than or equal to the second 1208 // 1209 // assert.LessOrEqualf(t, 1, 2, "error message %s", "formatted") 1210 // assert.LessOrEqualf(t, 2, 2, "error message %s", "formatted") 1211 // assert.LessOrEqualf(t, "a", "b", "error message %s", "formatted") 1212 // assert.LessOrEqualf(t, "b", "b", "error message %s", "formatted") 1213 func LessOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) { 1214 if h, ok := t.(tHelper); ok { 1215 h.Helper() 1216 } 1217 if assert.LessOrEqualf(t, e1, e2, msg, args...) { 1218 return 1219 } 1220 t.FailNow() 1221 } 1222 1223 // Lessf asserts that the first element is less than the second 1224 // 1225 // assert.Lessf(t, 1, 2, "error message %s", "formatted") 1226 // assert.Lessf(t, float64(1), float64(2), "error message %s", "formatted") 1227 // assert.Lessf(t, "a", "b", "error message %s", "formatted") 1228 func Lessf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) { 1229 if h, ok := t.(tHelper); ok { 1230 h.Helper() 1231 } 1232 if assert.Lessf(t, e1, e2, msg, args...) { 1233 return 1234 } 1235 t.FailNow() 1236 } 1237 1238 // Negative asserts that the specified element is negative 1239 // 1240 // assert.Negative(t, -1) 1241 // assert.Negative(t, -1.23) 1242 func Negative(t TestingT, e interface{}, msgAndArgs ...interface{}) { 1243 if h, ok := t.(tHelper); ok { 1244 h.Helper() 1245 } 1246 if assert.Negative(t, e, msgAndArgs...) { 1247 return 1248 } 1249 t.FailNow() 1250 } 1251 1252 // Negativef asserts that the specified element is negative 1253 // 1254 // assert.Negativef(t, -1, "error message %s", "formatted") 1255 // assert.Negativef(t, -1.23, "error message %s", "formatted") 1256 func Negativef(t TestingT, e interface{}, msg string, args ...interface{}) { 1257 if h, ok := t.(tHelper); ok { 1258 h.Helper() 1259 } 1260 if assert.Negativef(t, e, msg, args...) { 1261 return 1262 } 1263 t.FailNow() 1264 } 1265 1266 // Never asserts that the given condition doesn't satisfy in waitFor time, 1267 // periodically checking the target function each tick. 1268 // 1269 // assert.Never(t, func() bool { return false; }, time.Second, 10*time.Millisecond) 1270 func Never(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) { 1271 if h, ok := t.(tHelper); ok { 1272 h.Helper() 1273 } 1274 if assert.Never(t, condition, waitFor, tick, msgAndArgs...) { 1275 return 1276 } 1277 t.FailNow() 1278 } 1279 1280 // Neverf asserts that the given condition doesn't satisfy in waitFor time, 1281 // periodically checking the target function each tick. 1282 // 1283 // assert.Neverf(t, func() bool { return false; }, time.Second, 10*time.Millisecond, "error message %s", "formatted") 1284 func Neverf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) { 1285 if h, ok := t.(tHelper); ok { 1286 h.Helper() 1287 } 1288 if assert.Neverf(t, condition, waitFor, tick, msg, args...) { 1289 return 1290 } 1291 t.FailNow() 1292 } 1293 1294 // Nil asserts that the specified object is nil. 1295 // 1296 // assert.Nil(t, err) 1297 func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) { 1298 if h, ok := t.(tHelper); ok { 1299 h.Helper() 1300 } 1301 if assert.Nil(t, object, msgAndArgs...) { 1302 return 1303 } 1304 t.FailNow() 1305 } 1306 1307 // Nilf asserts that the specified object is nil. 1308 // 1309 // assert.Nilf(t, err, "error message %s", "formatted") 1310 func Nilf(t TestingT, object interface{}, msg string, args ...interface{}) { 1311 if h, ok := t.(tHelper); ok { 1312 h.Helper() 1313 } 1314 if assert.Nilf(t, object, msg, args...) { 1315 return 1316 } 1317 t.FailNow() 1318 } 1319 1320 // NoDirExists checks whether a directory does not exist in the given path. 1321 // It fails if the path points to an existing _directory_ only. 1322 func NoDirExists(t TestingT, path string, msgAndArgs ...interface{}) { 1323 if h, ok := t.(tHelper); ok { 1324 h.Helper() 1325 } 1326 if assert.NoDirExists(t, path, msgAndArgs...) { 1327 return 1328 } 1329 t.FailNow() 1330 } 1331 1332 // NoDirExistsf checks whether a directory does not exist in the given path. 1333 // It fails if the path points to an existing _directory_ only. 1334 func NoDirExistsf(t TestingT, path string, msg string, args ...interface{}) { 1335 if h, ok := t.(tHelper); ok { 1336 h.Helper() 1337 } 1338 if assert.NoDirExistsf(t, path, msg, args...) { 1339 return 1340 } 1341 t.FailNow() 1342 } 1343 1344 // NoError asserts that a function returned no error (i.e. `nil`). 1345 // 1346 // actualObj, err := SomeFunction() 1347 // if assert.NoError(t, err) { 1348 // assert.Equal(t, expectedObj, actualObj) 1349 // } 1350 func NoError(t TestingT, err error, msgAndArgs ...interface{}) { 1351 if h, ok := t.(tHelper); ok { 1352 h.Helper() 1353 } 1354 if assert.NoError(t, err, msgAndArgs...) { 1355 return 1356 } 1357 t.FailNow() 1358 } 1359 1360 // NoErrorf asserts that a function returned no error (i.e. `nil`). 1361 // 1362 // actualObj, err := SomeFunction() 1363 // if assert.NoErrorf(t, err, "error message %s", "formatted") { 1364 // assert.Equal(t, expectedObj, actualObj) 1365 // } 1366 func NoErrorf(t TestingT, err error, msg string, args ...interface{}) { 1367 if h, ok := t.(tHelper); ok { 1368 h.Helper() 1369 } 1370 if assert.NoErrorf(t, err, msg, args...) { 1371 return 1372 } 1373 t.FailNow() 1374 } 1375 1376 // NoFileExists checks whether a file does not exist in a given path. It fails 1377 // if the path points to an existing _file_ only. 1378 func NoFileExists(t TestingT, path string, msgAndArgs ...interface{}) { 1379 if h, ok := t.(tHelper); ok { 1380 h.Helper() 1381 } 1382 if assert.NoFileExists(t, path, msgAndArgs...) { 1383 return 1384 } 1385 t.FailNow() 1386 } 1387 1388 // NoFileExistsf checks whether a file does not exist in a given path. It fails 1389 // if the path points to an existing _file_ only. 1390 func NoFileExistsf(t TestingT, path string, msg string, args ...interface{}) { 1391 if h, ok := t.(tHelper); ok { 1392 h.Helper() 1393 } 1394 if assert.NoFileExistsf(t, path, msg, args...) { 1395 return 1396 } 1397 t.FailNow() 1398 } 1399 1400 // NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the 1401 // specified substring or element. 1402 // 1403 // assert.NotContains(t, "Hello World", "Earth") 1404 // assert.NotContains(t, ["Hello", "World"], "Earth") 1405 // assert.NotContains(t, {"Hello": "World"}, "Earth") 1406 func NotContains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) { 1407 if h, ok := t.(tHelper); ok { 1408 h.Helper() 1409 } 1410 if assert.NotContains(t, s, contains, msgAndArgs...) { 1411 return 1412 } 1413 t.FailNow() 1414 } 1415 1416 // NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the 1417 // specified substring or element. 1418 // 1419 // assert.NotContainsf(t, "Hello World", "Earth", "error message %s", "formatted") 1420 // assert.NotContainsf(t, ["Hello", "World"], "Earth", "error message %s", "formatted") 1421 // assert.NotContainsf(t, {"Hello": "World"}, "Earth", "error message %s", "formatted") 1422 func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) { 1423 if h, ok := t.(tHelper); ok { 1424 h.Helper() 1425 } 1426 if assert.NotContainsf(t, s, contains, msg, args...) { 1427 return 1428 } 1429 t.FailNow() 1430 } 1431 1432 // NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either 1433 // a slice or a channel with len == 0. 1434 // 1435 // if assert.NotEmpty(t, obj) { 1436 // assert.Equal(t, "two", obj[1]) 1437 // } 1438 func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) { 1439 if h, ok := t.(tHelper); ok { 1440 h.Helper() 1441 } 1442 if assert.NotEmpty(t, object, msgAndArgs...) { 1443 return 1444 } 1445 t.FailNow() 1446 } 1447 1448 // NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either 1449 // a slice or a channel with len == 0. 1450 // 1451 // if assert.NotEmptyf(t, obj, "error message %s", "formatted") { 1452 // assert.Equal(t, "two", obj[1]) 1453 // } 1454 func NotEmptyf(t TestingT, object interface{}, msg string, args ...interface{}) { 1455 if h, ok := t.(tHelper); ok { 1456 h.Helper() 1457 } 1458 if assert.NotEmptyf(t, object, msg, args...) { 1459 return 1460 } 1461 t.FailNow() 1462 } 1463 1464 // NotEqual asserts that the specified values are NOT equal. 1465 // 1466 // assert.NotEqual(t, obj1, obj2) 1467 // 1468 // Pointer variable equality is determined based on the equality of the 1469 // referenced values (as opposed to the memory addresses). 1470 func NotEqual(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { 1471 if h, ok := t.(tHelper); ok { 1472 h.Helper() 1473 } 1474 if assert.NotEqual(t, expected, actual, msgAndArgs...) { 1475 return 1476 } 1477 t.FailNow() 1478 } 1479 1480 // NotEqualValues asserts that two objects are not equal even when converted to the same type 1481 // 1482 // assert.NotEqualValues(t, obj1, obj2) 1483 func NotEqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { 1484 if h, ok := t.(tHelper); ok { 1485 h.Helper() 1486 } 1487 if assert.NotEqualValues(t, expected, actual, msgAndArgs...) { 1488 return 1489 } 1490 t.FailNow() 1491 } 1492 1493 // NotEqualValuesf asserts that two objects are not equal even when converted to the same type 1494 // 1495 // assert.NotEqualValuesf(t, obj1, obj2, "error message %s", "formatted") 1496 func NotEqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { 1497 if h, ok := t.(tHelper); ok { 1498 h.Helper() 1499 } 1500 if assert.NotEqualValuesf(t, expected, actual, msg, args...) { 1501 return 1502 } 1503 t.FailNow() 1504 } 1505 1506 // NotEqualf asserts that the specified values are NOT equal. 1507 // 1508 // assert.NotEqualf(t, obj1, obj2, "error message %s", "formatted") 1509 // 1510 // Pointer variable equality is determined based on the equality of the 1511 // referenced values (as opposed to the memory addresses). 1512 func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { 1513 if h, ok := t.(tHelper); ok { 1514 h.Helper() 1515 } 1516 if assert.NotEqualf(t, expected, actual, msg, args...) { 1517 return 1518 } 1519 t.FailNow() 1520 } 1521 1522 // NotErrorIs asserts that at none of the errors in err's chain matches target. 1523 // This is a wrapper for errors.Is. 1524 func NotErrorIs(t TestingT, err error, target error, msgAndArgs ...interface{}) { 1525 if h, ok := t.(tHelper); ok { 1526 h.Helper() 1527 } 1528 if assert.NotErrorIs(t, err, target, msgAndArgs...) { 1529 return 1530 } 1531 t.FailNow() 1532 } 1533 1534 // NotErrorIsf asserts that at none of the errors in err's chain matches target. 1535 // This is a wrapper for errors.Is. 1536 func NotErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) { 1537 if h, ok := t.(tHelper); ok { 1538 h.Helper() 1539 } 1540 if assert.NotErrorIsf(t, err, target, msg, args...) { 1541 return 1542 } 1543 t.FailNow() 1544 } 1545 1546 // NotImplements asserts that an object does not implement the specified interface. 1547 // 1548 // assert.NotImplements(t, (*MyInterface)(nil), new(MyObject)) 1549 func NotImplements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) { 1550 if h, ok := t.(tHelper); ok { 1551 h.Helper() 1552 } 1553 if assert.NotImplements(t, interfaceObject, object, msgAndArgs...) { 1554 return 1555 } 1556 t.FailNow() 1557 } 1558 1559 // NotImplementsf asserts that an object does not implement the specified interface. 1560 // 1561 // assert.NotImplementsf(t, (*MyInterface)(nil), new(MyObject), "error message %s", "formatted") 1562 func NotImplementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) { 1563 if h, ok := t.(tHelper); ok { 1564 h.Helper() 1565 } 1566 if assert.NotImplementsf(t, interfaceObject, object, msg, args...) { 1567 return 1568 } 1569 t.FailNow() 1570 } 1571 1572 // NotNil asserts that the specified object is not nil. 1573 // 1574 // assert.NotNil(t, err) 1575 func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) { 1576 if h, ok := t.(tHelper); ok { 1577 h.Helper() 1578 } 1579 if assert.NotNil(t, object, msgAndArgs...) { 1580 return 1581 } 1582 t.FailNow() 1583 } 1584 1585 // NotNilf asserts that the specified object is not nil. 1586 // 1587 // assert.NotNilf(t, err, "error message %s", "formatted") 1588 func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) { 1589 if h, ok := t.(tHelper); ok { 1590 h.Helper() 1591 } 1592 if assert.NotNilf(t, object, msg, args...) { 1593 return 1594 } 1595 t.FailNow() 1596 } 1597 1598 // NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic. 1599 // 1600 // assert.NotPanics(t, func(){ RemainCalm() }) 1601 func NotPanics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) { 1602 if h, ok := t.(tHelper); ok { 1603 h.Helper() 1604 } 1605 if assert.NotPanics(t, f, msgAndArgs...) { 1606 return 1607 } 1608 t.FailNow() 1609 } 1610 1611 // NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic. 1612 // 1613 // assert.NotPanicsf(t, func(){ RemainCalm() }, "error message %s", "formatted") 1614 func NotPanicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{}) { 1615 if h, ok := t.(tHelper); ok { 1616 h.Helper() 1617 } 1618 if assert.NotPanicsf(t, f, msg, args...) { 1619 return 1620 } 1621 t.FailNow() 1622 } 1623 1624 // NotRegexp asserts that a specified regexp does not match a string. 1625 // 1626 // assert.NotRegexp(t, regexp.MustCompile("starts"), "it's starting") 1627 // assert.NotRegexp(t, "^start", "it's not starting") 1628 func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) { 1629 if h, ok := t.(tHelper); ok { 1630 h.Helper() 1631 } 1632 if assert.NotRegexp(t, rx, str, msgAndArgs...) { 1633 return 1634 } 1635 t.FailNow() 1636 } 1637 1638 // NotRegexpf asserts that a specified regexp does not match a string. 1639 // 1640 // assert.NotRegexpf(t, regexp.MustCompile("starts"), "it's starting", "error message %s", "formatted") 1641 // assert.NotRegexpf(t, "^start", "it's not starting", "error message %s", "formatted") 1642 func NotRegexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) { 1643 if h, ok := t.(tHelper); ok { 1644 h.Helper() 1645 } 1646 if assert.NotRegexpf(t, rx, str, msg, args...) { 1647 return 1648 } 1649 t.FailNow() 1650 } 1651 1652 // NotSame asserts that two pointers do not reference the same object. 1653 // 1654 // assert.NotSame(t, ptr1, ptr2) 1655 // 1656 // Both arguments must be pointer variables. Pointer variable sameness is 1657 // determined based on the equality of both type and value. 1658 func NotSame(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { 1659 if h, ok := t.(tHelper); ok { 1660 h.Helper() 1661 } 1662 if assert.NotSame(t, expected, actual, msgAndArgs...) { 1663 return 1664 } 1665 t.FailNow() 1666 } 1667 1668 // NotSamef asserts that two pointers do not reference the same object. 1669 // 1670 // assert.NotSamef(t, ptr1, ptr2, "error message %s", "formatted") 1671 // 1672 // Both arguments must be pointer variables. Pointer variable sameness is 1673 // determined based on the equality of both type and value. 1674 func NotSamef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { 1675 if h, ok := t.(tHelper); ok { 1676 h.Helper() 1677 } 1678 if assert.NotSamef(t, expected, actual, msg, args...) { 1679 return 1680 } 1681 t.FailNow() 1682 } 1683 1684 // NotSubset asserts that the specified list(array, slice...) or map does NOT 1685 // contain all elements given in the specified subset list(array, slice...) or 1686 // map. 1687 // 1688 // assert.NotSubset(t, [1, 3, 4], [1, 2]) 1689 // assert.NotSubset(t, {"x": 1, "y": 2}, {"z": 3}) 1690 func NotSubset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) { 1691 if h, ok := t.(tHelper); ok { 1692 h.Helper() 1693 } 1694 if assert.NotSubset(t, list, subset, msgAndArgs...) { 1695 return 1696 } 1697 t.FailNow() 1698 } 1699 1700 // NotSubsetf asserts that the specified list(array, slice...) or map does NOT 1701 // contain all elements given in the specified subset list(array, slice...) or 1702 // map. 1703 // 1704 // assert.NotSubsetf(t, [1, 3, 4], [1, 2], "error message %s", "formatted") 1705 // assert.NotSubsetf(t, {"x": 1, "y": 2}, {"z": 3}, "error message %s", "formatted") 1706 func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) { 1707 if h, ok := t.(tHelper); ok { 1708 h.Helper() 1709 } 1710 if assert.NotSubsetf(t, list, subset, msg, args...) { 1711 return 1712 } 1713 t.FailNow() 1714 } 1715 1716 // NotZero asserts that i is not the zero value for its type. 1717 func NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) { 1718 if h, ok := t.(tHelper); ok { 1719 h.Helper() 1720 } 1721 if assert.NotZero(t, i, msgAndArgs...) { 1722 return 1723 } 1724 t.FailNow() 1725 } 1726 1727 // NotZerof asserts that i is not the zero value for its type. 1728 func NotZerof(t TestingT, i interface{}, msg string, args ...interface{}) { 1729 if h, ok := t.(tHelper); ok { 1730 h.Helper() 1731 } 1732 if assert.NotZerof(t, i, msg, args...) { 1733 return 1734 } 1735 t.FailNow() 1736 } 1737 1738 // Panics asserts that the code inside the specified PanicTestFunc panics. 1739 // 1740 // assert.Panics(t, func(){ GoCrazy() }) 1741 func Panics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) { 1742 if h, ok := t.(tHelper); ok { 1743 h.Helper() 1744 } 1745 if assert.Panics(t, f, msgAndArgs...) { 1746 return 1747 } 1748 t.FailNow() 1749 } 1750 1751 // PanicsWithError asserts that the code inside the specified PanicTestFunc 1752 // panics, and that the recovered panic value is an error that satisfies the 1753 // EqualError comparison. 1754 // 1755 // assert.PanicsWithError(t, "crazy error", func(){ GoCrazy() }) 1756 func PanicsWithError(t TestingT, errString string, f assert.PanicTestFunc, msgAndArgs ...interface{}) { 1757 if h, ok := t.(tHelper); ok { 1758 h.Helper() 1759 } 1760 if assert.PanicsWithError(t, errString, f, msgAndArgs...) { 1761 return 1762 } 1763 t.FailNow() 1764 } 1765 1766 // PanicsWithErrorf asserts that the code inside the specified PanicTestFunc 1767 // panics, and that the recovered panic value is an error that satisfies the 1768 // EqualError comparison. 1769 // 1770 // assert.PanicsWithErrorf(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted") 1771 func PanicsWithErrorf(t TestingT, errString string, f assert.PanicTestFunc, msg string, args ...interface{}) { 1772 if h, ok := t.(tHelper); ok { 1773 h.Helper() 1774 } 1775 if assert.PanicsWithErrorf(t, errString, f, msg, args...) { 1776 return 1777 } 1778 t.FailNow() 1779 } 1780 1781 // PanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that 1782 // the recovered panic value equals the expected panic value. 1783 // 1784 // assert.PanicsWithValue(t, "crazy error", func(){ GoCrazy() }) 1785 func PanicsWithValue(t TestingT, expected interface{}, f assert.PanicTestFunc, msgAndArgs ...interface{}) { 1786 if h, ok := t.(tHelper); ok { 1787 h.Helper() 1788 } 1789 if assert.PanicsWithValue(t, expected, f, msgAndArgs...) { 1790 return 1791 } 1792 t.FailNow() 1793 } 1794 1795 // PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that 1796 // the recovered panic value equals the expected panic value. 1797 // 1798 // assert.PanicsWithValuef(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted") 1799 func PanicsWithValuef(t TestingT, expected interface{}, f assert.PanicTestFunc, msg string, args ...interface{}) { 1800 if h, ok := t.(tHelper); ok { 1801 h.Helper() 1802 } 1803 if assert.PanicsWithValuef(t, expected, f, msg, args...) { 1804 return 1805 } 1806 t.FailNow() 1807 } 1808 1809 // Panicsf asserts that the code inside the specified PanicTestFunc panics. 1810 // 1811 // assert.Panicsf(t, func(){ GoCrazy() }, "error message %s", "formatted") 1812 func Panicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{}) { 1813 if h, ok := t.(tHelper); ok { 1814 h.Helper() 1815 } 1816 if assert.Panicsf(t, f, msg, args...) { 1817 return 1818 } 1819 t.FailNow() 1820 } 1821 1822 // Positive asserts that the specified element is positive 1823 // 1824 // assert.Positive(t, 1) 1825 // assert.Positive(t, 1.23) 1826 func Positive(t TestingT, e interface{}, msgAndArgs ...interface{}) { 1827 if h, ok := t.(tHelper); ok { 1828 h.Helper() 1829 } 1830 if assert.Positive(t, e, msgAndArgs...) { 1831 return 1832 } 1833 t.FailNow() 1834 } 1835 1836 // Positivef asserts that the specified element is positive 1837 // 1838 // assert.Positivef(t, 1, "error message %s", "formatted") 1839 // assert.Positivef(t, 1.23, "error message %s", "formatted") 1840 func Positivef(t TestingT, e interface{}, msg string, args ...interface{}) { 1841 if h, ok := t.(tHelper); ok { 1842 h.Helper() 1843 } 1844 if assert.Positivef(t, e, msg, args...) { 1845 return 1846 } 1847 t.FailNow() 1848 } 1849 1850 // Regexp asserts that a specified regexp matches a string. 1851 // 1852 // assert.Regexp(t, regexp.MustCompile("start"), "it's starting") 1853 // assert.Regexp(t, "start...$", "it's not starting") 1854 func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) { 1855 if h, ok := t.(tHelper); ok { 1856 h.Helper() 1857 } 1858 if assert.Regexp(t, rx, str, msgAndArgs...) { 1859 return 1860 } 1861 t.FailNow() 1862 } 1863 1864 // Regexpf asserts that a specified regexp matches a string. 1865 // 1866 // assert.Regexpf(t, regexp.MustCompile("start"), "it's starting", "error message %s", "formatted") 1867 // assert.Regexpf(t, "start...$", "it's not starting", "error message %s", "formatted") 1868 func Regexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) { 1869 if h, ok := t.(tHelper); ok { 1870 h.Helper() 1871 } 1872 if assert.Regexpf(t, rx, str, msg, args...) { 1873 return 1874 } 1875 t.FailNow() 1876 } 1877 1878 // Same asserts that two pointers reference the same object. 1879 // 1880 // assert.Same(t, ptr1, ptr2) 1881 // 1882 // Both arguments must be pointer variables. Pointer variable sameness is 1883 // determined based on the equality of both type and value. 1884 func Same(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { 1885 if h, ok := t.(tHelper); ok { 1886 h.Helper() 1887 } 1888 if assert.Same(t, expected, actual, msgAndArgs...) { 1889 return 1890 } 1891 t.FailNow() 1892 } 1893 1894 // Samef asserts that two pointers reference the same object. 1895 // 1896 // assert.Samef(t, ptr1, ptr2, "error message %s", "formatted") 1897 // 1898 // Both arguments must be pointer variables. Pointer variable sameness is 1899 // determined based on the equality of both type and value. 1900 func Samef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { 1901 if h, ok := t.(tHelper); ok { 1902 h.Helper() 1903 } 1904 if assert.Samef(t, expected, actual, msg, args...) { 1905 return 1906 } 1907 t.FailNow() 1908 } 1909 1910 // Subset asserts that the specified list(array, slice...) or map contains all 1911 // elements given in the specified subset list(array, slice...) or map. 1912 // 1913 // assert.Subset(t, [1, 2, 3], [1, 2]) 1914 // assert.Subset(t, {"x": 1, "y": 2}, {"x": 1}) 1915 func Subset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) { 1916 if h, ok := t.(tHelper); ok { 1917 h.Helper() 1918 } 1919 if assert.Subset(t, list, subset, msgAndArgs...) { 1920 return 1921 } 1922 t.FailNow() 1923 } 1924 1925 // Subsetf asserts that the specified list(array, slice...) or map contains all 1926 // elements given in the specified subset list(array, slice...) or map. 1927 // 1928 // assert.Subsetf(t, [1, 2, 3], [1, 2], "error message %s", "formatted") 1929 // assert.Subsetf(t, {"x": 1, "y": 2}, {"x": 1}, "error message %s", "formatted") 1930 func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) { 1931 if h, ok := t.(tHelper); ok { 1932 h.Helper() 1933 } 1934 if assert.Subsetf(t, list, subset, msg, args...) { 1935 return 1936 } 1937 t.FailNow() 1938 } 1939 1940 // True asserts that the specified value is true. 1941 // 1942 // assert.True(t, myBool) 1943 func True(t TestingT, value bool, msgAndArgs ...interface{}) { 1944 if h, ok := t.(tHelper); ok { 1945 h.Helper() 1946 } 1947 if assert.True(t, value, msgAndArgs...) { 1948 return 1949 } 1950 t.FailNow() 1951 } 1952 1953 // Truef asserts that the specified value is true. 1954 // 1955 // assert.Truef(t, myBool, "error message %s", "formatted") 1956 func Truef(t TestingT, value bool, msg string, args ...interface{}) { 1957 if h, ok := t.(tHelper); ok { 1958 h.Helper() 1959 } 1960 if assert.Truef(t, value, msg, args...) { 1961 return 1962 } 1963 t.FailNow() 1964 } 1965 1966 // WithinDuration asserts that the two times are within duration delta of each other. 1967 // 1968 // assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second) 1969 func WithinDuration(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) { 1970 if h, ok := t.(tHelper); ok { 1971 h.Helper() 1972 } 1973 if assert.WithinDuration(t, expected, actual, delta, msgAndArgs...) { 1974 return 1975 } 1976 t.FailNow() 1977 } 1978 1979 // WithinDurationf asserts that the two times are within duration delta of each other. 1980 // 1981 // assert.WithinDurationf(t, time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted") 1982 func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) { 1983 if h, ok := t.(tHelper); ok { 1984 h.Helper() 1985 } 1986 if assert.WithinDurationf(t, expected, actual, delta, msg, args...) { 1987 return 1988 } 1989 t.FailNow() 1990 } 1991 1992 // WithinRange asserts that a time is within a time range (inclusive). 1993 // 1994 // assert.WithinRange(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second)) 1995 func WithinRange(t TestingT, actual time.Time, start time.Time, end time.Time, msgAndArgs ...interface{}) { 1996 if h, ok := t.(tHelper); ok { 1997 h.Helper() 1998 } 1999 if assert.WithinRange(t, actual, start, end, msgAndArgs...) { 2000 return 2001 } 2002 t.FailNow() 2003 } 2004 2005 // WithinRangef asserts that a time is within a time range (inclusive). 2006 // 2007 // assert.WithinRangef(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second), "error message %s", "formatted") 2008 func WithinRangef(t TestingT, actual time.Time, start time.Time, end time.Time, msg string, args ...interface{}) { 2009 if h, ok := t.(tHelper); ok { 2010 h.Helper() 2011 } 2012 if assert.WithinRangef(t, actual, start, end, msg, args...) { 2013 return 2014 } 2015 t.FailNow() 2016 } 2017 2018 // YAMLEq asserts that two YAML strings are equivalent. 2019 func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) { 2020 if h, ok := t.(tHelper); ok { 2021 h.Helper() 2022 } 2023 if assert.YAMLEq(t, expected, actual, msgAndArgs...) { 2024 return 2025 } 2026 t.FailNow() 2027 } 2028 2029 // YAMLEqf asserts that two YAML strings are equivalent. 2030 func YAMLEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) { 2031 if h, ok := t.(tHelper); ok { 2032 h.Helper() 2033 } 2034 if assert.YAMLEqf(t, expected, actual, msg, args...) { 2035 return 2036 } 2037 t.FailNow() 2038 } 2039 2040 // Zero asserts that i is the zero value for its type. 2041 func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) { 2042 if h, ok := t.(tHelper); ok { 2043 h.Helper() 2044 } 2045 if assert.Zero(t, i, msgAndArgs...) { 2046 return 2047 } 2048 t.FailNow() 2049 } 2050 2051 // Zerof asserts that i is the zero value for its type. 2052 func Zerof(t TestingT, i interface{}, msg string, args ...interface{}) { 2053 if h, ok := t.(tHelper); ok { 2054 h.Helper() 2055 } 2056 if assert.Zerof(t, i, msg, args...) { 2057 return 2058 } 2059 t.FailNow() 2060 }