Debian Codegraph @

require.go

raw symbols SCIP
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 assert "github.com/stretchr/testify/assert"
14 )
15
16 // Condition uses a Comparison to assert a complex condition.
17 func Condition(t TestingT, comp assert.Comparison, msgAndArgs ...interface{}) {
18 if !assert.Condition(t, comp, msgAndArgs...) {
19 t.FailNow()
20 }
21 }
22
23 // Contains asserts that the specified string, list(array, slice...) or map contains the
24 // specified substring or element.
25 //
26 // assert.Contains(t, "Hello World", "World")
27 // assert.Contains(t, ["Hello", "World"], "World")
28 // assert.Contains(t, {"Hello": "World"}, "Hello")
29 func Contains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) {
30 if !assert.Contains(t, s, contains, msgAndArgs...) {
31 t.FailNow()
32 }
33 }
34
35 // DirExists checks whether a directory exists in the given path. It also fails
36 // if the path is a file rather a directory or there is an error checking whether it exists.
37 func DirExists(t TestingT, path string, msgAndArgs ...interface{}) {
38 if !assert.DirExists(t, path, msgAndArgs...) {
39 t.FailNow()
40 }
41 }
42
43 // ElementsMatch asserts that the specified listA(array, slice...) is equal to specified
44 // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,
45 // the number of appearances of each of them in both lists should match.
46 //
47 // assert.ElementsMatch(t, [1, 3, 2, 3], [1, 3, 3, 2])
48 func ElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndArgs ...interface{}) {
49 if !assert.ElementsMatch(t, listA, listB, msgAndArgs...) {
50 t.FailNow()
51 }
52 }
53
54 // Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either
55 // a slice or a channel with len == 0.
56 //
57 // assert.Empty(t, obj)
58 func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) {
59 if !assert.Empty(t, object, msgAndArgs...) {
60 t.FailNow()
61 }
62 }
63
64 // Equal asserts that two objects are equal.
65 //
66 // assert.Equal(t, 123, 123)
67 //
68 // Pointer variable equality is determined based on the equality of the
69 // referenced values (as opposed to the memory addresses). Function equality
70 // cannot be determined and will always fail.
71 func Equal(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
72 if !assert.Equal(t, expected, actual, msgAndArgs...) {
73 t.FailNow()
74 }
75 }
76
77 // EqualError asserts that a function returned an error (i.e. not `nil`)
78 // and that it is equal to the provided error.
79 //
80 // actualObj, err := SomeFunction()
81 // assert.EqualError(t, err, expectedErrorString)
82 func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) {
83 if !assert.EqualError(t, theError, errString, msgAndArgs...) {
84 t.FailNow()
85 }
86 }
87
88 // EqualValues asserts that two objects are equal or convertable to the same types
89 // and equal.
90 //
91 // assert.EqualValues(t, uint32(123), int32(123))
92 func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
93 if !assert.EqualValues(t, expected, actual, msgAndArgs...) {
94 t.FailNow()
95 }
96 }
97
98 // Error asserts that a function returned an error (i.e. not `nil`).
99 //
100 // actualObj, err := SomeFunction()
101 // if assert.Error(t, err) {
102 // assert.Equal(t, expectedError, err)
103 // }
104 func Error(t TestingT, err error, msgAndArgs ...interface{}) {
105 if !assert.Error(t, err, msgAndArgs...) {
106 t.FailNow()
107 }
108 }
109
110 // Eventually asserts that given condition will be met in waitFor time,
111 // periodically checking target function each tick.
112 //
113 // assert.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond)
114 func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) {
115 if !assert.Eventually(t, condition, waitFor, tick, msgAndArgs...) {
116 t.FailNow()
117 }
118 }
119
120 // Exactly asserts that two objects are equal in value and type.
121 //
122 // assert.Exactly(t, int32(123), int64(123))
123 func Exactly(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
124 if !assert.Exactly(t, expected, actual, msgAndArgs...) {
125 t.FailNow()
126 }
127 }
128
129 // Fail reports a failure through
130 func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) {
131 if !assert.Fail(t, failureMessage, msgAndArgs...) {
132 t.FailNow()
133 }
134 }
135
136 // FailNow fails test
137 func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) {
138 if !assert.FailNow(t, failureMessage, msgAndArgs...) {
139 t.FailNow()
140 }
141 }
142
143 // False asserts that the specified value is false.
144 //
145 // assert.False(t, myBool)
146 func False(t TestingT, value bool, msgAndArgs ...interface{}) {
147 if !assert.False(t, value, msgAndArgs...) {
148 t.FailNow()
149 }
150 }
151
152 // FileExists checks whether a file exists in the given path. It also fails if
153 // the path points to a directory or there is an error when trying to check the file.
154 func FileExists(t TestingT, path string, msgAndArgs ...interface{}) {
155 if !assert.FileExists(t, path, msgAndArgs...) {
156 t.FailNow()
157 }
158 }
159
160 // Greater asserts that the first element is greater than the second
161 //
162 // assert.Greater(t, 2, 1)
163 // assert.Greater(t, float64(2), float64(1))
164 // assert.Greater(t, "b", "a")
165 func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) {
166 if !assert.Greater(t, e1, e2, msgAndArgs...) {
167 t.FailNow()
168 }
169 }
170
171 // GreaterOrEqual asserts that the first element is greater than or equal to the second
172 //
173 // assert.GreaterOrEqual(t, 2, 1)
174 // assert.GreaterOrEqual(t, 2, 2)
175 // assert.GreaterOrEqual(t, "b", "a")
176 // assert.GreaterOrEqual(t, "b", "b")
177 func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) {
178 if !assert.GreaterOrEqual(t, e1, e2, msgAndArgs...) {
179 t.FailNow()
180 }
181 }
182
183 // HTTPBodyContains asserts that a specified handler returns a
184 // body that contains a string.
185 //
186 // assert.HTTPBodyContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")
187 //
188 // Returns whether the assertion was successful (true) or not (false).
189 func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) {
190 if !assert.HTTPBodyContains(t, handler, method, url, values, str, msgAndArgs...) {
191 t.FailNow()
192 }
193 }
194
195 // HTTPBodyNotContains asserts that a specified handler returns a
196 // body that does not contain a string.
197 //
198 // assert.HTTPBodyNotContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")
199 //
200 // Returns whether the assertion was successful (true) or not (false).
201 func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) {
202 if !assert.HTTPBodyNotContains(t, handler, method, url, values, str, msgAndArgs...) {
203 t.FailNow()
204 }
205 }
206
207 // HTTPError asserts that a specified handler returns an error status code.
208 //
209 // assert.HTTPError(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
210 //
211 // Returns whether the assertion was successful (true) or not (false).
212 func HTTPError(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) {
213 if !assert.HTTPError(t, handler, method, url, values, msgAndArgs...) {
214 t.FailNow()
215 }
216 }
217
218 // HTTPRedirect asserts that a specified handler returns a redirect status code.
219 //
220 // assert.HTTPRedirect(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
221 //
222 // Returns whether the assertion was successful (true) or not (false).
223 func HTTPRedirect(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) {
224 if !assert.HTTPRedirect(t, handler, method, url, values, msgAndArgs...) {
225 t.FailNow()
226 }
227 }
228
229 // HTTPStatusCode asserts that a specified handler returns a specified status code.
230 //
231 // assert.HTTPStatusCode(t, myHandler, "GET", "/notImplemented", nil, 501)
232 //
233 // Returns whether the assertion was successful (true) or not (false).
234 func HTTPStatusCode(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msgAndArgs ...interface{}) {
235 if !assert.HTTPStatusCode(t, handler, method, url, values, statuscode, msgAndArgs...) {
236 t.FailNow()
237 }
238 }
239
240 // HTTPSuccess asserts that a specified handler returns a success status code.
241 //
242 // assert.HTTPSuccess(t, myHandler, "POST", "http://www.google.com", nil)
243 //
244 // Returns whether the assertion was successful (true) or not (false).
245 func HTTPSuccess(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) {
246 if !assert.HTTPSuccess(t, handler, method, url, values, msgAndArgs...) {
247 t.FailNow()
248 }
249 }
250
251 // Implements asserts that an object is implemented by the specified interface.
252 //
253 // assert.Implements(t, (*MyInterface)(nil), new(MyObject))
254 func Implements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) {
255 if !assert.Implements(t, interfaceObject, object, msgAndArgs...) {
256 t.FailNow()
257 }
258 }
259
260 // InDelta asserts that the two numerals are within delta of each other.
261 //
262 // assert.InDelta(t, math.Pi, 22/7.0, 0.01)
263 func InDelta(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
264 if !assert.InDelta(t, expected, actual, delta, msgAndArgs...) {
265 t.FailNow()
266 }
267 }
268
269 // InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.
270 func InDeltaMapValues(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
271 if !assert.InDeltaMapValues(t, expected, actual, delta, msgAndArgs...) {
272 t.FailNow()
273 }
274 }
275
276 // InDeltaSlice is the same as InDelta, except it compares two slices.
277 func InDeltaSlice(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
278 if !assert.InDeltaSlice(t, expected, actual, delta, msgAndArgs...) {
279 t.FailNow()
280 }
281 }
282
283 // InEpsilon asserts that expected and actual have a relative error less than epsilon
284 func InEpsilon(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) {
285 if !assert.InEpsilon(t, expected, actual, epsilon, msgAndArgs...) {
286 t.FailNow()
287 }
288 }
289
290 // InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices.
291 func InEpsilonSlice(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) {
292 if !assert.InEpsilonSlice(t, expected, actual, epsilon, msgAndArgs...) {
293 t.FailNow()
294 }
295 }
296
297 // IsType asserts that the specified objects are of the same type.
298 func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) {
299 if !assert.IsType(t, expectedType, object, msgAndArgs...) {
300 t.FailNow()
301 }
302 }
303
304 // JSONEq asserts that two JSON strings are equivalent.
305 //
306 // assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
307 func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) {
308 if !assert.JSONEq(t, expected, actual, msgAndArgs...) {
309 t.FailNow()
310 }
311 }
312
313 // Len asserts that the specified object has specific length.
314 // Len also fails if the object has a type that len() not accept.
315 //
316 // assert.Len(t, mySlice, 3)
317 func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) {
318 if !assert.Len(t, object, length, msgAndArgs...) {
319 t.FailNow()
320 }
321 }
322
323 // Less asserts that the first element is less than the second
324 //
325 // assert.Less(t, 1, 2)
326 // assert.Less(t, float64(1), float64(2))
327 // assert.Less(t, "a", "b")
328 func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) {
329 if !assert.Less(t, e1, e2, msgAndArgs...) {
330 t.FailNow()
331 }
332 }
333
334 // LessOrEqual asserts that the first element is less than or equal to the second
335 //
336 // assert.LessOrEqual(t, 1, 2)
337 // assert.LessOrEqual(t, 2, 2)
338 // assert.LessOrEqual(t, "a", "b")
339 // assert.LessOrEqual(t, "b", "b")
340 func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) {
341 if !assert.LessOrEqual(t, e1, e2, msgAndArgs...) {
342 t.FailNow()
343 }
344 }
345
346 // Never asserts that the given condition doesn't satisfy in waitFor time,
347 // periodically checking the target function each tick.
348 //
349 // assert.Never(t, func() bool { return false; }, time.Second, 10*time.Millisecond)
350 func Never(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) {
351 if !assert.Never(t, condition, waitFor, tick, msgAndArgs...) {
352 t.FailNow()
353 }
354 }
355
356 // Nil asserts that the specified object is nil.
357 //
358 // assert.Nil(t, err)
359 func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) {
360 if !assert.Nil(t, object, msgAndArgs...) {
361 t.FailNow()
362 }
363 }
364
365 // NoDirExists checks whether a directory does not exist in the given path.
366 // It fails if the path points to an existing _directory_ only.
367 func NoDirExists(t TestingT, path string, msgAndArgs ...interface{}) {
368 if !assert.NoDirExists(t, path, msgAndArgs...) {
369 t.FailNow()
370 }
371 }
372
373 // NoError asserts that a function returned no error (i.e. `nil`).
374 //
375 // actualObj, err := SomeFunction()
376 // if assert.NoError(t, err) {
377 // assert.Equal(t, expectedObj, actualObj)
378 // }
379 func NoError(t TestingT, err error, msgAndArgs ...interface{}) {
380 if !assert.NoError(t, err, msgAndArgs...) {
381 t.FailNow()
382 }
383 }
384
385 // NoFileExists checks whether a file does not exist in a given path. It fails
386 // if the path points to an existing _file_ only.
387 func NoFileExists(t TestingT, path string, msgAndArgs ...interface{}) {
388 if !assert.NoFileExists(t, path, msgAndArgs...) {
389 t.FailNow()
390 }
391 }
392
393 // NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the
394 // specified substring or element.
395 //
396 // assert.NotContains(t, "Hello World", "Earth")
397 // assert.NotContains(t, ["Hello", "World"], "Earth")
398 // assert.NotContains(t, {"Hello": "World"}, "Earth")
399 func NotContains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) {
400 if !assert.NotContains(t, s, contains, msgAndArgs...) {
401 t.FailNow()
402 }
403 }
404
405 // NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
406 // a slice or a channel with len == 0.
407 //
408 // if assert.NotEmpty(t, obj) {
409 // assert.Equal(t, "two", obj[1])
410 // }
411 func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) {
412 if !assert.NotEmpty(t, object, msgAndArgs...) {
413 t.FailNow()
414 }
415 }
416
417 // NotEqual asserts that the specified values are NOT equal.
418 //
419 // assert.NotEqual(t, obj1, obj2)
420 //
421 // Pointer variable equality is determined based on the equality of the
422 // referenced values (as opposed to the memory addresses).
423 func NotEqual(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
424 if !assert.NotEqual(t, expected, actual, msgAndArgs...) {
425 t.FailNow()
426 }
427 }
428
429 // NotEqualValues asserts that two objects are not equal even when converted to the same type
430 //
431 // assert.NotEqualValues(t, obj1, obj2)
432 func NotEqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
433 if !assert.NotEqualValues(t, expected, actual, msgAndArgs...) {
434 t.FailNow()
435 }
436 }
437
438 // NotNil asserts that the specified object is not nil.
439 //
440 // assert.NotNil(t, err)
441 func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) {
442 if !assert.NotNil(t, object, msgAndArgs...) {
443 t.FailNow()
444 }
445 }
446
447 // NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.
448 //
449 // assert.NotPanics(t, func(){ RemainCalm() })
450 func NotPanics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
451 if !assert.NotPanics(t, f, msgAndArgs...) {
452 t.FailNow()
453 }
454 }
455
456 // NotRegexp asserts that a specified regexp does not match a string.
457 //
458 // assert.NotRegexp(t, regexp.MustCompile("starts"), "it's starting")
459 // assert.NotRegexp(t, "^start", "it's not starting")
460 func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) {
461 if !assert.NotRegexp(t, rx, str, msgAndArgs...) {
462 t.FailNow()
463 }
464 }
465
466 // NotSame asserts that two pointers do not reference the same object.
467 //
468 // assert.NotSame(t, ptr1, ptr2)
469 //
470 // Both arguments must be pointer variables. Pointer variable sameness is
471 // determined based on the equality of both type and value.
472 func NotSame(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
473 if !assert.NotSame(t, expected, actual, msgAndArgs...) {
474 t.FailNow()
475 }
476 }
477
478 // NotSubset asserts that the specified list(array, slice...) contains not all
479 // elements given in the specified subset(array, slice...).
480 //
481 // assert.NotSubset(t, [1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]")
482 func NotSubset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) {
483 if !assert.NotSubset(t, list, subset, msgAndArgs...) {
484 t.FailNow()
485 }
486 }
487
488 // NotZero asserts that i is not the zero value for its type.
489 func NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) {
490 if !assert.NotZero(t, i, msgAndArgs...) {
491 t.FailNow()
492 }
493 }
494
495 // Panics asserts that the code inside the specified PanicTestFunc panics.
496 //
497 // assert.Panics(t, func(){ GoCrazy() })
498 func Panics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
499 if !assert.Panics(t, f, msgAndArgs...) {
500 t.FailNow()
501 }
502 }
503
504 // PanicsWithError asserts that the code inside the specified PanicTestFunc
505 // panics, and that the recovered panic value is an error that satisfies the
506 // EqualError comparison.
507 //
508 // assert.PanicsWithError(t, "crazy error", func(){ GoCrazy() })
509 func PanicsWithError(t TestingT, errString string, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
510 if !assert.PanicsWithError(t, errString, f, msgAndArgs...) {
511 t.FailNow()
512 }
513 }
514
515 // PanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that
516 // the recovered panic value equals the expected panic value.
517 //
518 // assert.PanicsWithValue(t, "crazy error", func(){ GoCrazy() })
519 func PanicsWithValue(t TestingT, expected interface{}, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
520 if !assert.PanicsWithValue(t, expected, f, msgAndArgs...) {
521 t.FailNow()
522 }
523 }
524
525 // Regexp asserts that a specified regexp matches a string.
526 //
527 // assert.Regexp(t, regexp.MustCompile("start"), "it's starting")
528 // assert.Regexp(t, "start...$", "it's not starting")
529 func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) {
530 if !assert.Regexp(t, rx, str, msgAndArgs...) {
531 t.FailNow()
532 }
533 }
534
535 // Same asserts that two pointers reference the same object.
536 //
537 // assert.Same(t, ptr1, ptr2)
538 //
539 // Both arguments must be pointer variables. Pointer variable sameness is
540 // determined based on the equality of both type and value.
541 func Same(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
542 if !assert.Same(t, expected, actual, msgAndArgs...) {
543 t.FailNow()
544 }
545 }
546
547 // Subset asserts that the specified list(array, slice...) contains all
548 // elements given in the specified subset(array, slice...).
549 //
550 // assert.Subset(t, [1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]")
551 func Subset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...interface{}) {
552 if !assert.Subset(t, list, subset, msgAndArgs...) {
553 t.FailNow()
554 }
555 }
556
557 // True asserts that the specified value is true.
558 //
559 // assert.True(t, myBool)
560 func True(t TestingT, value bool, msgAndArgs ...interface{}) {
561 if !assert.True(t, value, msgAndArgs...) {
562 t.FailNow()
563 }
564 }
565
566 // WithinDuration asserts that the two times are within duration delta of each other.
567 //
568 // assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second)
569 func WithinDuration(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) {
570 if !assert.WithinDuration(t, expected, actual, delta, msgAndArgs...) {
571 t.FailNow()
572 }
573 }
574
575 // YAMLEq asserts that two YAML strings are equivalent.
576 func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) {
577 if !assert.YAMLEq(t, expected, actual, msgAndArgs...) {
578 t.FailNow()
579 }
580 }
581
582 // Zero asserts that i is the zero value for its type.
583 func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) {
584 if !assert.Zero(t, i, msgAndArgs...) {
585 t.FailNow()
586 }
587 }