From 922f326cd730e64b189e818b4eca8f106a7c9ac4 Mon Sep 17 00:00:00 2001 From: Andrew Gerrand Date: Tue, 10 Dec 2013 15:30:35 +1100 Subject: [PATCH] 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 --- dashboard/app/build/test.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/dashboard/app/build/test.go b/dashboard/app/build/test.go index d78ba573..bfaf1c75 100644 --- a/dashboard/app/build/test.go +++ b/dashboard/app/build/test.go @@ -7,10 +7,9 @@ package build // TODO(adg): test authentication +// TODO(adg): refactor to use appengine/aetest instead import ( - "appengine" - "appengine/datastore" "bytes" "encoding/json" "errors" @@ -21,6 +20,9 @@ import ( "net/url" "strings" "time" + + "appengine" + "appengine/datastore" ) 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 { c.Infof("running test %d %s", i, t.path) errorf := func(format string, args ...interface{}) { @@ -165,11 +173,13 @@ func testHandler(w http.ResponseWriter, r *http.Request) { if t.req != nil { req.Method = "POST" } - req.Header = r.Header + req.Header = origReq.Header rec := httptest.NewRecorder() // 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 { errorf(rec.Body.String())