require_forward.go 55 KB

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