require_forward.go 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957
  1. /*
  2. * CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen
  3. * THIS FILE MUST NOT BE EDITED BY HAND
  4. */
  5. package require
  6. import (
  7. assert "github.com/stretchr/testify/assert"
  8. http "net/http"
  9. url "net/url"
  10. time "time"
  11. )
  12. // Condition uses a Comparison to assert a complex condition.
  13. func (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. // Conditionf uses a Comparison to assert a complex condition.
  20. func (a *Assertions) Conditionf(comp assert.Comparison, msg string, args ...interface{}) {
  21. if h, ok := a.t.(tHelper); ok {
  22. h.Helper()
  23. }
  24. Conditionf(a.t, comp, msg, args...)
  25. }
  26. // Contains asserts that the specified string, list(array, slice...) or map contains the
  27. // specified substring or element.
  28. //
  29. // a.Contains("Hello World", "World")
  30. // a.Contains(["Hello", "World"], "World")
  31. // a.Contains({"Hello": "World"}, "Hello")
  32. func (a *Assertions) Contains(s interface{}, contains interface{}, msgAndArgs ...interface{}) {
  33. if h, ok := a.t.(tHelper); ok {
  34. h.Helper()
  35. }
  36. Contains(a.t, s, contains, msgAndArgs...)
  37. }
  38. // Containsf asserts that the specified string, list(array, slice...) or map contains the
  39. // specified substring or element.
  40. //
  41. // a.Containsf("Hello World", "World", "error message %s", "formatted")
  42. // a.Containsf(["Hello", "World"], "World", "error message %s", "formatted")
  43. // a.Containsf({"Hello": "World"}, "Hello", "error message %s", "formatted")
  44. func (a *Assertions) Containsf(s interface{}, contains interface{}, msg string, args ...interface{}) {
  45. if h, ok := a.t.(tHelper); ok {
  46. h.Helper()
  47. }
  48. Containsf(a.t, s, contains, msg, args...)
  49. }
  50. // DirExists checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists.
  51. func (a *Assertions) DirExists(path string, msgAndArgs ...interface{}) {
  52. if h, ok := a.t.(tHelper); ok {
  53. h.Helper()
  54. }
  55. DirExists(a.t, path, msgAndArgs...)
  56. }
  57. // DirExistsf checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists.
  58. func (a *Assertions) DirExistsf(path string, msg string, args ...interface{}) {
  59. if h, ok := a.t.(tHelper); ok {
  60. h.Helper()
  61. }
  62. DirExistsf(a.t, path, msg, args...)
  63. }
  64. // ElementsMatch asserts that the specified listA(array, slice...) is equal to specified
  65. // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,
  66. // the number of appearances of each of them in both lists should match.
  67. //
  68. // a.ElementsMatch([1, 3, 2, 3], [1, 3, 3, 2])
  69. func (a *Assertions) ElementsMatch(listA interface{}, listB interface{}, msgAndArgs ...interface{}) {
  70. if h, ok := a.t.(tHelper); ok {
  71. h.Helper()
  72. }
  73. ElementsMatch(a.t, listA, listB, msgAndArgs...)
  74. }
  75. // ElementsMatchf asserts that the specified listA(array, slice...) is equal to specified
  76. // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,
  77. // the number of appearances of each of them in both lists should match.
  78. //
  79. // a.ElementsMatchf([1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted")
  80. func (a *Assertions) ElementsMatchf(listA interface{}, listB interface{}, msg string, args ...interface{}) {
  81. if h, ok := a.t.(tHelper); ok {
  82. h.Helper()
  83. }
  84. ElementsMatchf(a.t, listA, listB, msg, args...)
  85. }
  86. // Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either
  87. // a slice or a channel with len == 0.
  88. //
  89. // a.Empty(obj)
  90. func (a *Assertions) Empty(object interface{}, msgAndArgs ...interface{}) {
  91. if h, ok := a.t.(tHelper); ok {
  92. h.Helper()
  93. }
  94. Empty(a.t, object, msgAndArgs...)
  95. }
  96. // Emptyf 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.Emptyf(obj, "error message %s", "formatted")
  100. func (a *Assertions) Emptyf(object interface{}, msg string, args ...interface{}) {
  101. if h, ok := a.t.(tHelper); ok {
  102. h.Helper()
  103. }
  104. Emptyf(a.t, object, msg, args...)
  105. }
  106. // Equal asserts that two objects are equal.
  107. //
  108. // a.Equal(123, 123)
  109. //
  110. // Pointer variable equality is determined based on the equality of the
  111. // referenced values (as opposed to the memory addresses). Function equality
  112. // cannot be determined and will always fail.
  113. func (a *Assertions) Equal(expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  114. if h, ok := a.t.(tHelper); ok {
  115. h.Helper()
  116. }
  117. Equal(a.t, expected, actual, msgAndArgs...)
  118. }
  119. // EqualError asserts that a function returned an error (i.e. not `nil`)
  120. // and that it is equal to the provided error.
  121. //
  122. // actualObj, err := SomeFunction()
  123. // a.EqualError(err, expectedErrorString)
  124. func (a *Assertions) EqualError(theError error, errString string, msgAndArgs ...interface{}) {
  125. if h, ok := a.t.(tHelper); ok {
  126. h.Helper()
  127. }
  128. EqualError(a.t, theError, errString, msgAndArgs...)
  129. }
  130. // EqualErrorf asserts that a function returned an error (i.e. not `nil`)
  131. // and that it is equal to the provided error.
  132. //
  133. // actualObj, err := SomeFunction()
  134. // a.EqualErrorf(err, expectedErrorString, "error message %s", "formatted")
  135. func (a *Assertions) EqualErrorf(theError error, errString string, msg string, args ...interface{}) {
  136. if h, ok := a.t.(tHelper); ok {
  137. h.Helper()
  138. }
  139. EqualErrorf(a.t, theError, errString, msg, args...)
  140. }
  141. // EqualValues asserts that two objects are equal or convertable to the same types
  142. // and equal.
  143. //
  144. // a.EqualValues(uint32(123), int32(123))
  145. func (a *Assertions) EqualValues(expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  146. if h, ok := a.t.(tHelper); ok {
  147. h.Helper()
  148. }
  149. EqualValues(a.t, expected, actual, msgAndArgs...)
  150. }
  151. // EqualValuesf asserts that two objects are equal or convertable to the same types
  152. // and equal.
  153. //
  154. // a.EqualValuesf(uint32(123, "error message %s", "formatted"), int32(123))
  155. func (a *Assertions) EqualValuesf(expected interface{}, actual interface{}, msg string, args ...interface{}) {
  156. if h, ok := a.t.(tHelper); ok {
  157. h.Helper()
  158. }
  159. EqualValuesf(a.t, expected, actual, msg, args...)
  160. }
  161. // Equalf asserts that two objects are equal.
  162. //
  163. // a.Equalf(123, 123, "error message %s", "formatted")
  164. //
  165. // Pointer variable equality is determined based on the equality of the
  166. // referenced values (as opposed to the memory addresses). Function equality
  167. // cannot be determined and will always fail.
  168. func (a *Assertions) Equalf(expected interface{}, actual interface{}, msg string, args ...interface{}) {
  169. if h, ok := a.t.(tHelper); ok {
  170. h.Helper()
  171. }
  172. Equalf(a.t, expected, actual, msg, args...)
  173. }
  174. // Error asserts that a function returned an error (i.e. not `nil`).
  175. //
  176. // actualObj, err := SomeFunction()
  177. // if a.Error(err) {
  178. // assert.Equal(t, expectedError, err)
  179. // }
  180. func (a *Assertions) Error(err error, msgAndArgs ...interface{}) {
  181. if h, ok := a.t.(tHelper); ok {
  182. h.Helper()
  183. }
  184. Error(a.t, err, msgAndArgs...)
  185. }
  186. // Errorf asserts that a function returned an error (i.e. not `nil`).
  187. //
  188. // actualObj, err := SomeFunction()
  189. // if a.Errorf(err, "error message %s", "formatted") {
  190. // assert.Equal(t, expectedErrorf, err)
  191. // }
  192. func (a *Assertions) Errorf(err error, msg string, args ...interface{}) {
  193. if h, ok := a.t.(tHelper); ok {
  194. h.Helper()
  195. }
  196. Errorf(a.t, err, msg, args...)
  197. }
  198. // Exactly asserts that two objects are equal in value and type.
  199. //
  200. // a.Exactly(int32(123), int64(123))
  201. func (a *Assertions) Exactly(expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  202. if h, ok := a.t.(tHelper); ok {
  203. h.Helper()
  204. }
  205. Exactly(a.t, expected, actual, msgAndArgs...)
  206. }
  207. // Exactlyf asserts that two objects are equal in value and type.
  208. //
  209. // a.Exactlyf(int32(123, "error message %s", "formatted"), int64(123))
  210. func (a *Assertions) Exactlyf(expected interface{}, actual interface{}, msg string, args ...interface{}) {
  211. if h, ok := a.t.(tHelper); ok {
  212. h.Helper()
  213. }
  214. Exactlyf(a.t, expected, actual, msg, args...)
  215. }
  216. // Fail reports a failure through
  217. func (a *Assertions) Fail(failureMessage string, msgAndArgs ...interface{}) {
  218. if h, ok := a.t.(tHelper); ok {
  219. h.Helper()
  220. }
  221. Fail(a.t, failureMessage, msgAndArgs...)
  222. }
  223. // FailNow fails test
  224. func (a *Assertions) FailNow(failureMessage string, msgAndArgs ...interface{}) {
  225. if h, ok := a.t.(tHelper); ok {
  226. h.Helper()
  227. }
  228. FailNow(a.t, failureMessage, msgAndArgs...)
  229. }
  230. // FailNowf fails test
  231. func (a *Assertions) FailNowf(failureMessage string, msg string, args ...interface{}) {
  232. if h, ok := a.t.(tHelper); ok {
  233. h.Helper()
  234. }
  235. FailNowf(a.t, failureMessage, msg, args...)
  236. }
  237. // Failf reports a failure through
  238. func (a *Assertions) Failf(failureMessage string, msg string, args ...interface{}) {
  239. if h, ok := a.t.(tHelper); ok {
  240. h.Helper()
  241. }
  242. Failf(a.t, failureMessage, msg, args...)
  243. }
  244. // False asserts that the specified value is false.
  245. //
  246. // a.False(myBool)
  247. func (a *Assertions) False(value bool, msgAndArgs ...interface{}) {
  248. if h, ok := a.t.(tHelper); ok {
  249. h.Helper()
  250. }
  251. False(a.t, value, msgAndArgs...)
  252. }
  253. // Falsef asserts that the specified value is false.
  254. //
  255. // a.Falsef(myBool, "error message %s", "formatted")
  256. func (a *Assertions) Falsef(value bool, msg string, args ...interface{}) {
  257. if h, ok := a.t.(tHelper); ok {
  258. h.Helper()
  259. }
  260. Falsef(a.t, value, msg, args...)
  261. }
  262. // FileExists checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file.
  263. func (a *Assertions) FileExists(path string, msgAndArgs ...interface{}) {
  264. if h, ok := a.t.(tHelper); ok {
  265. h.Helper()
  266. }
  267. FileExists(a.t, path, msgAndArgs...)
  268. }
  269. // FileExistsf checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file.
  270. func (a *Assertions) FileExistsf(path string, msg string, args ...interface{}) {
  271. if h, ok := a.t.(tHelper); ok {
  272. h.Helper()
  273. }
  274. FileExistsf(a.t, path, msg, args...)
  275. }
  276. // HTTPBodyContains asserts that a specified handler returns a
  277. // body that contains a string.
  278. //
  279. // a.HTTPBodyContains(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")
  280. //
  281. // Returns whether the assertion was successful (true) or not (false).
  282. func (a *Assertions) HTTPBodyContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) {
  283. if h, ok := a.t.(tHelper); ok {
  284. h.Helper()
  285. }
  286. HTTPBodyContains(a.t, handler, method, url, values, str, msgAndArgs...)
  287. }
  288. // HTTPBodyContainsf asserts that a specified handler returns a
  289. // body that contains a string.
  290. //
  291. // a.HTTPBodyContainsf(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")
  292. //
  293. // Returns whether the assertion was successful (true) or not (false).
  294. func (a *Assertions) HTTPBodyContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) {
  295. if h, ok := a.t.(tHelper); ok {
  296. h.Helper()
  297. }
  298. HTTPBodyContainsf(a.t, handler, method, url, values, str, msg, args...)
  299. }
  300. // HTTPBodyNotContains asserts that a specified handler returns a
  301. // body that does not contain a string.
  302. //
  303. // a.HTTPBodyNotContains(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")
  304. //
  305. // Returns whether the assertion was successful (true) or not (false).
  306. func (a *Assertions) HTTPBodyNotContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) {
  307. if h, ok := a.t.(tHelper); ok {
  308. h.Helper()
  309. }
  310. HTTPBodyNotContains(a.t, handler, method, url, values, str, msgAndArgs...)
  311. }
  312. // HTTPBodyNotContainsf asserts that a specified handler returns a
  313. // body that does not contain a string.
  314. //
  315. // a.HTTPBodyNotContainsf(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")
  316. //
  317. // Returns whether the assertion was successful (true) or not (false).
  318. func (a *Assertions) HTTPBodyNotContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) {
  319. if h, ok := a.t.(tHelper); ok {
  320. h.Helper()
  321. }
  322. HTTPBodyNotContainsf(a.t, handler, method, url, values, str, msg, args...)
  323. }
  324. // HTTPError asserts that a specified handler returns an error status code.
  325. //
  326. // a.HTTPError(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
  327. //
  328. // Returns whether the assertion was successful (true) or not (false).
  329. func (a *Assertions) HTTPError(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) {
  330. if h, ok := a.t.(tHelper); ok {
  331. h.Helper()
  332. }
  333. HTTPError(a.t, handler, method, url, values, msgAndArgs...)
  334. }
  335. // HTTPErrorf asserts that a specified handler returns an error status code.
  336. //
  337. // a.HTTPErrorf(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
  338. //
  339. // Returns whether the assertion was successful (true, "error message %s", "formatted") or not (false).
  340. func (a *Assertions) HTTPErrorf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) {
  341. if h, ok := a.t.(tHelper); ok {
  342. h.Helper()
  343. }
  344. HTTPErrorf(a.t, handler, method, url, values, msg, args...)
  345. }
  346. // HTTPRedirect asserts that a specified handler returns a redirect status code.
  347. //
  348. // a.HTTPRedirect(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
  349. //
  350. // Returns whether the assertion was successful (true) or not (false).
  351. func (a *Assertions) HTTPRedirect(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) {
  352. if h, ok := a.t.(tHelper); ok {
  353. h.Helper()
  354. }
  355. HTTPRedirect(a.t, handler, method, url, values, msgAndArgs...)
  356. }
  357. // HTTPRedirectf asserts that a specified handler returns a redirect status code.
  358. //
  359. // a.HTTPRedirectf(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
  360. //
  361. // Returns whether the assertion was successful (true, "error message %s", "formatted") or not (false).
  362. func (a *Assertions) HTTPRedirectf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) {
  363. if h, ok := a.t.(tHelper); ok {
  364. h.Helper()
  365. }
  366. HTTPRedirectf(a.t, handler, method, url, values, msg, args...)
  367. }
  368. // HTTPSuccess asserts that a specified handler returns a success status code.
  369. //
  370. // a.HTTPSuccess(myHandler, "POST", "http://www.google.com", nil)
  371. //
  372. // Returns whether the assertion was successful (true) or not (false).
  373. func (a *Assertions) HTTPSuccess(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) {
  374. if h, ok := a.t.(tHelper); ok {
  375. h.Helper()
  376. }
  377. HTTPSuccess(a.t, handler, method, url, values, msgAndArgs...)
  378. }
  379. // HTTPSuccessf asserts that a specified handler returns a success status code.
  380. //
  381. // a.HTTPSuccessf(myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted")
  382. //
  383. // Returns whether the assertion was successful (true) or not (false).
  384. func (a *Assertions) HTTPSuccessf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) {
  385. if h, ok := a.t.(tHelper); ok {
  386. h.Helper()
  387. }
  388. HTTPSuccessf(a.t, handler, method, url, values, msg, args...)
  389. }
  390. // Implements asserts that an object is implemented by the specified interface.
  391. //
  392. // a.Implements((*MyInterface)(nil), new(MyObject))
  393. func (a *Assertions) Implements(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) {
  394. if h, ok := a.t.(tHelper); ok {
  395. h.Helper()
  396. }
  397. Implements(a.t, interfaceObject, object, msgAndArgs...)
  398. }
  399. // Implementsf asserts that an object is implemented by the specified interface.
  400. //
  401. // a.Implementsf((*MyInterface, "error message %s", "formatted")(nil), new(MyObject))
  402. func (a *Assertions) Implementsf(interfaceObject interface{}, object interface{}, msg string, args ...interface{}) {
  403. if h, ok := a.t.(tHelper); ok {
  404. h.Helper()
  405. }
  406. Implementsf(a.t, interfaceObject, object, msg, args...)
  407. }
  408. // InDelta asserts that the two numerals are within delta of each other.
  409. //
  410. // a.InDelta(math.Pi, (22 / 7.0), 0.01)
  411. func (a *Assertions) InDelta(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
  412. if h, ok := a.t.(tHelper); ok {
  413. h.Helper()
  414. }
  415. InDelta(a.t, expected, actual, delta, msgAndArgs...)
  416. }
  417. // InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.
  418. func (a *Assertions) InDeltaMapValues(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
  419. if h, ok := a.t.(tHelper); ok {
  420. h.Helper()
  421. }
  422. InDeltaMapValues(a.t, expected, actual, delta, msgAndArgs...)
  423. }
  424. // InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.
  425. func (a *Assertions) InDeltaMapValuesf(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) {
  426. if h, ok := a.t.(tHelper); ok {
  427. h.Helper()
  428. }
  429. InDeltaMapValuesf(a.t, expected, actual, delta, msg, args...)
  430. }
  431. // InDeltaSlice is the same as InDelta, except it compares two slices.
  432. func (a *Assertions) InDeltaSlice(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
  433. if h, ok := a.t.(tHelper); ok {
  434. h.Helper()
  435. }
  436. InDeltaSlice(a.t, expected, actual, delta, msgAndArgs...)
  437. }
  438. // InDeltaSlicef is the same as InDelta, except it compares two slices.
  439. func (a *Assertions) InDeltaSlicef(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) {
  440. if h, ok := a.t.(tHelper); ok {
  441. h.Helper()
  442. }
  443. InDeltaSlicef(a.t, expected, actual, delta, msg, args...)
  444. }
  445. // InDeltaf asserts that the two numerals are within delta of each other.
  446. //
  447. // a.InDeltaf(math.Pi, (22 / 7.0, "error message %s", "formatted"), 0.01)
  448. func (a *Assertions) InDeltaf(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) {
  449. if h, ok := a.t.(tHelper); ok {
  450. h.Helper()
  451. }
  452. InDeltaf(a.t, expected, actual, delta, msg, args...)
  453. }
  454. // InEpsilon asserts that expected and actual have a relative error less than epsilon
  455. func (a *Assertions) InEpsilon(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) {
  456. if h, ok := a.t.(tHelper); ok {
  457. h.Helper()
  458. }
  459. InEpsilon(a.t, expected, actual, epsilon, msgAndArgs...)
  460. }
  461. // InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices.
  462. func (a *Assertions) InEpsilonSlice(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) {
  463. if h, ok := a.t.(tHelper); ok {
  464. h.Helper()
  465. }
  466. InEpsilonSlice(a.t, expected, actual, epsilon, msgAndArgs...)
  467. }
  468. // InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices.
  469. func (a *Assertions) InEpsilonSlicef(expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) {
  470. if h, ok := a.t.(tHelper); ok {
  471. h.Helper()
  472. }
  473. InEpsilonSlicef(a.t, expected, actual, epsilon, msg, args...)
  474. }
  475. // InEpsilonf asserts that expected and actual have a relative error less than epsilon
  476. func (a *Assertions) InEpsilonf(expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) {
  477. if h, ok := a.t.(tHelper); ok {
  478. h.Helper()
  479. }
  480. InEpsilonf(a.t, expected, actual, epsilon, msg, args...)
  481. }
  482. // IsType asserts that the specified objects are of the same type.
  483. func (a *Assertions) IsType(expectedType interface{}, object interface{}, msgAndArgs ...interface{}) {
  484. if h, ok := a.t.(tHelper); ok {
  485. h.Helper()
  486. }
  487. IsType(a.t, expectedType, object, msgAndArgs...)
  488. }
  489. // IsTypef asserts that the specified objects are of the same type.
  490. func (a *Assertions) IsTypef(expectedType interface{}, object interface{}, msg string, args ...interface{}) {
  491. if h, ok := a.t.(tHelper); ok {
  492. h.Helper()
  493. }
  494. IsTypef(a.t, expectedType, object, msg, args...)
  495. }
  496. // JSONEq asserts that two JSON strings are equivalent.
  497. //
  498. // a.JSONEq(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
  499. func (a *Assertions) JSONEq(expected string, actual string, msgAndArgs ...interface{}) {
  500. if h, ok := a.t.(tHelper); ok {
  501. h.Helper()
  502. }
  503. JSONEq(a.t, expected, actual, msgAndArgs...)
  504. }
  505. // JSONEqf asserts that two JSON strings are equivalent.
  506. //
  507. // a.JSONEqf(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted")
  508. func (a *Assertions) JSONEqf(expected string, actual string, msg string, args ...interface{}) {
  509. if h, ok := a.t.(tHelper); ok {
  510. h.Helper()
  511. }
  512. JSONEqf(a.t, expected, actual, msg, args...)
  513. }
  514. // Len asserts that the specified object has specific length.
  515. // Len also fails if the object has a type that len() not accept.
  516. //
  517. // a.Len(mySlice, 3)
  518. func (a *Assertions) Len(object interface{}, length int, msgAndArgs ...interface{}) {
  519. if h, ok := a.t.(tHelper); ok {
  520. h.Helper()
  521. }
  522. Len(a.t, object, length, msgAndArgs...)
  523. }
  524. // Lenf asserts that the specified object has specific length.
  525. // Lenf also fails if the object has a type that len() not accept.
  526. //
  527. // a.Lenf(mySlice, 3, "error message %s", "formatted")
  528. func (a *Assertions) Lenf(object interface{}, length int, msg string, args ...interface{}) {
  529. if h, ok := a.t.(tHelper); ok {
  530. h.Helper()
  531. }
  532. Lenf(a.t, object, length, msg, args...)
  533. }
  534. // Nil asserts that the specified object is nil.
  535. //
  536. // a.Nil(err)
  537. func (a *Assertions) Nil(object interface{}, msgAndArgs ...interface{}) {
  538. if h, ok := a.t.(tHelper); ok {
  539. h.Helper()
  540. }
  541. Nil(a.t, object, msgAndArgs...)
  542. }
  543. // Nilf asserts that the specified object is nil.
  544. //
  545. // a.Nilf(err, "error message %s", "formatted")
  546. func (a *Assertions) Nilf(object interface{}, msg string, args ...interface{}) {
  547. if h, ok := a.t.(tHelper); ok {
  548. h.Helper()
  549. }
  550. Nilf(a.t, object, msg, args...)
  551. }
  552. // NoError asserts that a function returned no error (i.e. `nil`).
  553. //
  554. // actualObj, err := SomeFunction()
  555. // if a.NoError(err) {
  556. // assert.Equal(t, expectedObj, actualObj)
  557. // }
  558. func (a *Assertions) NoError(err error, msgAndArgs ...interface{}) {
  559. if h, ok := a.t.(tHelper); ok {
  560. h.Helper()
  561. }
  562. NoError(a.t, err, msgAndArgs...)
  563. }
  564. // NoErrorf asserts that a function returned no error (i.e. `nil`).
  565. //
  566. // actualObj, err := SomeFunction()
  567. // if a.NoErrorf(err, "error message %s", "formatted") {
  568. // assert.Equal(t, expectedObj, actualObj)
  569. // }
  570. func (a *Assertions) NoErrorf(err error, msg string, args ...interface{}) {
  571. if h, ok := a.t.(tHelper); ok {
  572. h.Helper()
  573. }
  574. NoErrorf(a.t, err, msg, args...)
  575. }
  576. // NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the
  577. // specified substring or element.
  578. //
  579. // a.NotContains("Hello World", "Earth")
  580. // a.NotContains(["Hello", "World"], "Earth")
  581. // a.NotContains({"Hello": "World"}, "Earth")
  582. func (a *Assertions) NotContains(s interface{}, contains interface{}, msgAndArgs ...interface{}) {
  583. if h, ok := a.t.(tHelper); ok {
  584. h.Helper()
  585. }
  586. NotContains(a.t, s, contains, msgAndArgs...)
  587. }
  588. // NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the
  589. // specified substring or element.
  590. //
  591. // a.NotContainsf("Hello World", "Earth", "error message %s", "formatted")
  592. // a.NotContainsf(["Hello", "World"], "Earth", "error message %s", "formatted")
  593. // a.NotContainsf({"Hello": "World"}, "Earth", "error message %s", "formatted")
  594. func (a *Assertions) NotContainsf(s interface{}, contains interface{}, msg string, args ...interface{}) {
  595. if h, ok := a.t.(tHelper); ok {
  596. h.Helper()
  597. }
  598. NotContainsf(a.t, s, contains, msg, args...)
  599. }
  600. // NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
  601. // a slice or a channel with len == 0.
  602. //
  603. // if a.NotEmpty(obj) {
  604. // assert.Equal(t, "two", obj[1])
  605. // }
  606. func (a *Assertions) NotEmpty(object interface{}, msgAndArgs ...interface{}) {
  607. if h, ok := a.t.(tHelper); ok {
  608. h.Helper()
  609. }
  610. NotEmpty(a.t, object, msgAndArgs...)
  611. }
  612. // NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
  613. // a slice or a channel with len == 0.
  614. //
  615. // if a.NotEmptyf(obj, "error message %s", "formatted") {
  616. // assert.Equal(t, "two", obj[1])
  617. // }
  618. func (a *Assertions) NotEmptyf(object interface{}, msg string, args ...interface{}) {
  619. if h, ok := a.t.(tHelper); ok {
  620. h.Helper()
  621. }
  622. NotEmptyf(a.t, object, msg, args...)
  623. }
  624. // NotEqual asserts that the specified values are NOT equal.
  625. //
  626. // a.NotEqual(obj1, obj2)
  627. //
  628. // Pointer variable equality is determined based on the equality of the
  629. // referenced values (as opposed to the memory addresses).
  630. func (a *Assertions) NotEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  631. if h, ok := a.t.(tHelper); ok {
  632. h.Helper()
  633. }
  634. NotEqual(a.t, expected, actual, msgAndArgs...)
  635. }
  636. // NotEqualf asserts that the specified values are NOT equal.
  637. //
  638. // a.NotEqualf(obj1, obj2, "error message %s", "formatted")
  639. //
  640. // Pointer variable equality is determined based on the equality of the
  641. // referenced values (as opposed to the memory addresses).
  642. func (a *Assertions) NotEqualf(expected interface{}, actual interface{}, msg string, args ...interface{}) {
  643. if h, ok := a.t.(tHelper); ok {
  644. h.Helper()
  645. }
  646. NotEqualf(a.t, expected, actual, msg, args...)
  647. }
  648. // NotNil asserts that the specified object is not nil.
  649. //
  650. // a.NotNil(err)
  651. func (a *Assertions) NotNil(object interface{}, msgAndArgs ...interface{}) {
  652. if h, ok := a.t.(tHelper); ok {
  653. h.Helper()
  654. }
  655. NotNil(a.t, object, msgAndArgs...)
  656. }
  657. // NotNilf asserts that the specified object is not nil.
  658. //
  659. // a.NotNilf(err, "error message %s", "formatted")
  660. func (a *Assertions) NotNilf(object interface{}, msg string, args ...interface{}) {
  661. if h, ok := a.t.(tHelper); ok {
  662. h.Helper()
  663. }
  664. NotNilf(a.t, object, msg, args...)
  665. }
  666. // NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.
  667. //
  668. // a.NotPanics(func(){ RemainCalm() })
  669. func (a *Assertions) NotPanics(f assert.PanicTestFunc, msgAndArgs ...interface{}) {
  670. if h, ok := a.t.(tHelper); ok {
  671. h.Helper()
  672. }
  673. NotPanics(a.t, f, msgAndArgs...)
  674. }
  675. // NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic.
  676. //
  677. // a.NotPanicsf(func(){ RemainCalm() }, "error message %s", "formatted")
  678. func (a *Assertions) NotPanicsf(f assert.PanicTestFunc, msg string, args ...interface{}) {
  679. if h, ok := a.t.(tHelper); ok {
  680. h.Helper()
  681. }
  682. NotPanicsf(a.t, f, msg, args...)
  683. }
  684. // NotRegexp asserts that a specified regexp does not match a string.
  685. //
  686. // a.NotRegexp(regexp.MustCompile("starts"), "it's starting")
  687. // a.NotRegexp("^start", "it's not starting")
  688. func (a *Assertions) NotRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) {
  689. if h, ok := a.t.(tHelper); ok {
  690. h.Helper()
  691. }
  692. NotRegexp(a.t, rx, str, msgAndArgs...)
  693. }
  694. // NotRegexpf asserts that a specified regexp does not match a string.
  695. //
  696. // a.NotRegexpf(regexp.MustCompile("starts", "error message %s", "formatted"), "it's starting")
  697. // a.NotRegexpf("^start", "it's not starting", "error message %s", "formatted")
  698. func (a *Assertions) NotRegexpf(rx interface{}, str interface{}, msg string, args ...interface{}) {
  699. if h, ok := a.t.(tHelper); ok {
  700. h.Helper()
  701. }
  702. NotRegexpf(a.t, rx, str, msg, args...)
  703. }
  704. // NotSubset asserts that the specified list(array, slice...) contains not all
  705. // elements given in the specified subset(array, slice...).
  706. //
  707. // a.NotSubset([1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]")
  708. func (a *Assertions) NotSubset(list interface{}, subset interface{}, msgAndArgs ...interface{}) {
  709. if h, ok := a.t.(tHelper); ok {
  710. h.Helper()
  711. }
  712. NotSubset(a.t, list, subset, msgAndArgs...)
  713. }
  714. // NotSubsetf asserts that the specified list(array, slice...) contains not all
  715. // elements given in the specified subset(array, slice...).
  716. //
  717. // a.NotSubsetf([1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]", "error message %s", "formatted")
  718. func (a *Assertions) NotSubsetf(list interface{}, subset interface{}, msg string, args ...interface{}) {
  719. if h, ok := a.t.(tHelper); ok {
  720. h.Helper()
  721. }
  722. NotSubsetf(a.t, list, subset, msg, args...)
  723. }
  724. // NotZero asserts that i is not the zero value for its type.
  725. func (a *Assertions) NotZero(i interface{}, msgAndArgs ...interface{}) {
  726. if h, ok := a.t.(tHelper); ok {
  727. h.Helper()
  728. }
  729. NotZero(a.t, i, msgAndArgs...)
  730. }
  731. // NotZerof asserts that i is not the zero value for its type.
  732. func (a *Assertions) NotZerof(i interface{}, msg string, args ...interface{}) {
  733. if h, ok := a.t.(tHelper); ok {
  734. h.Helper()
  735. }
  736. NotZerof(a.t, i, msg, args...)
  737. }
  738. // Panics asserts that the code inside the specified PanicTestFunc panics.
  739. //
  740. // a.Panics(func(){ GoCrazy() })
  741. func (a *Assertions) Panics(f assert.PanicTestFunc, msgAndArgs ...interface{}) {
  742. if h, ok := a.t.(tHelper); ok {
  743. h.Helper()
  744. }
  745. Panics(a.t, f, msgAndArgs...)
  746. }
  747. // PanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that
  748. // the recovered panic value equals the expected panic value.
  749. //
  750. // a.PanicsWithValue("crazy error", func(){ GoCrazy() })
  751. func (a *Assertions) PanicsWithValue(expected interface{}, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
  752. if h, ok := a.t.(tHelper); ok {
  753. h.Helper()
  754. }
  755. PanicsWithValue(a.t, expected, f, msgAndArgs...)
  756. }
  757. // PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that
  758. // the recovered panic value equals the expected panic value.
  759. //
  760. // a.PanicsWithValuef("crazy error", func(){ GoCrazy() }, "error message %s", "formatted")
  761. func (a *Assertions) PanicsWithValuef(expected interface{}, f assert.PanicTestFunc, msg string, args ...interface{}) {
  762. if h, ok := a.t.(tHelper); ok {
  763. h.Helper()
  764. }
  765. PanicsWithValuef(a.t, expected, f, msg, args...)
  766. }
  767. // Panicsf asserts that the code inside the specified PanicTestFunc panics.
  768. //
  769. // a.Panicsf(func(){ GoCrazy() }, "error message %s", "formatted")
  770. func (a *Assertions) Panicsf(f assert.PanicTestFunc, msg string, args ...interface{}) {
  771. if h, ok := a.t.(tHelper); ok {
  772. h.Helper()
  773. }
  774. Panicsf(a.t, f, msg, args...)
  775. }
  776. // Regexp asserts that a specified regexp matches a string.
  777. //
  778. // a.Regexp(regexp.MustCompile("start"), "it's starting")
  779. // a.Regexp("start...$", "it's not starting")
  780. func (a *Assertions) Regexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) {
  781. if h, ok := a.t.(tHelper); ok {
  782. h.Helper()
  783. }
  784. Regexp(a.t, rx, str, msgAndArgs...)
  785. }
  786. // Regexpf asserts that a specified regexp matches a string.
  787. //
  788. // a.Regexpf(regexp.MustCompile("start", "error message %s", "formatted"), "it's starting")
  789. // a.Regexpf("start...$", "it's not starting", "error message %s", "formatted")
  790. func (a *Assertions) Regexpf(rx interface{}, str interface{}, msg string, args ...interface{}) {
  791. if h, ok := a.t.(tHelper); ok {
  792. h.Helper()
  793. }
  794. Regexpf(a.t, rx, str, msg, args...)
  795. }
  796. // Subset asserts that the specified list(array, slice...) contains all
  797. // elements given in the specified subset(array, slice...).
  798. //
  799. // a.Subset([1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]")
  800. func (a *Assertions) Subset(list interface{}, subset interface{}, msgAndArgs ...interface{}) {
  801. if h, ok := a.t.(tHelper); ok {
  802. h.Helper()
  803. }
  804. Subset(a.t, list, subset, msgAndArgs...)
  805. }
  806. // Subsetf asserts that the specified list(array, slice...) contains all
  807. // elements given in the specified subset(array, slice...).
  808. //
  809. // a.Subsetf([1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]", "error message %s", "formatted")
  810. func (a *Assertions) Subsetf(list interface{}, subset interface{}, msg string, args ...interface{}) {
  811. if h, ok := a.t.(tHelper); ok {
  812. h.Helper()
  813. }
  814. Subsetf(a.t, list, subset, msg, args...)
  815. }
  816. // True asserts that the specified value is true.
  817. //
  818. // a.True(myBool)
  819. func (a *Assertions) True(value bool, msgAndArgs ...interface{}) {
  820. if h, ok := a.t.(tHelper); ok {
  821. h.Helper()
  822. }
  823. True(a.t, value, msgAndArgs...)
  824. }
  825. // Truef asserts that the specified value is true.
  826. //
  827. // a.Truef(myBool, "error message %s", "formatted")
  828. func (a *Assertions) Truef(value bool, msg string, args ...interface{}) {
  829. if h, ok := a.t.(tHelper); ok {
  830. h.Helper()
  831. }
  832. Truef(a.t, value, msg, args...)
  833. }
  834. // WithinDuration asserts that the two times are within duration delta of each other.
  835. //
  836. // a.WithinDuration(time.Now(), time.Now(), 10*time.Second)
  837. func (a *Assertions) WithinDuration(expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) {
  838. if h, ok := a.t.(tHelper); ok {
  839. h.Helper()
  840. }
  841. WithinDuration(a.t, expected, actual, delta, msgAndArgs...)
  842. }
  843. // WithinDurationf asserts that the two times are within duration delta of each other.
  844. //
  845. // a.WithinDurationf(time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted")
  846. func (a *Assertions) WithinDurationf(expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) {
  847. if h, ok := a.t.(tHelper); ok {
  848. h.Helper()
  849. }
  850. WithinDurationf(a.t, expected, actual, delta, msg, args...)
  851. }
  852. // Zero asserts that i is the zero value for its type.
  853. func (a *Assertions) Zero(i interface{}, msgAndArgs ...interface{}) {
  854. if h, ok := a.t.(tHelper); ok {
  855. h.Helper()
  856. }
  857. Zero(a.t, i, msgAndArgs...)
  858. }
  859. // Zerof asserts that i is the zero value for its type.
  860. func (a *Assertions) Zerof(i interface{}, msg string, args ...interface{}) {
  861. if h, ok := a.t.(tHelper); ok {
  862. h.Helper()
  863. }
  864. Zerof(a.t, i, msg, args...)
  865. }