|
5 | 5 | "net/http"
|
6 | 6 | "net/http/httptest"
|
7 | 7 | "reflect"
|
8 |
| - "testing" |
9 |
| - "strings" |
10 | 8 | "strconv"
|
| 9 | + "strings" |
| 10 | + "testing" |
11 | 11 | "time"
|
12 | 12 |
|
13 | 13 | "github.com/lunny/tango"
|
@@ -96,6 +96,69 @@ func TestFlash(t *testing.T) {
|
96 | 96 | expect(t, buff.String(), "")
|
97 | 97 | }
|
98 | 98 |
|
| 99 | +/*func TestFlashRedis(t *testing.T) { |
| 100 | + buff := bytes.NewBufferString("") |
| 101 | + recorder := httptest.NewRecorder() |
| 102 | + recorder.Body = buff |
| 103 | +
|
| 104 | + tg := tango.Classic() |
| 105 | + sessions := session.New(session.Options{ |
| 106 | + Store: redistore.New(redistore.Options{ |
| 107 | + Host: "127.0.0.1", |
| 108 | + DbIndex: 0, |
| 109 | + MaxAge: 30 * time.Minute, |
| 110 | + }), |
| 111 | + }) |
| 112 | + tg.Use(Flashes(sessions)) |
| 113 | + tg.Any("/", new(FlashAction)) |
| 114 | +
|
| 115 | + req, err := http.NewRequest("GET", "http://localhost:8000/", nil) |
| 116 | + if err != nil { |
| 117 | + t.Error(err) |
| 118 | + } |
| 119 | +
|
| 120 | + tg.ServeHTTP(recorder, req) |
| 121 | + expect(t, recorder.Code, http.StatusOK) |
| 122 | + refute(t, len(buff.String()), 0) |
| 123 | + expect(t, buff.String(), "test") |
| 124 | +
|
| 125 | + buff.Reset() |
| 126 | +
|
| 127 | + req, err = http.NewRequest("POST", "http://localhost:8000/", nil) |
| 128 | + if err != nil { |
| 129 | + t.Error(err) |
| 130 | + } |
| 131 | +
|
| 132 | + cks := readSetCookies(recorder.Header()) |
| 133 | + for _, ck := range cks { |
| 134 | + req.AddCookie(ck) |
| 135 | + } |
| 136 | + recorder.HeaderMap = make(map[string][]string) |
| 137 | +
|
| 138 | + tg.ServeHTTP(recorder, req) |
| 139 | + expect(t, recorder.Code, http.StatusOK) |
| 140 | + refute(t, len(buff.String()), 0) |
| 141 | + expect(t, buff.String(), "test") |
| 142 | +
|
| 143 | + buff.Reset() |
| 144 | +
|
| 145 | + req, err = http.NewRequest("PUT", "http://localhost:8000/", nil) |
| 146 | + if err != nil { |
| 147 | + t.Error(err) |
| 148 | + } |
| 149 | +
|
| 150 | + cks = readSetCookies(recorder.Header()) |
| 151 | + for _, ck := range cks { |
| 152 | + req.AddCookie(ck) |
| 153 | + } |
| 154 | + recorder.HeaderMap = make(map[string][]string) |
| 155 | +
|
| 156 | + tg.ServeHTTP(recorder, req) |
| 157 | + expect(t, recorder.Code, http.StatusOK) |
| 158 | + expect(t, len(buff.String()), 0) |
| 159 | + expect(t, buff.String(), "") |
| 160 | +}*/ |
| 161 | + |
99 | 162 | /* Test Helpers */
|
100 | 163 | func expect(t *testing.T, a interface{}, b interface{}) {
|
101 | 164 | if a != b {
|
|
0 commit comments