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