Explorar el Código

Named router fixed + test coverage

tags/v0.9.0
jimzhan hace 9 años
padre
commit
aa2b4405ef
Se han modificado 2 ficheros con 17 adiciones y 2 borrados
  1. +3
    -2
      server.go
  2. +14
    -0
      server_test.go

+ 3
- 2
server.go Ver fichero

@@ -6,8 +6,8 @@ import (
"log"
"net/http"
"path/filepath"
"reflect"
"runtime"
"strings"
"sync"
"time"

@@ -69,8 +69,9 @@ func (self *server) build() http.Handler {

// register adds the http.Handler/http.HandleFunc into Gorilla mux.
func (self *server) register(pattern string, handler interface{}, methods ...string) {
var name = strings.Join(methods, "|") + ":" + pattern
// finds the full function name (with package) as its mappings.
var name = runtime.FuncForPC(reflect.ValueOf(handler).Pointer()).Name()
//var name = runtime.FuncForPC(reflect.ValueOf(handler).Pointer()).Name()

switch H := handler.(type) {
case http.Handler:

+ 14
- 0
server_test.go Ver fichero

@@ -106,6 +106,20 @@ func TestAny(t *testing.T) {
})
}

func TestName(t *testing.T) {
Convey("rex.Name", t, func() {
app := New()
app.GET("/login", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})

request, _ := http.NewRequest("GET", "/login", nil)
response := httptest.NewRecorder()
app.ServeHTTP(response, request)
So(app.Name(request), ShouldEqual, "GET:/login")
})
}

func TestGET(t *testing.T) {
app := New()
app.GET("/", func(w http.ResponseWriter, r *http.Request) {

Cargando…
Cancelar
Guardar