1
0

require.go 15 KB

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