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