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