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.

884 lines
17KB

  1. // Copyright 2016 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. )
  13. type Form1Action struct {
  14. Ctx
  15. }
  16. func (a *Form1Action) Get() string {
  17. v, _ := a.Forms().Int("test")
  18. return fmt.Sprintf("%d", v)
  19. }
  20. func TestForm1(t *testing.T) {
  21. buff := bytes.NewBufferString("")
  22. recorder := httptest.NewRecorder()
  23. recorder.Body = buff
  24. o := Classic()
  25. o.Get("/", new(Form1Action))
  26. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  27. if err != nil {
  28. t.Error(err)
  29. }
  30. o.ServeHTTP(recorder, req)
  31. expect(t, recorder.Code, http.StatusOK)
  32. refute(t, len(buff.String()), 0)
  33. expect(t, buff.String(), "1")
  34. }
  35. type Form2Action struct {
  36. Ctx
  37. }
  38. func (a *Form2Action) Post() string {
  39. v, _ := a.Forms().Int32("test")
  40. return fmt.Sprintf("%d", v)
  41. }
  42. func TestForm2(t *testing.T) {
  43. buff := bytes.NewBufferString("")
  44. recorder := httptest.NewRecorder()
  45. recorder.Body = buff
  46. o := Classic()
  47. o.Post("/", new(Form2Action))
  48. req, err := http.NewRequest("POST", "http://localhost:8000", strings.NewReader("test=1"))
  49. if err != nil {
  50. t.Error(err)
  51. }
  52. req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
  53. o.ServeHTTP(recorder, req)
  54. expect(t, recorder.Code, http.StatusOK)
  55. refute(t, len(buff.String()), 0)
  56. expect(t, buff.String(), "1")
  57. }
  58. type Form3Action struct {
  59. Ctx
  60. }
  61. func (a *Form3Action) Get() string {
  62. v, _ := a.Forms().Int64("test")
  63. return fmt.Sprintf("%d", v)
  64. }
  65. func TestForm3(t *testing.T) {
  66. buff := bytes.NewBufferString("")
  67. recorder := httptest.NewRecorder()
  68. recorder.Body = buff
  69. o := Classic()
  70. o.Get("/", new(Form3Action))
  71. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  72. if err != nil {
  73. t.Error(err)
  74. }
  75. o.ServeHTTP(recorder, req)
  76. expect(t, recorder.Code, http.StatusOK)
  77. refute(t, len(buff.String()), 0)
  78. expect(t, buff.String(), "1")
  79. }
  80. type Form4Action struct {
  81. Ctx
  82. }
  83. func (a *Form4Action) Get() string {
  84. v, _ := a.Forms().Uint("test")
  85. return fmt.Sprintf("%d", v)
  86. }
  87. func TestForm4(t *testing.T) {
  88. buff := bytes.NewBufferString("")
  89. recorder := httptest.NewRecorder()
  90. recorder.Body = buff
  91. o := Classic()
  92. o.Get("/", new(Form4Action))
  93. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  94. if err != nil {
  95. t.Error(err)
  96. }
  97. o.ServeHTTP(recorder, req)
  98. expect(t, recorder.Code, http.StatusOK)
  99. refute(t, len(buff.String()), 0)
  100. expect(t, buff.String(), "1")
  101. }
  102. type Form5Action struct {
  103. Ctx
  104. }
  105. func (a *Form5Action) Get() string {
  106. v, _ := a.Forms().Uint32("test")
  107. return fmt.Sprintf("%d", v)
  108. }
  109. func TestForm5(t *testing.T) {
  110. buff := bytes.NewBufferString("")
  111. recorder := httptest.NewRecorder()
  112. recorder.Body = buff
  113. o := Classic()
  114. o.Get("/", new(Form5Action))
  115. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  116. if err != nil {
  117. t.Error(err)
  118. }
  119. o.ServeHTTP(recorder, req)
  120. expect(t, recorder.Code, http.StatusOK)
  121. refute(t, len(buff.String()), 0)
  122. expect(t, buff.String(), "1")
  123. }
  124. type Form6Action struct {
  125. Ctx
  126. }
  127. func (a *Form6Action) Get() string {
  128. v, _ := a.Forms().Uint64("test")
  129. return fmt.Sprintf("%d", v)
  130. }
  131. func TestForm6(t *testing.T) {
  132. buff := bytes.NewBufferString("")
  133. recorder := httptest.NewRecorder()
  134. recorder.Body = buff
  135. o := Classic()
  136. o.Get("/", new(Form6Action))
  137. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  138. if err != nil {
  139. t.Error(err)
  140. }
  141. o.ServeHTTP(recorder, req)
  142. expect(t, recorder.Code, http.StatusOK)
  143. refute(t, len(buff.String()), 0)
  144. expect(t, buff.String(), "1")
  145. }
  146. type Form7Action struct {
  147. Ctx
  148. }
  149. func (a *Form7Action) Get() string {
  150. v, _ := a.Forms().Float32("test")
  151. return fmt.Sprintf("%.2f", v)
  152. }
  153. func TestForm7(t *testing.T) {
  154. buff := bytes.NewBufferString("")
  155. recorder := httptest.NewRecorder()
  156. recorder.Body = buff
  157. o := Classic()
  158. o.Get("/", new(Form7Action))
  159. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  160. if err != nil {
  161. t.Error(err)
  162. }
  163. o.ServeHTTP(recorder, req)
  164. expect(t, recorder.Code, http.StatusOK)
  165. refute(t, len(buff.String()), 0)
  166. expect(t, buff.String(), "1.00")
  167. }
  168. type Form8Action struct {
  169. Ctx
  170. }
  171. func (a *Form8Action) Get() string {
  172. v, _ := a.Forms().Float64("test")
  173. return fmt.Sprintf("%.2f", v)
  174. }
  175. func TestForm8(t *testing.T) {
  176. buff := bytes.NewBufferString("")
  177. recorder := httptest.NewRecorder()
  178. recorder.Body = buff
  179. o := Classic()
  180. o.Get("/", new(Form8Action))
  181. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  182. if err != nil {
  183. t.Error(err)
  184. }
  185. o.ServeHTTP(recorder, req)
  186. expect(t, recorder.Code, http.StatusOK)
  187. refute(t, len(buff.String()), 0)
  188. expect(t, buff.String(), "1.00")
  189. }
  190. type Form9Action struct {
  191. Ctx
  192. }
  193. func (a *Form9Action) Get() string {
  194. v, _ := a.Forms().Bool("test")
  195. return fmt.Sprintf("%v", v)
  196. }
  197. func TestForm9(t *testing.T) {
  198. buff := bytes.NewBufferString("")
  199. recorder := httptest.NewRecorder()
  200. recorder.Body = buff
  201. o := Classic()
  202. o.Get("/", new(Form9Action))
  203. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  204. if err != nil {
  205. t.Error(err)
  206. }
  207. o.ServeHTTP(recorder, req)
  208. expect(t, recorder.Code, http.StatusOK)
  209. refute(t, len(buff.String()), 0)
  210. expect(t, buff.String(), "true")
  211. }
  212. type Form10Action struct {
  213. Ctx
  214. }
  215. func (a *Form10Action) Get() string {
  216. v, _ := a.Forms().String("test")
  217. return fmt.Sprintf("%v", v)
  218. }
  219. func TestForm10(t *testing.T) {
  220. buff := bytes.NewBufferString("")
  221. recorder := httptest.NewRecorder()
  222. recorder.Body = buff
  223. o := Classic()
  224. o.Get("/", new(Form10Action))
  225. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  226. if err != nil {
  227. t.Error(err)
  228. }
  229. o.ServeHTTP(recorder, req)
  230. expect(t, recorder.Code, http.StatusOK)
  231. refute(t, len(buff.String()), 0)
  232. expect(t, buff.String(), "1")
  233. }
  234. type Form11Action struct {
  235. Ctx
  236. }
  237. func (a *Form11Action) Get() string {
  238. v := a.Forms().MustInt("test")
  239. return fmt.Sprintf("%d", v)
  240. }
  241. func TestForm11(t *testing.T) {
  242. buff := bytes.NewBufferString("")
  243. recorder := httptest.NewRecorder()
  244. recorder.Body = buff
  245. o := Classic()
  246. o.Get("/", new(Form11Action))
  247. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  248. if err != nil {
  249. t.Error(err)
  250. }
  251. o.ServeHTTP(recorder, req)
  252. expect(t, recorder.Code, http.StatusOK)
  253. refute(t, len(buff.String()), 0)
  254. expect(t, buff.String(), "1")
  255. }
  256. type Form12Action struct {
  257. Ctx
  258. }
  259. func (a *Form12Action) Get() string {
  260. v := a.Forms().MustInt32("test")
  261. return fmt.Sprintf("%d", v)
  262. }
  263. func TestForm12(t *testing.T) {
  264. buff := bytes.NewBufferString("")
  265. recorder := httptest.NewRecorder()
  266. recorder.Body = buff
  267. o := Classic()
  268. o.Get("/", new(Form12Action))
  269. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  270. if err != nil {
  271. t.Error(err)
  272. }
  273. o.ServeHTTP(recorder, req)
  274. expect(t, recorder.Code, http.StatusOK)
  275. refute(t, len(buff.String()), 0)
  276. expect(t, buff.String(), "1")
  277. }
  278. type Form13Action struct {
  279. Ctx
  280. }
  281. func (a *Form13Action) Get() string {
  282. v := a.Forms().MustInt64("test")
  283. return fmt.Sprintf("%d", v)
  284. }
  285. func TestForm13(t *testing.T) {
  286. buff := bytes.NewBufferString("")
  287. recorder := httptest.NewRecorder()
  288. recorder.Body = buff
  289. o := Classic()
  290. o.Get("/", new(Form13Action))
  291. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  292. if err != nil {
  293. t.Error(err)
  294. }
  295. o.ServeHTTP(recorder, req)
  296. expect(t, recorder.Code, http.StatusOK)
  297. refute(t, len(buff.String()), 0)
  298. expect(t, buff.String(), "1")
  299. }
  300. type Form14Action struct {
  301. Ctx
  302. }
  303. func (a *Form14Action) Get() string {
  304. v := a.Forms().MustUint("test")
  305. return fmt.Sprintf("%d", v)
  306. }
  307. func TestForm14(t *testing.T) {
  308. buff := bytes.NewBufferString("")
  309. recorder := httptest.NewRecorder()
  310. recorder.Body = buff
  311. o := Classic()
  312. o.Get("/", new(Form14Action))
  313. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  314. if err != nil {
  315. t.Error(err)
  316. }
  317. o.ServeHTTP(recorder, req)
  318. expect(t, recorder.Code, http.StatusOK)
  319. refute(t, len(buff.String()), 0)
  320. expect(t, buff.String(), "1")
  321. }
  322. type Form15Action struct {
  323. Ctx
  324. }
  325. func (a *Form15Action) Get() string {
  326. v := a.Forms().MustUint32("test")
  327. return fmt.Sprintf("%d", v)
  328. }
  329. func TestForm15(t *testing.T) {
  330. buff := bytes.NewBufferString("")
  331. recorder := httptest.NewRecorder()
  332. recorder.Body = buff
  333. o := Classic()
  334. o.Get("/", new(Form15Action))
  335. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  336. if err != nil {
  337. t.Error(err)
  338. }
  339. o.ServeHTTP(recorder, req)
  340. expect(t, recorder.Code, http.StatusOK)
  341. refute(t, len(buff.String()), 0)
  342. expect(t, buff.String(), "1")
  343. }
  344. type Form16Action struct {
  345. Ctx
  346. }
  347. func (a *Form16Action) Get() string {
  348. v := a.Forms().MustUint64("test")
  349. return fmt.Sprintf("%d", v)
  350. }
  351. func TestForm16(t *testing.T) {
  352. buff := bytes.NewBufferString("")
  353. recorder := httptest.NewRecorder()
  354. recorder.Body = buff
  355. o := Classic()
  356. o.Get("/", new(Form16Action))
  357. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  358. if err != nil {
  359. t.Error(err)
  360. }
  361. o.ServeHTTP(recorder, req)
  362. expect(t, recorder.Code, http.StatusOK)
  363. refute(t, len(buff.String()), 0)
  364. expect(t, buff.String(), "1")
  365. }
  366. type Form17Action struct {
  367. Ctx
  368. }
  369. func (a *Form17Action) Get() string {
  370. v := a.Forms().MustFloat32("test")
  371. return fmt.Sprintf("%.2f", v)
  372. }
  373. func TestForm17(t *testing.T) {
  374. buff := bytes.NewBufferString("")
  375. recorder := httptest.NewRecorder()
  376. recorder.Body = buff
  377. o := Classic()
  378. o.Get("/", new(Form17Action))
  379. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  380. if err != nil {
  381. t.Error(err)
  382. }
  383. o.ServeHTTP(recorder, req)
  384. expect(t, recorder.Code, http.StatusOK)
  385. refute(t, len(buff.String()), 0)
  386. expect(t, buff.String(), "1.00")
  387. }
  388. type Form18Action struct {
  389. Ctx
  390. }
  391. func (a *Form18Action) Get() string {
  392. v := a.Forms().MustFloat64("test")
  393. return fmt.Sprintf("%.2f", v)
  394. }
  395. func TestForm18(t *testing.T) {
  396. buff := bytes.NewBufferString("")
  397. recorder := httptest.NewRecorder()
  398. recorder.Body = buff
  399. o := Classic()
  400. o.Get("/", new(Form18Action))
  401. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  402. if err != nil {
  403. t.Error(err)
  404. }
  405. o.ServeHTTP(recorder, req)
  406. expect(t, recorder.Code, http.StatusOK)
  407. refute(t, len(buff.String()), 0)
  408. expect(t, buff.String(), "1.00")
  409. }
  410. type Form19Action struct {
  411. Ctx
  412. }
  413. func (a *Form19Action) Get() string {
  414. v := a.Forms().MustBool("test")
  415. return fmt.Sprintf("%v", v)
  416. }
  417. func TestForm19(t *testing.T) {
  418. buff := bytes.NewBufferString("")
  419. recorder := httptest.NewRecorder()
  420. recorder.Body = buff
  421. o := Classic()
  422. o.Get("/", new(Form19Action))
  423. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  424. if err != nil {
  425. t.Error(err)
  426. }
  427. o.ServeHTTP(recorder, req)
  428. expect(t, recorder.Code, http.StatusOK)
  429. refute(t, len(buff.String()), 0)
  430. expect(t, buff.String(), "true")
  431. }
  432. type Form20Action struct {
  433. Ctx
  434. }
  435. func (a *Form20Action) Get() string {
  436. v := a.Forms().MustString("test")
  437. return fmt.Sprintf("%s", v)
  438. }
  439. func TestForm20(t *testing.T) {
  440. buff := bytes.NewBufferString("")
  441. recorder := httptest.NewRecorder()
  442. recorder.Body = buff
  443. o := Classic()
  444. o.Get("/", new(Form20Action))
  445. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  446. if err != nil {
  447. t.Error(err)
  448. }
  449. o.ServeHTTP(recorder, req)
  450. expect(t, recorder.Code, http.StatusOK)
  451. refute(t, len(buff.String()), 0)
  452. expect(t, buff.String(), "1")
  453. }
  454. type Form21Action struct {
  455. Ctx
  456. }
  457. func (a *Form21Action) Get() string {
  458. v := a.FormInt("test")
  459. return fmt.Sprintf("%d", v)
  460. }
  461. func TestForm21(t *testing.T) {
  462. buff := bytes.NewBufferString("")
  463. recorder := httptest.NewRecorder()
  464. recorder.Body = buff
  465. o := Classic()
  466. o.Get("/", new(Form21Action))
  467. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  468. if err != nil {
  469. t.Error(err)
  470. }
  471. o.ServeHTTP(recorder, req)
  472. expect(t, recorder.Code, http.StatusOK)
  473. refute(t, len(buff.String()), 0)
  474. expect(t, buff.String(), "1")
  475. }
  476. type Form22Action struct {
  477. Ctx
  478. }
  479. func (a *Form22Action) Get() string {
  480. v := a.FormInt32("test")
  481. return fmt.Sprintf("%d", v)
  482. }
  483. func TestForm22(t *testing.T) {
  484. buff := bytes.NewBufferString("")
  485. recorder := httptest.NewRecorder()
  486. recorder.Body = buff
  487. o := Classic()
  488. o.Get("/", new(Form22Action))
  489. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  490. if err != nil {
  491. t.Error(err)
  492. }
  493. o.ServeHTTP(recorder, req)
  494. expect(t, recorder.Code, http.StatusOK)
  495. refute(t, len(buff.String()), 0)
  496. expect(t, buff.String(), "1")
  497. }
  498. type Form23Action struct {
  499. Ctx
  500. }
  501. func (a *Form23Action) Get() string {
  502. v := a.FormInt64("test")
  503. return fmt.Sprintf("%d", v)
  504. }
  505. func TestForm23(t *testing.T) {
  506. buff := bytes.NewBufferString("")
  507. recorder := httptest.NewRecorder()
  508. recorder.Body = buff
  509. o := Classic()
  510. o.Get("/", new(Form23Action))
  511. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  512. if err != nil {
  513. t.Error(err)
  514. }
  515. o.ServeHTTP(recorder, req)
  516. expect(t, recorder.Code, http.StatusOK)
  517. refute(t, len(buff.String()), 0)
  518. expect(t, buff.String(), "1")
  519. }
  520. type Form24Action struct {
  521. Ctx
  522. }
  523. func (a *Form24Action) Get() string {
  524. v := a.FormUint("test")
  525. return fmt.Sprintf("%d", v)
  526. }
  527. func TestForm24(t *testing.T) {
  528. buff := bytes.NewBufferString("")
  529. recorder := httptest.NewRecorder()
  530. recorder.Body = buff
  531. o := Classic()
  532. o.Get("/", new(Form24Action))
  533. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  534. if err != nil {
  535. t.Error(err)
  536. }
  537. o.ServeHTTP(recorder, req)
  538. expect(t, recorder.Code, http.StatusOK)
  539. refute(t, len(buff.String()), 0)
  540. expect(t, buff.String(), "1")
  541. }
  542. type Form25Action struct {
  543. Ctx
  544. }
  545. func (a *Form25Action) Get() string {
  546. v := a.FormUint32("test")
  547. return fmt.Sprintf("%d", v)
  548. }
  549. func TestForm25(t *testing.T) {
  550. buff := bytes.NewBufferString("")
  551. recorder := httptest.NewRecorder()
  552. recorder.Body = buff
  553. o := Classic()
  554. o.Get("/", new(Form25Action))
  555. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  556. if err != nil {
  557. t.Error(err)
  558. }
  559. o.ServeHTTP(recorder, req)
  560. expect(t, recorder.Code, http.StatusOK)
  561. refute(t, len(buff.String()), 0)
  562. expect(t, buff.String(), "1")
  563. }
  564. type Form26Action struct {
  565. Ctx
  566. }
  567. func (a *Form26Action) Get() string {
  568. v := a.FormUint64("test")
  569. return fmt.Sprintf("%d", v)
  570. }
  571. func TestForm26(t *testing.T) {
  572. buff := bytes.NewBufferString("")
  573. recorder := httptest.NewRecorder()
  574. recorder.Body = buff
  575. o := Classic()
  576. o.Get("/", new(Form26Action))
  577. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  578. if err != nil {
  579. t.Error(err)
  580. }
  581. o.ServeHTTP(recorder, req)
  582. expect(t, recorder.Code, http.StatusOK)
  583. refute(t, len(buff.String()), 0)
  584. expect(t, buff.String(), "1")
  585. }
  586. type Form27Action struct {
  587. Ctx
  588. }
  589. func (a *Form27Action) Get() string {
  590. v := a.FormFloat32("test")
  591. return fmt.Sprintf("%.2f", v)
  592. }
  593. func TestForm27(t *testing.T) {
  594. buff := bytes.NewBufferString("")
  595. recorder := httptest.NewRecorder()
  596. recorder.Body = buff
  597. o := Classic()
  598. o.Get("/", new(Form27Action))
  599. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  600. if err != nil {
  601. t.Error(err)
  602. }
  603. o.ServeHTTP(recorder, req)
  604. expect(t, recorder.Code, http.StatusOK)
  605. refute(t, len(buff.String()), 0)
  606. expect(t, buff.String(), "1.00")
  607. }
  608. type Form28Action struct {
  609. Ctx
  610. }
  611. func (a *Form28Action) Get() string {
  612. v := a.FormFloat64("test")
  613. return fmt.Sprintf("%.2f", v)
  614. }
  615. func TestForm28(t *testing.T) {
  616. buff := bytes.NewBufferString("")
  617. recorder := httptest.NewRecorder()
  618. recorder.Body = buff
  619. o := Classic()
  620. o.Get("/", new(Form28Action))
  621. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  622. if err != nil {
  623. t.Error(err)
  624. }
  625. o.ServeHTTP(recorder, req)
  626. expect(t, recorder.Code, http.StatusOK)
  627. refute(t, len(buff.String()), 0)
  628. expect(t, buff.String(), "1.00")
  629. }
  630. type Form29Action struct {
  631. Ctx
  632. }
  633. func (a *Form29Action) Get() string {
  634. v := a.FormBool("test")
  635. return fmt.Sprintf("%v", v)
  636. }
  637. func TestForm29(t *testing.T) {
  638. buff := bytes.NewBufferString("")
  639. recorder := httptest.NewRecorder()
  640. recorder.Body = buff
  641. o := Classic()
  642. o.Get("/", new(Form29Action))
  643. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  644. if err != nil {
  645. t.Error(err)
  646. }
  647. o.ServeHTTP(recorder, req)
  648. expect(t, recorder.Code, http.StatusOK)
  649. refute(t, len(buff.String()), 0)
  650. expect(t, buff.String(), "true")
  651. }
  652. type Form30Action struct {
  653. Ctx
  654. }
  655. func (a *Form30Action) Get() string {
  656. v := a.Form("test")
  657. return fmt.Sprintf("%s", v)
  658. }
  659. func TestForm30(t *testing.T) {
  660. buff := bytes.NewBufferString("")
  661. recorder := httptest.NewRecorder()
  662. recorder.Body = buff
  663. o := Classic()
  664. o.Get("/", new(Form30Action))
  665. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1", nil)
  666. if err != nil {
  667. t.Error(err)
  668. }
  669. o.ServeHTTP(recorder, req)
  670. expect(t, recorder.Code, http.StatusOK)
  671. refute(t, len(buff.String()), 0)
  672. expect(t, buff.String(), "1")
  673. }
  674. type Form31Action struct {
  675. Ctx
  676. }
  677. func (a *Form31Action) Get() string {
  678. v := a.FormTrimmed("test")
  679. return fmt.Sprintf("%s", v)
  680. }
  681. func TestForm31(t *testing.T) {
  682. buff := bytes.NewBufferString("")
  683. recorder := httptest.NewRecorder()
  684. recorder.Body = buff
  685. o := Classic()
  686. o.Get("/", new(Form31Action))
  687. req, err := http.NewRequest("GET", "http://localhost:8000/?test=1%20", nil)
  688. if err != nil {
  689. t.Error(err)
  690. }
  691. o.ServeHTTP(recorder, req)
  692. expect(t, recorder.Code, http.StatusOK)
  693. refute(t, len(buff.String()), 0)
  694. expect(t, buff.String(), "1")
  695. }