Micro & pluggable web framework for Go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1674 lines
35KB

  1. // Copyright 2015 The Tango Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package tango
  5. import (
  6. "bytes"
  7. "fmt"
  8. "net/http"
  9. "net/http/httptest"
  10. "strings"
  11. "testing"
  12. "time"
  13. )
  14. func TestCookie1(t *testing.T) {
  15. buff := bytes.NewBufferString("")
  16. recorder := httptest.NewRecorder()
  17. recorder.Body = buff
  18. o := Classic()
  19. o.Get("/", func(ctx *Context) string {
  20. ck := ctx.Cookies().Get("name")
  21. if ck != nil {
  22. return ck.Value
  23. }
  24. return ""
  25. })
  26. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  27. if err != nil {
  28. t.Error(err)
  29. }
  30. req.AddCookie(NewCookie("name", "test"))
  31. o.ServeHTTP(recorder, req)
  32. expect(t, recorder.Code, http.StatusOK)
  33. refute(t, len(buff.String()), 0)
  34. expect(t, buff.String(), "test")
  35. }
  36. func TestCookie2(t *testing.T) {
  37. buff := bytes.NewBufferString("")
  38. recorder := httptest.NewRecorder()
  39. recorder.Body = buff
  40. o := Classic()
  41. o.Get("/", func(ctx *Context) string {
  42. ctx.Cookies().Set(NewCookie("name", "test"))
  43. return "test"
  44. })
  45. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  46. if err != nil {
  47. t.Error(err)
  48. }
  49. o.ServeHTTP(recorder, req)
  50. expect(t, recorder.Code, http.StatusOK)
  51. refute(t, len(buff.String()), 0)
  52. expect(t, buff.String(), "test")
  53. expect(t, strings.Split(recorder.Header().Get("Set-Cookie"), ";")[0], "name=test")
  54. }
  55. func TestCookie3(t *testing.T) {
  56. buff := bytes.NewBufferString("")
  57. recorder := httptest.NewRecorder()
  58. recorder.Body = buff
  59. o := Classic()
  60. o.Get("/", func(ctx *Context) string {
  61. ctx.Cookies().Expire("expire", time.Now())
  62. return "test"
  63. })
  64. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  65. if err != nil {
  66. t.Error(err)
  67. }
  68. req.AddCookie(NewCookie("expire", "test"))
  69. o.ServeHTTP(recorder, req)
  70. expect(t, recorder.Code, http.StatusOK)
  71. refute(t, len(buff.String()), 0)
  72. expect(t, buff.String(), "test")
  73. fmt.Println(recorder.Header().Get("Set-Cookie"))
  74. expect(t, strings.Split(recorder.Header().Get("Set-Cookie"), ";")[0], "expire=test")
  75. }
  76. func TestCookie4(t *testing.T) {
  77. buff := bytes.NewBufferString("")
  78. recorder := httptest.NewRecorder()
  79. recorder.Body = buff
  80. o := Classic()
  81. o.Get("/", func(ctx *Context) string {
  82. ctx.Cookies().Del("ttttt")
  83. return "test"
  84. })
  85. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  86. if err != nil {
  87. t.Error(err)
  88. }
  89. req.AddCookie(NewCookie("ttttt", "test"))
  90. o.ServeHTTP(recorder, req)
  91. expect(t, recorder.Code, http.StatusOK)
  92. refute(t, len(buff.String()), 0)
  93. expect(t, buff.String(), "test")
  94. //expect(t, recorder.Header().Get("Set-Cookie"), "ttttt=test; Max-Age=0")
  95. }
  96. func TestCookie5(t *testing.T) {
  97. buff := bytes.NewBufferString("")
  98. recorder := httptest.NewRecorder()
  99. recorder.Body = buff
  100. o := Classic()
  101. o.Get("/", func(ctx *Context) string {
  102. ck := ctx.SecureCookies("sssss").Get("name")
  103. if ck != nil {
  104. return ck.Value
  105. }
  106. return ""
  107. })
  108. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  109. if err != nil {
  110. t.Error(err)
  111. }
  112. req.AddCookie(NewSecureCookie("sssss", "name", "test"))
  113. o.ServeHTTP(recorder, req)
  114. expect(t, recorder.Code, http.StatusOK)
  115. refute(t, len(buff.String()), 0)
  116. expect(t, buff.String(), "test")
  117. }
  118. func TestCookie6(t *testing.T) {
  119. buff := bytes.NewBufferString("")
  120. recorder := httptest.NewRecorder()
  121. recorder.Body = buff
  122. o := Classic()
  123. o.Get("/", func(ctx *Context) string {
  124. ctx.SecureCookies("ttttt").Set(NewSecureCookie("ttttt", "name", "test"))
  125. return "test"
  126. })
  127. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  128. if err != nil {
  129. t.Error(err)
  130. }
  131. o.ServeHTTP(recorder, req)
  132. expect(t, recorder.Code, http.StatusOK)
  133. refute(t, len(buff.String()), 0)
  134. expect(t, buff.String(), "test")
  135. r := strings.Split(recorder.Header().Get("Set-Cookie"), ";")[0]
  136. s := strings.SplitN(r, "=", 2)
  137. name, value := s[0], s[1]
  138. expect(t, name, "name")
  139. expect(t, parseSecureCookie("ttttt", value), "test")
  140. }
  141. func TestCookie7(t *testing.T) {
  142. buff := bytes.NewBufferString("")
  143. recorder := httptest.NewRecorder()
  144. recorder.Body = buff
  145. o := Classic()
  146. o.Get("/", func(ctx *Context) string {
  147. ctx.SecureCookies("ttttt").Expire("expire", time.Now())
  148. return "test"
  149. })
  150. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  151. if err != nil {
  152. t.Error(err)
  153. }
  154. req.AddCookie(NewSecureCookie("ttttt", "expire", "test"))
  155. o.ServeHTTP(recorder, req)
  156. expect(t, recorder.Code, http.StatusOK)
  157. refute(t, len(buff.String()), 0)
  158. expect(t, buff.String(), "test")
  159. expect(t, strings.Split(recorder.Header().Get("Set-Cookie"), "|")[0], "expire=test")
  160. }
  161. func TestCookie8(t *testing.T) {
  162. buff := bytes.NewBufferString("")
  163. recorder := httptest.NewRecorder()
  164. recorder.Body = buff
  165. o := Classic()
  166. o.Get("/", func(ctx *Context) string {
  167. ctx.SecureCookies("ttttt").Del("ttttt")
  168. return "test"
  169. })
  170. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  171. if err != nil {
  172. t.Error(err)
  173. }
  174. req.AddCookie(NewSecureCookie("ttttt", "ttttt", "test"))
  175. o.ServeHTTP(recorder, req)
  176. expect(t, recorder.Code, http.StatusOK)
  177. refute(t, len(buff.String()), 0)
  178. expect(t, buff.String(), "test")
  179. expect(t, strings.Split(recorder.Header().Get("Set-Cookie"), "|")[0], "ttttt=test")
  180. }
  181. type Cookie11Action struct {
  182. Ctx
  183. }
  184. func (a *Cookie11Action) Get() string {
  185. v, _ := a.Cookies().Int("test")
  186. return fmt.Sprintf("%d", v)
  187. }
  188. func TestCookie11(t *testing.T) {
  189. buff := bytes.NewBufferString("")
  190. recorder := httptest.NewRecorder()
  191. recorder.Body = buff
  192. o := Classic()
  193. o.Get("/", new(Cookie11Action))
  194. req, err := http.NewRequest("GET", "http://localhost:8000", nil)
  195. if err != nil {
  196. t.Error(err)
  197. }
  198. req.AddCookie(NewCookie("test", "1"))
  199. o.ServeHTTP(recorder, req)
  200. expect(t, recorder.Code, http.StatusOK)
  201. refute(t, len(buff.String()), 0)
  202. expect(t, buff.String(), "1")
  203. }
  204. type Cookie12Action struct {
  205. Ctx
  206. }
  207. func (a *Cookie12Action) Get() string {
  208. v, _ := a.Cookies().Int32("test")
  209. return fmt.Sprintf("%d", v)
  210. }
  211. func TestCookie12(t *testing.T) {
  212. buff := bytes.NewBufferString("")
  213. recorder := httptest.NewRecorder()
  214. recorder.Body = buff
  215. o := Classic()
  216. o.Get("/", new(Cookie12Action))
  217. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  218. if err != nil {
  219. t.Error(err)
  220. }
  221. req.AddCookie(NewCookie("test", "1"))
  222. o.ServeHTTP(recorder, req)
  223. expect(t, recorder.Code, http.StatusOK)
  224. refute(t, len(buff.String()), 0)
  225. expect(t, buff.String(), "1")
  226. }
  227. type Cookie13Action struct {
  228. Ctx
  229. }
  230. func (a *Cookie13Action) Get() string {
  231. v, _ := a.Cookies().Int64("test")
  232. return fmt.Sprintf("%d", v)
  233. }
  234. func TestCookie13(t *testing.T) {
  235. buff := bytes.NewBufferString("")
  236. recorder := httptest.NewRecorder()
  237. recorder.Body = buff
  238. o := Classic()
  239. o.Get("/", new(Cookie13Action))
  240. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  241. if err != nil {
  242. t.Error(err)
  243. }
  244. req.AddCookie(NewCookie("test", "1"))
  245. o.ServeHTTP(recorder, req)
  246. expect(t, recorder.Code, http.StatusOK)
  247. refute(t, len(buff.String()), 0)
  248. expect(t, buff.String(), "1")
  249. }
  250. type Cookie14Action struct {
  251. Ctx
  252. }
  253. func (a *Cookie14Action) Get() string {
  254. v, _ := a.Cookies().Uint("test")
  255. return fmt.Sprintf("%d", v)
  256. }
  257. func TestCookie14(t *testing.T) {
  258. buff := bytes.NewBufferString("")
  259. recorder := httptest.NewRecorder()
  260. recorder.Body = buff
  261. o := Classic()
  262. o.Get("/", new(Cookie14Action))
  263. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  264. if err != nil {
  265. t.Error(err)
  266. }
  267. req.AddCookie(NewCookie("test", "1"))
  268. o.ServeHTTP(recorder, req)
  269. expect(t, recorder.Code, http.StatusOK)
  270. refute(t, len(buff.String()), 0)
  271. expect(t, buff.String(), "1")
  272. }
  273. type Cookie15Action struct {
  274. Ctx
  275. }
  276. func (a *Cookie15Action) Get() string {
  277. v, _ := a.Cookies().Uint32("test")
  278. return fmt.Sprintf("%d", v)
  279. }
  280. func TestCookie15(t *testing.T) {
  281. buff := bytes.NewBufferString("")
  282. recorder := httptest.NewRecorder()
  283. recorder.Body = buff
  284. o := Classic()
  285. o.Get("/", new(Cookie15Action))
  286. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  287. if err != nil {
  288. t.Error(err)
  289. }
  290. req.AddCookie(NewCookie("test", "1"))
  291. o.ServeHTTP(recorder, req)
  292. expect(t, recorder.Code, http.StatusOK)
  293. refute(t, len(buff.String()), 0)
  294. expect(t, buff.String(), "1")
  295. }
  296. type Cookie16Action struct {
  297. Ctx
  298. }
  299. func (a *Cookie16Action) Get() string {
  300. v, _ := a.Cookies().Uint64("test")
  301. return fmt.Sprintf("%d", v)
  302. }
  303. func TestCookie16(t *testing.T) {
  304. buff := bytes.NewBufferString("")
  305. recorder := httptest.NewRecorder()
  306. recorder.Body = buff
  307. o := Classic()
  308. o.Get("/", new(Cookie16Action))
  309. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  310. if err != nil {
  311. t.Error(err)
  312. }
  313. req.AddCookie(NewCookie("test", "1"))
  314. o.ServeHTTP(recorder, req)
  315. expect(t, recorder.Code, http.StatusOK)
  316. refute(t, len(buff.String()), 0)
  317. expect(t, buff.String(), "1")
  318. }
  319. type Cookie17Action struct {
  320. Ctx
  321. }
  322. func (a *Cookie17Action) Get() string {
  323. v, _ := a.Cookies().Float32("test")
  324. return fmt.Sprintf("%.2f", v)
  325. }
  326. func TestCookie17(t *testing.T) {
  327. buff := bytes.NewBufferString("")
  328. recorder := httptest.NewRecorder()
  329. recorder.Body = buff
  330. o := Classic()
  331. o.Get("/", new(Cookie17Action))
  332. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  333. if err != nil {
  334. t.Error(err)
  335. }
  336. req.AddCookie(NewCookie("test", "1"))
  337. o.ServeHTTP(recorder, req)
  338. expect(t, recorder.Code, http.StatusOK)
  339. refute(t, len(buff.String()), 0)
  340. expect(t, buff.String(), "1.00")
  341. }
  342. type Cookie18Action struct {
  343. Ctx
  344. }
  345. func (a *Cookie18Action) Get() string {
  346. v, _ := a.Cookies().Float64("test")
  347. return fmt.Sprintf("%.2f", v)
  348. }
  349. func TestCookie18(t *testing.T) {
  350. buff := bytes.NewBufferString("")
  351. recorder := httptest.NewRecorder()
  352. recorder.Body = buff
  353. o := Classic()
  354. o.Get("/", new(Cookie18Action))
  355. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  356. if err != nil {
  357. t.Error(err)
  358. }
  359. req.AddCookie(NewCookie("test", "1"))
  360. o.ServeHTTP(recorder, req)
  361. expect(t, recorder.Code, http.StatusOK)
  362. refute(t, len(buff.String()), 0)
  363. expect(t, buff.String(), "1.00")
  364. }
  365. type Cookie19Action struct {
  366. Ctx
  367. }
  368. func (a *Cookie19Action) Get() string {
  369. v, _ := a.Cookies().Bool("test")
  370. return fmt.Sprintf("%v", v)
  371. }
  372. func TestCookie19(t *testing.T) {
  373. buff := bytes.NewBufferString("")
  374. recorder := httptest.NewRecorder()
  375. recorder.Body = buff
  376. o := Classic()
  377. o.Get("/", new(Cookie19Action))
  378. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  379. if err != nil {
  380. t.Error(err)
  381. }
  382. req.AddCookie(NewCookie("test", "1"))
  383. o.ServeHTTP(recorder, req)
  384. expect(t, recorder.Code, http.StatusOK)
  385. refute(t, len(buff.String()), 0)
  386. expect(t, buff.String(), "true")
  387. }
  388. type Cookie20Action struct {
  389. Ctx
  390. }
  391. func (a *Cookie20Action) Get() string {
  392. v, _ := a.Cookies().String("test")
  393. return fmt.Sprintf("%v", v)
  394. }
  395. func TestCookie20(t *testing.T) {
  396. buff := bytes.NewBufferString("")
  397. recorder := httptest.NewRecorder()
  398. recorder.Body = buff
  399. o := Classic()
  400. o.Get("/", new(Cookie20Action))
  401. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  402. if err != nil {
  403. t.Error(err)
  404. }
  405. req.AddCookie(NewCookie("test", "1"))
  406. o.ServeHTTP(recorder, req)
  407. expect(t, recorder.Code, http.StatusOK)
  408. refute(t, len(buff.String()), 0)
  409. expect(t, buff.String(), "1")
  410. }
  411. type Cookie21Action struct {
  412. Ctx
  413. }
  414. func (a *Cookie21Action) Get() string {
  415. v := a.Cookies().MustInt("test")
  416. return fmt.Sprintf("%d", v)
  417. }
  418. func TestCookie21(t *testing.T) {
  419. buff := bytes.NewBufferString("")
  420. recorder := httptest.NewRecorder()
  421. recorder.Body = buff
  422. o := Classic()
  423. o.Get("/", new(Cookie21Action))
  424. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  425. if err != nil {
  426. t.Error(err)
  427. }
  428. req.AddCookie(NewCookie("test", "1"))
  429. o.ServeHTTP(recorder, req)
  430. expect(t, recorder.Code, http.StatusOK)
  431. refute(t, len(buff.String()), 0)
  432. expect(t, buff.String(), "1")
  433. }
  434. type Cookie22Action struct {
  435. Ctx
  436. }
  437. func (a *Cookie22Action) Get() string {
  438. v := a.Cookies().MustInt32("test")
  439. return fmt.Sprintf("%d", v)
  440. }
  441. func TestCookie22(t *testing.T) {
  442. buff := bytes.NewBufferString("")
  443. recorder := httptest.NewRecorder()
  444. recorder.Body = buff
  445. o := Classic()
  446. o.Get("/", new(Cookie22Action))
  447. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  448. if err != nil {
  449. t.Error(err)
  450. }
  451. req.AddCookie(NewCookie("test", "1"))
  452. o.ServeHTTP(recorder, req)
  453. expect(t, recorder.Code, http.StatusOK)
  454. refute(t, len(buff.String()), 0)
  455. expect(t, buff.String(), "1")
  456. }
  457. type Cookie23Action struct {
  458. Ctx
  459. }
  460. func (a *Cookie23Action) Get() string {
  461. v := a.Cookies().MustInt64("test")
  462. return fmt.Sprintf("%d", v)
  463. }
  464. func TestCookie23(t *testing.T) {
  465. buff := bytes.NewBufferString("")
  466. recorder := httptest.NewRecorder()
  467. recorder.Body = buff
  468. o := Classic()
  469. o.Get("/", new(Cookie23Action))
  470. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  471. if err != nil {
  472. t.Error(err)
  473. }
  474. req.AddCookie(NewCookie("test", "1"))
  475. o.ServeHTTP(recorder, req)
  476. expect(t, recorder.Code, http.StatusOK)
  477. refute(t, len(buff.String()), 0)
  478. expect(t, buff.String(), "1")
  479. }
  480. type Cookie24Action struct {
  481. Ctx
  482. }
  483. func (a *Cookie24Action) Get() string {
  484. v := a.Cookies().MustUint("test")
  485. return fmt.Sprintf("%d", v)
  486. }
  487. func TestCookie24(t *testing.T) {
  488. buff := bytes.NewBufferString("")
  489. recorder := httptest.NewRecorder()
  490. recorder.Body = buff
  491. o := Classic()
  492. o.Get("/", new(Cookie24Action))
  493. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  494. if err != nil {
  495. t.Error(err)
  496. }
  497. req.AddCookie(NewCookie("test", "1"))
  498. o.ServeHTTP(recorder, req)
  499. expect(t, recorder.Code, http.StatusOK)
  500. refute(t, len(buff.String()), 0)
  501. expect(t, buff.String(), "1")
  502. }
  503. type Cookie25Action struct {
  504. Ctx
  505. }
  506. func (a *Cookie25Action) Get() string {
  507. v := a.Cookies().MustUint32("test")
  508. return fmt.Sprintf("%d", v)
  509. }
  510. func TestCookie25(t *testing.T) {
  511. buff := bytes.NewBufferString("")
  512. recorder := httptest.NewRecorder()
  513. recorder.Body = buff
  514. o := Classic()
  515. o.Get("/", new(Cookie25Action))
  516. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  517. if err != nil {
  518. t.Error(err)
  519. }
  520. req.AddCookie(NewCookie("test", "1"))
  521. o.ServeHTTP(recorder, req)
  522. expect(t, recorder.Code, http.StatusOK)
  523. refute(t, len(buff.String()), 0)
  524. expect(t, buff.String(), "1")
  525. }
  526. type Cookie26Action struct {
  527. Ctx
  528. }
  529. func (a *Cookie26Action) Get() string {
  530. v := a.Cookies().MustUint64("test")
  531. return fmt.Sprintf("%d", v)
  532. }
  533. func TestCookie26(t *testing.T) {
  534. buff := bytes.NewBufferString("")
  535. recorder := httptest.NewRecorder()
  536. recorder.Body = buff
  537. o := Classic()
  538. o.Get("/", new(Cookie26Action))
  539. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  540. if err != nil {
  541. t.Error(err)
  542. }
  543. req.AddCookie(NewCookie("test", "1"))
  544. o.ServeHTTP(recorder, req)
  545. expect(t, recorder.Code, http.StatusOK)
  546. refute(t, len(buff.String()), 0)
  547. expect(t, buff.String(), "1")
  548. }
  549. type Cookie27Action struct {
  550. Ctx
  551. }
  552. func (a *Cookie27Action) Get() string {
  553. v := a.Cookies().MustFloat32("test")
  554. return fmt.Sprintf("%.2f", v)
  555. }
  556. func TestCookie27(t *testing.T) {
  557. buff := bytes.NewBufferString("")
  558. recorder := httptest.NewRecorder()
  559. recorder.Body = buff
  560. o := Classic()
  561. o.Get("/", new(Cookie27Action))
  562. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  563. if err != nil {
  564. t.Error(err)
  565. }
  566. req.AddCookie(NewCookie("test", "1"))
  567. o.ServeHTTP(recorder, req)
  568. expect(t, recorder.Code, http.StatusOK)
  569. refute(t, len(buff.String()), 0)
  570. expect(t, buff.String(), "1.00")
  571. }
  572. type Cookie28Action struct {
  573. Ctx
  574. }
  575. func (a *Cookie28Action) Get() string {
  576. v := a.Cookies().MustFloat64("test")
  577. return fmt.Sprintf("%.2f", v)
  578. }
  579. func TestCookie28(t *testing.T) {
  580. buff := bytes.NewBufferString("")
  581. recorder := httptest.NewRecorder()
  582. recorder.Body = buff
  583. o := Classic()
  584. o.Get("/", new(Cookie28Action))
  585. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  586. if err != nil {
  587. t.Error(err)
  588. }
  589. req.AddCookie(NewCookie("test", "1"))
  590. o.ServeHTTP(recorder, req)
  591. expect(t, recorder.Code, http.StatusOK)
  592. refute(t, len(buff.String()), 0)
  593. expect(t, buff.String(), "1.00")
  594. }
  595. type Cookie29Action struct {
  596. Ctx
  597. }
  598. func (a *Cookie29Action) Get() string {
  599. v := a.Cookies().MustBool("test")
  600. return fmt.Sprintf("%v", v)
  601. }
  602. func TestCookie29(t *testing.T) {
  603. buff := bytes.NewBufferString("")
  604. recorder := httptest.NewRecorder()
  605. recorder.Body = buff
  606. o := Classic()
  607. o.Get("/", new(Cookie29Action))
  608. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  609. if err != nil {
  610. t.Error(err)
  611. }
  612. req.AddCookie(NewCookie("test", "1"))
  613. o.ServeHTTP(recorder, req)
  614. expect(t, recorder.Code, http.StatusOK)
  615. refute(t, len(buff.String()), 0)
  616. expect(t, buff.String(), "true")
  617. }
  618. type Cookie30Action struct {
  619. Ctx
  620. }
  621. func (a *Cookie30Action) Get() string {
  622. v := a.Cookies().MustString("test")
  623. return fmt.Sprintf("%s", v)
  624. }
  625. func TestCookie30(t *testing.T) {
  626. buff := bytes.NewBufferString("")
  627. recorder := httptest.NewRecorder()
  628. recorder.Body = buff
  629. o := Classic()
  630. o.Get("/", new(Cookie30Action))
  631. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  632. if err != nil {
  633. t.Error(err)
  634. }
  635. req.AddCookie(NewCookie("test", "1"))
  636. o.ServeHTTP(recorder, req)
  637. expect(t, recorder.Code, http.StatusOK)
  638. refute(t, len(buff.String()), 0)
  639. expect(t, buff.String(), "1")
  640. }
  641. const (
  642. secrectCookie = "ssss"
  643. )
  644. type Cookie31Action struct {
  645. Ctx
  646. }
  647. func (a *Cookie31Action) Get() string {
  648. v, _ := a.SecureCookies(secrectCookie).Int("test")
  649. return fmt.Sprintf("%d", v)
  650. }
  651. func TestCookie31(t *testing.T) {
  652. buff := bytes.NewBufferString("")
  653. recorder := httptest.NewRecorder()
  654. recorder.Body = buff
  655. o := Classic()
  656. o.Get("/", new(Cookie31Action))
  657. req, err := http.NewRequest("GET", "http://localhost:8000", nil)
  658. if err != nil {
  659. t.Error(err)
  660. }
  661. req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
  662. o.ServeHTTP(recorder, req)
  663. expect(t, recorder.Code, http.StatusOK)
  664. refute(t, len(buff.String()), 0)
  665. expect(t, buff.String(), "1")
  666. }
  667. type Cookie32Action struct {
  668. Ctx
  669. }
  670. func (a *Cookie32Action) Get() string {
  671. v, _ := a.SecureCookies(secrectCookie).Int32("test")
  672. return fmt.Sprintf("%d", v)
  673. }
  674. func TestCookie32(t *testing.T) {
  675. buff := bytes.NewBufferString("")
  676. recorder := httptest.NewRecorder()
  677. recorder.Body = buff
  678. o := Classic()
  679. o.Get("/", new(Cookie32Action))
  680. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  681. if err != nil {
  682. t.Error(err)
  683. }
  684. req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
  685. o.ServeHTTP(recorder, req)
  686. expect(t, recorder.Code, http.StatusOK)
  687. refute(t, len(buff.String()), 0)
  688. expect(t, buff.String(), "1")
  689. }
  690. type Cookie33Action struct {
  691. Ctx
  692. }
  693. func (a *Cookie33Action) Get() string {
  694. v, _ := a.SecureCookies(secrectCookie).Int64("test")
  695. return fmt.Sprintf("%d", v)
  696. }
  697. func TestCookie33(t *testing.T) {
  698. buff := bytes.NewBufferString("")
  699. recorder := httptest.NewRecorder()
  700. recorder.Body = buff
  701. o := Classic()
  702. o.Get("/", new(Cookie33Action))
  703. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  704. if err != nil {
  705. t.Error(err)
  706. }
  707. req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
  708. o.ServeHTTP(recorder, req)
  709. expect(t, recorder.Code, http.StatusOK)
  710. refute(t, len(buff.String()), 0)
  711. expect(t, buff.String(), "1")
  712. }
  713. type Cookie34Action struct {
  714. Ctx
  715. }
  716. func (a *Cookie34Action) Get() string {
  717. v, _ := a.SecureCookies(secrectCookie).Uint("test")
  718. return fmt.Sprintf("%d", v)
  719. }
  720. func TestCookie34(t *testing.T) {
  721. buff := bytes.NewBufferString("")
  722. recorder := httptest.NewRecorder()
  723. recorder.Body = buff
  724. o := Classic()
  725. o.Get("/", new(Cookie34Action))
  726. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  727. if err != nil {
  728. t.Error(err)
  729. }
  730. req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
  731. o.ServeHTTP(recorder, req)
  732. expect(t, recorder.Code, http.StatusOK)
  733. refute(t, len(buff.String()), 0)
  734. expect(t, buff.String(), "1")
  735. }
  736. type Cookie35Action struct {
  737. Ctx
  738. }
  739. func (a *Cookie35Action) Get() string {
  740. v, _ := a.SecureCookies(secrectCookie).Uint32("test")
  741. return fmt.Sprintf("%d", v)
  742. }
  743. func TestCookie35(t *testing.T) {
  744. buff := bytes.NewBufferString("")
  745. recorder := httptest.NewRecorder()
  746. recorder.Body = buff
  747. o := Classic()
  748. o.Get("/", new(Cookie35Action))
  749. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  750. if err != nil {
  751. t.Error(err)
  752. }
  753. req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
  754. o.ServeHTTP(recorder, req)
  755. expect(t, recorder.Code, http.StatusOK)
  756. refute(t, len(buff.String()), 0)
  757. expect(t, buff.String(), "1")
  758. }
  759. type Cookie36Action struct {
  760. Ctx
  761. }
  762. func (a *Cookie36Action) Get() string {
  763. v, _ := a.SecureCookies(secrectCookie).Uint64("test")
  764. return fmt.Sprintf("%d", v)
  765. }
  766. func TestCookie36(t *testing.T) {
  767. buff := bytes.NewBufferString("")
  768. recorder := httptest.NewRecorder()
  769. recorder.Body = buff
  770. o := Classic()
  771. o.Get("/", new(Cookie36Action))
  772. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  773. if err != nil {
  774. t.Error(err)
  775. }
  776. req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
  777. o.ServeHTTP(recorder, req)
  778. expect(t, recorder.Code, http.StatusOK)
  779. refute(t, len(buff.String()), 0)
  780. expect(t, buff.String(), "1")
  781. }
  782. type Cookie37Action struct {
  783. Ctx
  784. }
  785. func (a *Cookie37Action) Get() string {
  786. v, _ := a.SecureCookies(secrectCookie).Float32("test")
  787. return fmt.Sprintf("%.2f", v)
  788. }
  789. func TestCookie37(t *testing.T) {
  790. buff := bytes.NewBufferString("")
  791. recorder := httptest.NewRecorder()
  792. recorder.Body = buff
  793. o := Classic()
  794. o.Get("/", new(Cookie37Action))
  795. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  796. if err != nil {
  797. t.Error(err)
  798. }
  799. req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
  800. o.ServeHTTP(recorder, req)
  801. expect(t, recorder.Code, http.StatusOK)
  802. refute(t, len(buff.String()), 0)
  803. expect(t, buff.String(), "1.00")
  804. }
  805. type Cookie38Action struct {
  806. Ctx
  807. }
  808. func (a *Cookie38Action) Get() string {
  809. v, _ := a.SecureCookies(secrectCookie).Float64("test")
  810. return fmt.Sprintf("%.2f", v)
  811. }
  812. func TestCookie38(t *testing.T) {
  813. buff := bytes.NewBufferString("")
  814. recorder := httptest.NewRecorder()
  815. recorder.Body = buff
  816. o := Classic()
  817. o.Get("/", new(Cookie38Action))
  818. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  819. if err != nil {
  820. t.Error(err)
  821. }
  822. req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
  823. o.ServeHTTP(recorder, req)
  824. expect(t, recorder.Code, http.StatusOK)
  825. refute(t, len(buff.String()), 0)
  826. expect(t, buff.String(), "1.00")
  827. }
  828. type Cookie39Action struct {
  829. Ctx
  830. }
  831. func (a *Cookie39Action) Get() string {
  832. v, _ := a.SecureCookies(secrectCookie).Bool("test")
  833. return fmt.Sprintf("%v", v)
  834. }
  835. func TestCookie39(t *testing.T) {
  836. buff := bytes.NewBufferString("")
  837. recorder := httptest.NewRecorder()
  838. recorder.Body = buff
  839. o := Classic()
  840. o.Get("/", new(Cookie39Action))
  841. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  842. if err != nil {
  843. t.Error(err)
  844. }
  845. req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
  846. o.ServeHTTP(recorder, req)
  847. expect(t, recorder.Code, http.StatusOK)
  848. refute(t, len(buff.String()), 0)
  849. expect(t, buff.String(), "true")
  850. }
  851. type Cookie40Action struct {
  852. Ctx
  853. }
  854. func (a *Cookie40Action) Get() string {
  855. v, _ := a.SecureCookies(secrectCookie).String("test")
  856. return fmt.Sprintf("%v", v)
  857. }
  858. func TestCookie40(t *testing.T) {
  859. buff := bytes.NewBufferString("")
  860. recorder := httptest.NewRecorder()
  861. recorder.Body = buff
  862. o := Classic()
  863. o.Get("/", new(Cookie40Action))
  864. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  865. if err != nil {
  866. t.Error(err)
  867. }
  868. req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
  869. o.ServeHTTP(recorder, req)
  870. expect(t, recorder.Code, http.StatusOK)
  871. refute(t, len(buff.String()), 0)
  872. expect(t, buff.String(), "1")
  873. }
  874. type Cookie41Action struct {
  875. Ctx
  876. }
  877. func (a *Cookie41Action) Get() string {
  878. v := a.SecureCookies(secrectCookie).MustInt("test")
  879. return fmt.Sprintf("%d", v)
  880. }
  881. func TestCookie41(t *testing.T) {
  882. buff := bytes.NewBufferString("")
  883. recorder := httptest.NewRecorder()
  884. recorder.Body = buff
  885. o := Classic()
  886. o.Get("/", new(Cookie41Action))
  887. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  888. if err != nil {
  889. t.Error(err)
  890. }
  891. req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
  892. o.ServeHTTP(recorder, req)
  893. expect(t, recorder.Code, http.StatusOK)
  894. refute(t, len(buff.String()), 0)
  895. expect(t, buff.String(), "1")
  896. }
  897. type Cookie42Action struct {
  898. Ctx
  899. }
  900. func (a *Cookie42Action) Get() string {
  901. v := a.SecureCookies(secrectCookie).MustInt32("test")
  902. return fmt.Sprintf("%d", v)
  903. }
  904. func TestCookie42(t *testing.T) {
  905. buff := bytes.NewBufferString("")
  906. recorder := httptest.NewRecorder()
  907. recorder.Body = buff
  908. o := Classic()
  909. o.Get("/", new(Cookie42Action))
  910. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  911. if err != nil {
  912. t.Error(err)
  913. }
  914. req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
  915. o.ServeHTTP(recorder, req)
  916. expect(t, recorder.Code, http.StatusOK)
  917. refute(t, len(buff.String()), 0)
  918. expect(t, buff.String(), "1")
  919. }
  920. type Cookie43Action struct {
  921. Ctx
  922. }
  923. func (a *Cookie43Action) Get() string {
  924. v := a.SecureCookies(secrectCookie).MustInt64("test")
  925. return fmt.Sprintf("%d", v)
  926. }
  927. func TestCookie43(t *testing.T) {
  928. buff := bytes.NewBufferString("")
  929. recorder := httptest.NewRecorder()
  930. recorder.Body = buff
  931. o := Classic()
  932. o.Get("/", new(Cookie43Action))
  933. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  934. if err != nil {
  935. t.Error(err)
  936. }
  937. req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
  938. o.ServeHTTP(recorder, req)
  939. expect(t, recorder.Code, http.StatusOK)
  940. refute(t, len(buff.String()), 0)
  941. expect(t, buff.String(), "1")
  942. }
  943. type Cookie44Action struct {
  944. Ctx
  945. }
  946. func (a *Cookie44Action) Get() string {
  947. v := a.SecureCookies(secrectCookie).MustUint("test")
  948. return fmt.Sprintf("%d", v)
  949. }
  950. func TestCookie44(t *testing.T) {
  951. buff := bytes.NewBufferString("")
  952. recorder := httptest.NewRecorder()
  953. recorder.Body = buff
  954. o := Classic()
  955. o.Get("/", new(Cookie44Action))
  956. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  957. if err != nil {
  958. t.Error(err)
  959. }
  960. req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
  961. o.ServeHTTP(recorder, req)
  962. expect(t, recorder.Code, http.StatusOK)
  963. refute(t, len(buff.String()), 0)
  964. expect(t, buff.String(), "1")
  965. }
  966. type Cookie45Action struct {
  967. Ctx
  968. }
  969. func (a *Cookie45Action) Get() string {
  970. v := a.SecureCookies(secrectCookie).MustUint32("test")
  971. return fmt.Sprintf("%d", v)
  972. }
  973. func TestCookie45(t *testing.T) {
  974. buff := bytes.NewBufferString("")
  975. recorder := httptest.NewRecorder()
  976. recorder.Body = buff
  977. o := Classic()
  978. o.Get("/", new(Cookie45Action))
  979. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  980. if err != nil {
  981. t.Error(err)
  982. }
  983. req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
  984. o.ServeHTTP(recorder, req)
  985. expect(t, recorder.Code, http.StatusOK)
  986. refute(t, len(buff.String()), 0)
  987. expect(t, buff.String(), "1")
  988. }
  989. type Cookie46Action struct {
  990. Ctx
  991. }
  992. func (a *Cookie46Action) Get() string {
  993. v := a.SecureCookies(secrectCookie).MustUint64("test")
  994. return fmt.Sprintf("%d", v)
  995. }
  996. func TestCookie46(t *testing.T) {
  997. buff := bytes.NewBufferString("")
  998. recorder := httptest.NewRecorder()
  999. recorder.Body = buff
  1000. o := Classic()
  1001. o.Get("/", new(Cookie46Action))
  1002. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  1003. if err != nil {
  1004. t.Error(err)
  1005. }
  1006. req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
  1007. o.ServeHTTP(recorder, req)
  1008. expect(t, recorder.Code, http.StatusOK)
  1009. refute(t, len(buff.String()), 0)
  1010. expect(t, buff.String(), "1")
  1011. }
  1012. type Cookie47Action struct {
  1013. Ctx
  1014. }
  1015. func (a *Cookie47Action) Get() string {
  1016. v := a.SecureCookies(secrectCookie).MustFloat32("test")
  1017. return fmt.Sprintf("%.2f", v)
  1018. }
  1019. func TestCookie47(t *testing.T) {
  1020. buff := bytes.NewBufferString("")
  1021. recorder := httptest.NewRecorder()
  1022. recorder.Body = buff
  1023. o := Classic()
  1024. o.Get("/", new(Cookie47Action))
  1025. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  1026. if err != nil {
  1027. t.Error(err)
  1028. }
  1029. req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
  1030. o.ServeHTTP(recorder, req)
  1031. expect(t, recorder.Code, http.StatusOK)
  1032. refute(t, len(buff.String()), 0)
  1033. expect(t, buff.String(), "1.00")
  1034. }
  1035. type Cookie48Action struct {
  1036. Ctx
  1037. }
  1038. func (a *Cookie48Action) Get() string {
  1039. v := a.SecureCookies(secrectCookie).MustFloat64("test")
  1040. return fmt.Sprintf("%.2f", v)
  1041. }
  1042. func TestCookie48(t *testing.T) {
  1043. buff := bytes.NewBufferString("")
  1044. recorder := httptest.NewRecorder()
  1045. recorder.Body = buff
  1046. o := Classic()
  1047. o.Get("/", new(Cookie48Action))
  1048. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  1049. if err != nil {
  1050. t.Error(err)
  1051. }
  1052. req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
  1053. o.ServeHTTP(recorder, req)
  1054. expect(t, recorder.Code, http.StatusOK)
  1055. refute(t, len(buff.String()), 0)
  1056. expect(t, buff.String(), "1.00")
  1057. }
  1058. type Cookie49Action struct {
  1059. Ctx
  1060. }
  1061. func (a *Cookie49Action) Get() string {
  1062. v := a.SecureCookies(secrectCookie).MustBool("test")
  1063. return fmt.Sprintf("%v", v)
  1064. }
  1065. func TestCookie49(t *testing.T) {
  1066. buff := bytes.NewBufferString("")
  1067. recorder := httptest.NewRecorder()
  1068. recorder.Body = buff
  1069. o := Classic()
  1070. o.Get("/", new(Cookie49Action))
  1071. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  1072. if err != nil {
  1073. t.Error(err)
  1074. }
  1075. req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
  1076. o.ServeHTTP(recorder, req)
  1077. expect(t, recorder.Code, http.StatusOK)
  1078. refute(t, len(buff.String()), 0)
  1079. expect(t, buff.String(), "true")
  1080. }
  1081. type Cookie50Action struct {
  1082. Ctx
  1083. }
  1084. func (a *Cookie50Action) Get() string {
  1085. v := a.SecureCookies(secrectCookie).MustString("test")
  1086. return fmt.Sprintf("%s", v)
  1087. }
  1088. func TestCookie50(t *testing.T) {
  1089. buff := bytes.NewBufferString("")
  1090. recorder := httptest.NewRecorder()
  1091. recorder.Body = buff
  1092. o := Classic()
  1093. o.Get("/", new(Cookie50Action))
  1094. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  1095. if err != nil {
  1096. t.Error(err)
  1097. }
  1098. req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
  1099. o.ServeHTTP(recorder, req)
  1100. expect(t, recorder.Code, http.StatusOK)
  1101. refute(t, len(buff.String()), 0)
  1102. expect(t, buff.String(), "1")
  1103. }
  1104. type Cookie51Action struct {
  1105. Ctx
  1106. }
  1107. func (a *Cookie51Action) Get() string {
  1108. v := a.CookieInt("test")
  1109. return fmt.Sprintf("%d", v)
  1110. }
  1111. func TestCookie51(t *testing.T) {
  1112. buff := bytes.NewBufferString("")
  1113. recorder := httptest.NewRecorder()
  1114. recorder.Body = buff
  1115. o := Classic()
  1116. o.Get("/", new(Cookie51Action))
  1117. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  1118. if err != nil {
  1119. t.Error(err)
  1120. }
  1121. req.AddCookie(NewCookie("test", "1"))
  1122. o.ServeHTTP(recorder, req)
  1123. expect(t, recorder.Code, http.StatusOK)
  1124. refute(t, len(buff.String()), 0)
  1125. expect(t, buff.String(), "1")
  1126. }
  1127. type Cookie52Action struct {
  1128. Ctx
  1129. }
  1130. func (a *Cookie52Action) Get() string {
  1131. v := a.CookieInt32("test")
  1132. return fmt.Sprintf("%d", v)
  1133. }
  1134. func TestCookie52(t *testing.T) {
  1135. buff := bytes.NewBufferString("")
  1136. recorder := httptest.NewRecorder()
  1137. recorder.Body = buff
  1138. o := Classic()
  1139. o.Get("/", new(Cookie52Action))
  1140. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  1141. if err != nil {
  1142. t.Error(err)
  1143. }
  1144. req.AddCookie(NewCookie("test", "1"))
  1145. o.ServeHTTP(recorder, req)
  1146. expect(t, recorder.Code, http.StatusOK)
  1147. refute(t, len(buff.String()), 0)
  1148. expect(t, buff.String(), "1")
  1149. }
  1150. type Cookie53Action struct {
  1151. Ctx
  1152. }
  1153. func (a *Cookie53Action) Get() string {
  1154. v := a.CookieInt64("test")
  1155. return fmt.Sprintf("%d", v)
  1156. }
  1157. func TestCookie53(t *testing.T) {
  1158. buff := bytes.NewBufferString("")
  1159. recorder := httptest.NewRecorder()
  1160. recorder.Body = buff
  1161. o := Classic()
  1162. o.Get("/", new(Cookie53Action))
  1163. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  1164. if err != nil {
  1165. t.Error(err)
  1166. }
  1167. req.AddCookie(NewCookie("test", "1"))
  1168. o.ServeHTTP(recorder, req)
  1169. expect(t, recorder.Code, http.StatusOK)
  1170. refute(t, len(buff.String()), 0)
  1171. expect(t, buff.String(), "1")
  1172. }
  1173. type Cookie54Action struct {
  1174. Ctx
  1175. }
  1176. func (a *Cookie54Action) Get() string {
  1177. v := a.CookieUint("test")
  1178. return fmt.Sprintf("%d", v)
  1179. }
  1180. func TestCookie54(t *testing.T) {
  1181. buff := bytes.NewBufferString("")
  1182. recorder := httptest.NewRecorder()
  1183. recorder.Body = buff
  1184. o := Classic()
  1185. o.Get("/", new(Cookie54Action))
  1186. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  1187. if err != nil {
  1188. t.Error(err)
  1189. }
  1190. req.AddCookie(NewCookie("test", "1"))
  1191. o.ServeHTTP(recorder, req)
  1192. expect(t, recorder.Code, http.StatusOK)
  1193. refute(t, len(buff.String()), 0)
  1194. expect(t, buff.String(), "1")
  1195. }
  1196. type Cookie55Action struct {
  1197. Ctx
  1198. }
  1199. func (a *Cookie55Action) Get() string {
  1200. v := a.CookieUint32("test")
  1201. return fmt.Sprintf("%d", v)
  1202. }
  1203. func TestCookie55(t *testing.T) {
  1204. buff := bytes.NewBufferString("")
  1205. recorder := httptest.NewRecorder()
  1206. recorder.Body = buff
  1207. o := Classic()
  1208. o.Get("/", new(Cookie55Action))
  1209. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  1210. if err != nil {
  1211. t.Error(err)
  1212. }
  1213. req.AddCookie(NewCookie("test", "1"))
  1214. o.ServeHTTP(recorder, req)
  1215. expect(t, recorder.Code, http.StatusOK)
  1216. refute(t, len(buff.String()), 0)
  1217. expect(t, buff.String(), "1")
  1218. }
  1219. type Cookie56Action struct {
  1220. Ctx
  1221. }
  1222. func (a *Cookie56Action) Get() string {
  1223. v := a.CookieUint64("test")
  1224. return fmt.Sprintf("%d", v)
  1225. }
  1226. func TestCookie56(t *testing.T) {
  1227. buff := bytes.NewBufferString("")
  1228. recorder := httptest.NewRecorder()
  1229. recorder.Body = buff
  1230. o := Classic()
  1231. o.Get("/", new(Cookie56Action))
  1232. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  1233. if err != nil {
  1234. t.Error(err)
  1235. }
  1236. req.AddCookie(NewCookie("test", "1"))
  1237. o.ServeHTTP(recorder, req)
  1238. expect(t, recorder.Code, http.StatusOK)
  1239. refute(t, len(buff.String()), 0)
  1240. expect(t, buff.String(), "1")
  1241. }
  1242. type Cookie57Action struct {
  1243. Ctx
  1244. }
  1245. func (a *Cookie57Action) Get() string {
  1246. v := a.CookieFloat32("test")
  1247. return fmt.Sprintf("%.2f", v)
  1248. }
  1249. func TestCookie57(t *testing.T) {
  1250. buff := bytes.NewBufferString("")
  1251. recorder := httptest.NewRecorder()
  1252. recorder.Body = buff
  1253. o := Classic()
  1254. o.Get("/", new(Cookie57Action))
  1255. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  1256. if err != nil {
  1257. t.Error(err)
  1258. }
  1259. req.AddCookie(NewCookie("test", "1"))
  1260. o.ServeHTTP(recorder, req)
  1261. expect(t, recorder.Code, http.StatusOK)
  1262. refute(t, len(buff.String()), 0)
  1263. expect(t, buff.String(), "1.00")
  1264. }
  1265. type Cookie58Action struct {
  1266. Ctx
  1267. }
  1268. func (a *Cookie58Action) Get() string {
  1269. v := a.CookieFloat64("test")
  1270. return fmt.Sprintf("%.2f", v)
  1271. }
  1272. func TestCookie58(t *testing.T) {
  1273. buff := bytes.NewBufferString("")
  1274. recorder := httptest.NewRecorder()
  1275. recorder.Body = buff
  1276. o := Classic()
  1277. o.Get("/", new(Cookie58Action))
  1278. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  1279. if err != nil {
  1280. t.Error(err)
  1281. }
  1282. req.AddCookie(NewCookie("test", "1"))
  1283. o.ServeHTTP(recorder, req)
  1284. expect(t, recorder.Code, http.StatusOK)
  1285. refute(t, len(buff.String()), 0)
  1286. expect(t, buff.String(), "1.00")
  1287. }
  1288. type Cookie59Action struct {
  1289. Ctx
  1290. }
  1291. func (a *Cookie59Action) Get() string {
  1292. v := a.CookieBool("test")
  1293. return fmt.Sprintf("%v", v)
  1294. }
  1295. func TestCookie59(t *testing.T) {
  1296. buff := bytes.NewBufferString("")
  1297. recorder := httptest.NewRecorder()
  1298. recorder.Body = buff
  1299. o := Classic()
  1300. o.Get("/", new(Cookie59Action))
  1301. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  1302. if err != nil {
  1303. t.Error(err)
  1304. }
  1305. req.AddCookie(NewCookie("test", "1"))
  1306. o.ServeHTTP(recorder, req)
  1307. expect(t, recorder.Code, http.StatusOK)
  1308. refute(t, len(buff.String()), 0)
  1309. expect(t, buff.String(), "true")
  1310. }
  1311. type Cookie60Action struct {
  1312. Ctx
  1313. }
  1314. func (a *Cookie60Action) Get() string {
  1315. v := a.Cookie("test")
  1316. return fmt.Sprintf("%s", v)
  1317. }
  1318. func TestCookie60(t *testing.T) {
  1319. buff := bytes.NewBufferString("")
  1320. recorder := httptest.NewRecorder()
  1321. recorder.Body = buff
  1322. o := Classic()
  1323. o.Get("/", new(Cookie60Action))
  1324. req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
  1325. if err != nil {
  1326. t.Error(err)
  1327. }
  1328. req.AddCookie(NewCookie("test", "1"))
  1329. o.ServeHTTP(recorder, req)
  1330. expect(t, recorder.Code, http.StatusOK)
  1331. refute(t, len(buff.String()), 0)
  1332. expect(t, buff.String(), "1")
  1333. }