assertion_forward.go 53 KB

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