cri-o/vendor/github.com/emicklei/go-restful/examples/restful-route_test.go
Jacek J. Łakis bf51655a7b vendor: Update vendoring for the exec client and server implementations
Signed-off-by: Jacek J. Łakis <jacek.lakis@intel.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2017-04-24 18:38:41 +02:00

39 lines
845 B
Go

package main
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/emicklei/go-restful"
)
var (
Result string
)
func TestRouteExtractParameter(t *testing.T) {
// setup service
ws := new(restful.WebService)
ws.Consumes(restful.MIME_XML)
ws.Route(ws.GET("/test/{param}").To(DummyHandler))
restful.Add(ws)
// setup request + writer
bodyReader := strings.NewReader("<Sample><Value>42</Value></Sample>")
httpRequest, _ := http.NewRequest("GET", "/test/THIS", bodyReader)
httpRequest.Header.Set("Content-Type", restful.MIME_XML)
httpWriter := httptest.NewRecorder()
// run
restful.DefaultContainer.ServeHTTP(httpWriter, httpRequest)
if Result != "THIS" {
t.Fatalf("Result is actually: %s", Result)
}
}
func DummyHandler(rq *restful.Request, rp *restful.Response) {
Result = rq.PathParameter("param")
}