1
0
mirror of https://github.com/golang/go synced 2024-11-18 22:55:23 -07:00

go.tools/dashboard/app: fix tests and add TODO to reall fix them

This change is a really nasty hack to preserve the magic header
across requests. The nasty hack will go away once we refactor these
tests to use the new "appengine/aetest" package instead.

R=golang-dev, dvyukov
CC=golang-dev
https://golang.org/cl/39230043
This commit is contained in:
Andrew Gerrand 2013-12-10 15:30:35 +11:00
parent 866b24e166
commit 922f326cd7

View File

@ -7,10 +7,9 @@
package build package build
// TODO(adg): test authentication // TODO(adg): test authentication
// TODO(adg): refactor to use appengine/aetest instead
import ( import (
"appengine"
"appengine/datastore"
"bytes" "bytes"
"encoding/json" "encoding/json"
"errors" "errors"
@ -21,6 +20,9 @@ import (
"net/url" "net/url"
"strings" "strings"
"time" "time"
"appengine"
"appengine/datastore"
) )
func init() { func init() {
@ -141,6 +143,12 @@ func testHandler(w http.ResponseWriter, r *http.Request) {
} }
} }
origReq := *r
defer func() {
// HACK: We need to clobber the original request (see below)
// so make sure we fix it before exiting the handler.
*r = origReq
}()
for i, t := range testRequests { for i, t := range testRequests {
c.Infof("running test %d %s", i, t.path) c.Infof("running test %d %s", i, t.path)
errorf := func(format string, args ...interface{}) { errorf := func(format string, args ...interface{}) {
@ -165,11 +173,13 @@ func testHandler(w http.ResponseWriter, r *http.Request) {
if t.req != nil { if t.req != nil {
req.Method = "POST" req.Method = "POST"
} }
req.Header = r.Header req.Header = origReq.Header
rec := httptest.NewRecorder() rec := httptest.NewRecorder()
// Make the request // Make the request
http.DefaultServeMux.ServeHTTP(rec, req) *r = *req // HACK: App Engine uses the request pointer
// as a map key to resolve Contexts.
http.DefaultServeMux.ServeHTTP(rec, r)
if rec.Code != 0 && rec.Code != 200 { if rec.Code != 0 && rec.Code != 200 {
errorf(rec.Body.String()) errorf(rec.Body.String())