(t *testing.T)
| 168 | } |
| 169 | |
| 170 | func TestMethod_Base(t *testing.T) { |
| 171 | k := New("testkite", "0.0.1") |
| 172 | k.Config.DisableAuthentication = true |
| 173 | k.Config.Port = 10000 |
| 174 | |
| 175 | k.PreHandleFunc(func(r *Request) (interface{}, error) { |
| 176 | r.Context = context.WithValue(r.Context, "pre1", "pre1") |
| 177 | return nil, nil |
| 178 | }) |
| 179 | |
| 180 | k.PreHandleFunc(func(r *Request) (interface{}, error) { |
| 181 | res, _ := r.Context.Value("pre1").(string) |
| 182 | if res != "pre1" { |
| 183 | t.Errorf("Context response from previous pre handler should be pre1, got: %v", res) |
| 184 | } |
| 185 | |
| 186 | r.Context = context.WithValue(r.Context, "pre2", "pre2") |
| 187 | return nil, nil |
| 188 | }) |
| 189 | |
| 190 | k.HandleFunc("foo", func(r *Request) (interface{}, error) { |
| 191 | res, _ := r.Context.Value("funcPre1").(string) |
| 192 | if res != "funcPre1" { |
| 193 | t.Errorf("Context response from previous pre handler should be funcPre1, got: %v", res) |
| 194 | } |
| 195 | |
| 196 | r.Context = context.WithValue(r.Context, "handle", "handle") |
| 197 | return "main-response", nil |
| 198 | }).PreHandleFunc(func(r *Request) (interface{}, error) { |
| 199 | r.Context = context.WithValue(r.Context, "funcPre1", "funcPre1") |
| 200 | return "funcPre1", nil |
| 201 | }).PostHandleFunc(func(r *Request) (interface{}, error) { |
| 202 | res, _ := r.Context.Value("handle").(string) |
| 203 | if res != "handle" { |
| 204 | t.Errorf("Context response from previous pre handler should be handle, got: %v", res) |
| 205 | } |
| 206 | |
| 207 | r.Context = context.WithValue(r.Context, "funcPost1", "funcPost1") |
| 208 | return "funcPost1", nil |
| 209 | }) |
| 210 | |
| 211 | k.PostHandleFunc(func(r *Request) (interface{}, error) { |
| 212 | res, _ := r.Context.Value("funcPost1").(string) |
| 213 | if res != "funcPost1" { |
| 214 | t.Errorf("Context response from previous pre handler should be funcPost1, got: %v", res) |
| 215 | } |
| 216 | |
| 217 | r.Context = context.WithValue(r.Context, "post1", "post1") |
| 218 | return "post1", nil |
| 219 | }) |
| 220 | |
| 221 | k.PostHandleFunc(func(r *Request) (interface{}, error) { |
| 222 | res, _ := r.Context.Value("post1").(string) |
| 223 | if res != "post1" { |
| 224 | t.Errorf("Context response from previous pre handler should be post1, got: %v", res) |
| 225 | } |
| 226 | |
| 227 | return "post2", nil |
nothing calls this directly
no test coverage detected