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