зеркало из https://github.com/Azure/draft-classic.git
update reference to context key
This commit is contained in:
Родитель
639fd574b3
Коммит
ebfbd29618
|
@ -199,7 +199,7 @@ func buildApp(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
|||
var imagePrefix string
|
||||
baseValues := map[string]interface{}{}
|
||||
appName := p.ByName("id")
|
||||
server := r.Context().Value("server").(*Server)
|
||||
server := r.Context().Value(contextKey("server")).(*Server)
|
||||
namespace := r.Header.Get("Kubernetes-Namespace")
|
||||
flagWait := r.Header.Get("Helm-Flag-Wait")
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ import (
|
|||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
func TestPing(t *testing.T) {
|
||||
|
@ -26,3 +28,24 @@ func TestPing(t *testing.T) {
|
|||
t.Errorf("%s expected, received %s\n", "PONG", message)
|
||||
}
|
||||
}
|
||||
|
||||
func TestServerMiddleware(t *testing.T) {
|
||||
srv, err := NewServer("tcp", "0.0.0.0:4567")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer srv.Close()
|
||||
|
||||
router := httprouter.New()
|
||||
router.Handle("GET", "/", srv.Middleware(func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
||||
server := r.Context().Value(contextKey("server")).(*Server)
|
||||
if server != srv {
|
||||
t.Errorf("expected %v, got %v", srv, server)
|
||||
}
|
||||
}))
|
||||
srv.HTTPServer.Handler = router
|
||||
|
||||
if _, err := http.NewRequest("GET", "/", nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче