1 // Copyright (c) 2012-2016 The Revel Framework Authors, All rights reserved.
2 // Revel Framework source code and usage is governed by a MIT style
3 // license that can be found in the LICENSE file.
14 // Added test case for redirection testing for strings
15 func TestRedirect(t *testing.T) {
17 redirect := RedirectToURLResult{fmt.Sprintf("/hotels/index/foo")}
18 resp := httptest.NewRecorder()
19 c := NewTestController(resp, showRequest)
20 redirect.Apply(c.Request, c.Response)
21 if resp.Header().Get("Location") != "/hotels/index/foo" {
22 t.Errorf("Failed to set redirect header correctly. : %s", resp.Header().Get("Location"))
26 // Test that the render response is as expected.
27 func TestBenchmarkRender(t *testing.T) {
29 resp := httptest.NewRecorder()
30 c := NewTestController(resp, showRequest)
31 if err := c.SetAction("Hotels", "Show"); err != nil {
32 t.Errorf("SetAction failed: %s", err)
34 result := Hotels{c}.Show(3)
35 result.Apply(c.Request, c.Response)
36 if !strings.Contains(resp.Body.String(), "300 Main St.") {
37 t.Errorf("Failed to find hotel address in action response:\n%s", resp.Body)
41 func BenchmarkRenderChunked(b *testing.B) {
43 resp := httptest.NewRecorder()
45 c := NewTestController(resp, showRequest)
46 if err := c.SetAction("Hotels", "Show"); err != nil {
47 b.Errorf("SetAction failed: %s", err)
49 Config.SetOption("results.chunked", "true")
53 for i := 0; i < b.N; i++ {
54 hotels.Show(3).Apply(c.Request, c.Response)
58 func BenchmarkRenderNotChunked(b *testing.B) {
60 resp := httptest.NewRecorder()
62 c := NewTestController(resp, showRequest)
63 if err := c.SetAction("Hotels", "Show"); err != nil {
64 b.Errorf("SetAction failed: %s", err)
66 Config.SetOption("results.chunked", "false")
70 for i := 0; i < b.N; i++ {
71 hotels.Show(3).Apply(c.Request, c.Response)