require.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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 Condition(t TestingT, comp assert.Comparison, msgAndArgs ...interface{}) {
  14. if !assert.Condition(t, comp, msgAndArgs...) {
  15. t.FailNow()
  16. }
  17. }
  18. // Contains asserts that the specified string, list(array, slice...) or map contains the
  19. // specified substring or element.
  20. //
  21. // assert.Contains(t, "Hello World", "World", "But 'Hello World' does contain 'World'")
  22. // assert.Contains(t, ["Hello", "World"], "World", "But ["Hello", "World"] does contain 'World'")
  23. // assert.Contains(t, {"Hello": "World"}, "Hello", "But {'Hello': 'World'} does contain 'Hello'")
  24. //
  25. // Returns whether the assertion was successful (true) or not (false).
  26. func Contains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) {
  27. if !assert.Contains(t, s, contains, msgAndArgs...) {
  28. t.FailNow()
  29. }
  30. }
  31. // Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either
  32. // a slice or a channel with len == 0.
  33. //
  34. // assert.Empty(t, obj)
  35. //
  36. // Returns whether the assertion was successful (true) or not (false).
  37. func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  38. if !assert.Empty(t, object, msgAndArgs...) {
  39. t.FailNow()
  40. }
  41. }
  42. // Equal asserts that two objects are equal.
  43. //
  44. // assert.Equal(t, 123, 123, "123 and 123 should be equal")
  45. //
  46. // Returns whether the assertion was successful (true) or not (false).
  47. func Equal(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  48. if !assert.Equal(t, expected, actual, msgAndArgs...) {
  49. t.FailNow()
  50. }
  51. }
  52. // EqualError asserts that a function returned an error (i.e. not `nil`)
  53. // and that it is equal to the provided error.
  54. //
  55. // actualObj, err := SomeFunction()
  56. // if assert.Error(t, err, "An error was expected") {
  57. // assert.Equal(t, err, expectedError)
  58. // }
  59. //
  60. // Returns whether the assertion was successful (true) or not (false).
  61. func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) {
  62. if !assert.EqualError(t, theError, errString, msgAndArgs...) {
  63. t.FailNow()
  64. }
  65. }
  66. // EqualValues asserts that two objects are equal or convertable to the same types
  67. // and equal.
  68. //
  69. // assert.EqualValues(t, uint32(123), int32(123), "123 and 123 should be equal")
  70. //
  71. // Returns whether the assertion was successful (true) or not (false).
  72. func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  73. if !assert.EqualValues(t, expected, actual, msgAndArgs...) {
  74. t.FailNow()
  75. }
  76. }
  77. // Error asserts that a function returned an error (i.e. not `nil`).
  78. //
  79. // actualObj, err := SomeFunction()
  80. // if assert.Error(t, err, "An error was expected") {
  81. // assert.Equal(t, err, expectedError)
  82. // }
  83. //
  84. // Returns whether the assertion was successful (true) or not (false).
  85. func Error(t TestingT, err error, msgAndArgs ...interface{}) {
  86. if !assert.Error(t, err, msgAndArgs...) {
  87. t.FailNow()
  88. }
  89. }
  90. // Exactly asserts that two objects are equal is value and type.
  91. //
  92. // assert.Exactly(t, int32(123), int64(123), "123 and 123 should NOT be equal")
  93. //
  94. // Returns whether the assertion was successful (true) or not (false).
  95. func Exactly(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  96. if !assert.Exactly(t, expected, actual, msgAndArgs...) {
  97. t.FailNow()
  98. }
  99. }
  100. // Fail reports a failure through
  101. func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) {
  102. if !assert.Fail(t, failureMessage, msgAndArgs...) {
  103. t.FailNow()
  104. }
  105. }
  106. // FailNow fails test
  107. func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) {
  108. if !assert.FailNow(t, failureMessage, msgAndArgs...) {
  109. t.FailNow()
  110. }
  111. }
  112. // False asserts that the specified value is false.
  113. //
  114. // assert.False(t, myBool, "myBool should be false")
  115. //
  116. // Returns whether the assertion was successful (true) or not (false).
  117. func False(t TestingT, value bool, msgAndArgs ...interface{}) {
  118. if !assert.False(t, value, msgAndArgs...) {
  119. t.FailNow()
  120. }
  121. }
  122. // HTTPBodyContains asserts that a specified handler returns a
  123. // body that contains a string.
  124. //
  125. // assert.HTTPBodyContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky")
  126. //
  127. // Returns whether the assertion was successful (true) or not (false).
  128. func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}) {
  129. if !assert.HTTPBodyContains(t, handler, method, url, values, str) {
  130. t.FailNow()
  131. }
  132. }
  133. // HTTPBodyNotContains asserts that a specified handler returns a
  134. // body that does not contain a string.
  135. //
  136. // assert.HTTPBodyNotContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky")
  137. //
  138. // Returns whether the assertion was successful (true) or not (false).
  139. func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}) {
  140. if !assert.HTTPBodyNotContains(t, handler, method, url, values, str) {
  141. t.FailNow()
  142. }
  143. }
  144. // HTTPError asserts that a specified handler returns an error status code.
  145. //
  146. // assert.HTTPError(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
  147. //
  148. // Returns whether the assertion was successful (true) or not (false).
  149. func HTTPError(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values) {
  150. if !assert.HTTPError(t, handler, method, url, values) {
  151. t.FailNow()
  152. }
  153. }
  154. // HTTPRedirect asserts that a specified handler returns a redirect status code.
  155. //
  156. // assert.HTTPRedirect(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
  157. //
  158. // Returns whether the assertion was successful (true) or not (false).
  159. func HTTPRedirect(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values) {
  160. if !assert.HTTPRedirect(t, handler, method, url, values) {
  161. t.FailNow()
  162. }
  163. }
  164. // HTTPSuccess asserts that a specified handler returns a success status code.
  165. //
  166. // assert.HTTPSuccess(t, myHandler, "POST", "http://www.google.com", nil)
  167. //
  168. // Returns whether the assertion was successful (true) or not (false).
  169. func HTTPSuccess(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values) {
  170. if !assert.HTTPSuccess(t, handler, method, url, values) {
  171. t.FailNow()
  172. }
  173. }
  174. // Implements asserts that an object is implemented by the specified interface.
  175. //
  176. // assert.Implements(t, (*MyInterface)(nil), new(MyObject), "MyObject")
  177. func Implements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) {
  178. if !assert.Implements(t, interfaceObject, object, msgAndArgs...) {
  179. t.FailNow()
  180. }
  181. }
  182. // InDelta asserts that the two numerals are within delta of each other.
  183. //
  184. // assert.InDelta(t, math.Pi, (22 / 7.0), 0.01)
  185. //
  186. // Returns whether the assertion was successful (true) or not (false).
  187. func InDelta(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
  188. if !assert.InDelta(t, expected, actual, delta, msgAndArgs...) {
  189. t.FailNow()
  190. }
  191. }
  192. // InDeltaSlice is the same as InDelta, except it compares two slices.
  193. func InDeltaSlice(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
  194. if !assert.InDeltaSlice(t, expected, actual, delta, msgAndArgs...) {
  195. t.FailNow()
  196. }
  197. }
  198. // InEpsilon asserts that expected and actual have a relative error less than epsilon
  199. //
  200. // Returns whether the assertion was successful (true) or not (false).
  201. func InEpsilon(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) {
  202. if !assert.InEpsilon(t, expected, actual, epsilon, msgAndArgs...) {
  203. t.FailNow()
  204. }
  205. }
  206. // InEpsilonSlice is the same as InEpsilon, except it compares two slices.
  207. func InEpsilonSlice(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
  208. if !assert.InEpsilonSlice(t, expected, actual, delta, msgAndArgs...) {
  209. t.FailNow()
  210. }
  211. }
  212. // IsType asserts that the specified objects are of the same type.
  213. func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) {
  214. if !assert.IsType(t, expectedType, object, msgAndArgs...) {
  215. t.FailNow()
  216. }
  217. }
  218. // JSONEq asserts that two JSON strings are equivalent.
  219. //
  220. // assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
  221. //
  222. // Returns whether the assertion was successful (true) or not (false).
  223. func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) {
  224. if !assert.JSONEq(t, expected, actual, msgAndArgs...) {
  225. t.FailNow()
  226. }
  227. }
  228. // Len asserts that the specified object has specific length.
  229. // Len also fails if the object has a type that len() not accept.
  230. //
  231. // assert.Len(t, mySlice, 3, "The size of slice is not 3")
  232. //
  233. // Returns whether the assertion was successful (true) or not (false).
  234. func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) {
  235. if !assert.Len(t, object, length, msgAndArgs...) {
  236. t.FailNow()
  237. }
  238. }
  239. // Nil asserts that the specified object is nil.
  240. //
  241. // assert.Nil(t, err, "err should be nothing")
  242. //
  243. // Returns whether the assertion was successful (true) or not (false).
  244. func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  245. if !assert.Nil(t, object, msgAndArgs...) {
  246. t.FailNow()
  247. }
  248. }
  249. // NoError asserts that a function returned no error (i.e. `nil`).
  250. //
  251. // actualObj, err := SomeFunction()
  252. // if assert.NoError(t, err) {
  253. // assert.Equal(t, actualObj, expectedObj)
  254. // }
  255. //
  256. // Returns whether the assertion was successful (true) or not (false).
  257. func NoError(t TestingT, err error, msgAndArgs ...interface{}) {
  258. if !assert.NoError(t, err, msgAndArgs...) {
  259. t.FailNow()
  260. }
  261. }
  262. // NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the
  263. // specified substring or element.
  264. //
  265. // assert.NotContains(t, "Hello World", "Earth", "But 'Hello World' does NOT contain 'Earth'")
  266. // assert.NotContains(t, ["Hello", "World"], "Earth", "But ['Hello', 'World'] does NOT contain 'Earth'")
  267. // assert.NotContains(t, {"Hello": "World"}, "Earth", "But {'Hello': 'World'} does NOT contain 'Earth'")
  268. //
  269. // Returns whether the assertion was successful (true) or not (false).
  270. func NotContains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) {
  271. if !assert.NotContains(t, s, contains, msgAndArgs...) {
  272. t.FailNow()
  273. }
  274. }
  275. // NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
  276. // a slice or a channel with len == 0.
  277. //
  278. // if assert.NotEmpty(t, obj) {
  279. // assert.Equal(t, "two", obj[1])
  280. // }
  281. //
  282. // Returns whether the assertion was successful (true) or not (false).
  283. func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  284. if !assert.NotEmpty(t, object, msgAndArgs...) {
  285. t.FailNow()
  286. }
  287. }
  288. // NotEqual asserts that the specified values are NOT equal.
  289. //
  290. // assert.NotEqual(t, obj1, obj2, "two objects shouldn't be equal")
  291. //
  292. // Returns whether the assertion was successful (true) or not (false).
  293. func NotEqual(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
  294. if !assert.NotEqual(t, expected, actual, msgAndArgs...) {
  295. t.FailNow()
  296. }
  297. }
  298. // NotNil asserts that the specified object is not nil.
  299. //
  300. // assert.NotNil(t, err, "err should be something")
  301. //
  302. // Returns whether the assertion was successful (true) or not (false).
  303. func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) {
  304. if !assert.NotNil(t, object, msgAndArgs...) {
  305. t.FailNow()
  306. }
  307. }
  308. // NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.
  309. //
  310. // assert.NotPanics(t, func(){
  311. // RemainCalm()
  312. // }, "Calling RemainCalm() should NOT panic")
  313. //
  314. // Returns whether the assertion was successful (true) or not (false).
  315. func NotPanics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
  316. if !assert.NotPanics(t, f, msgAndArgs...) {
  317. t.FailNow()
  318. }
  319. }
  320. // NotRegexp asserts that a specified regexp does not match a string.
  321. //
  322. // assert.NotRegexp(t, regexp.MustCompile("starts"), "it's starting")
  323. // assert.NotRegexp(t, "^start", "it's not starting")
  324. //
  325. // Returns whether the assertion was successful (true) or not (false).
  326. func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) {
  327. if !assert.NotRegexp(t, rx, str, msgAndArgs...) {
  328. t.FailNow()
  329. }
  330. }
  331. // NotZero asserts that i is not the zero value for its type and returns the truth.
  332. func NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) {
  333. if !assert.NotZero(t, i, msgAndArgs...) {
  334. t.FailNow()
  335. }
  336. }
  337. // Panics asserts that the code inside the specified PanicTestFunc panics.
  338. //
  339. // assert.Panics(t, func(){
  340. // GoCrazy()
  341. // }, "Calling GoCrazy() should panic")
  342. //
  343. // Returns whether the assertion was successful (true) or not (false).
  344. func Panics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
  345. if !assert.Panics(t, f, msgAndArgs...) {
  346. t.FailNow()
  347. }
  348. }
  349. // Regexp asserts that a specified regexp matches a string.
  350. //
  351. // assert.Regexp(t, regexp.MustCompile("start"), "it's starting")
  352. // assert.Regexp(t, "start...$", "it's not starting")
  353. //
  354. // Returns whether the assertion was successful (true) or not (false).
  355. func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) {
  356. if !assert.Regexp(t, rx, str, msgAndArgs...) {
  357. t.FailNow()
  358. }
  359. }
  360. // True asserts that the specified value is true.
  361. //
  362. // assert.True(t, myBool, "myBool should be true")
  363. //
  364. // Returns whether the assertion was successful (true) or not (false).
  365. func True(t TestingT, value bool, msgAndArgs ...interface{}) {
  366. if !assert.True(t, value, msgAndArgs...) {
  367. t.FailNow()
  368. }
  369. }
  370. // WithinDuration asserts that the two times are within duration delta of each other.
  371. //
  372. // assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second, "The difference should not be more than 10s")
  373. //
  374. // Returns whether the assertion was successful (true) or not (false).
  375. func WithinDuration(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) {
  376. if !assert.WithinDuration(t, expected, actual, delta, msgAndArgs...) {
  377. t.FailNow()
  378. }
  379. }
  380. // Zero asserts that i is the zero value for its type and returns the truth.
  381. func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) {
  382. if !assert.Zero(t, i, msgAndArgs...) {
  383. t.FailNow()
  384. }
  385. }