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