Sfoglia il codice sorgente

test coverage++

tags/v0.9.0
jimzhan 9 anni fa
parent
commit
ab9145ca0d
2 ha cambiato i file con 47 aggiunte e 3 eliminazioni
  1. +1
    -1
      server.go
  2. +46
    -2
      server_test.go

+ 1
- 1
server.go Vedi File

self.mux.HandleFunc(pattern, H).Methods(methods...).Name(name) self.mux.HandleFunc(pattern, H).Methods(methods...).Name(name)


default: default:
Fatalf("Unsupported handler (%s) passed in.", name)
panic("Unsupported handler: " + name)
} }
} }



+ 46
- 2
server_test.go Vedi File

w.WriteHeader(http.StatusAccepted) w.WriteHeader(http.StatusAccepted)
w.Header().Set("X-Auth-Server", "rex") w.Header().Set("X-Auth-Server", "rex")
}, "POST") }, "POST")
app.register("/signup", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusAccepted)
w.Header().Set("X-Auth-Server", "rex")
}), "POST")


request, _ := http.NewRequest("POST", "/login", nil) request, _ := http.NewRequest("POST", "/login", nil)
response := httptest.NewRecorder() response := httptest.NewRecorder()
app.ServeHTTP(response, request) app.ServeHTTP(response, request)
So(response.Code, ShouldEqual, http.StatusAccepted) So(response.Code, ShouldEqual, http.StatusAccepted)
So(response.Header().Get("X-Auth-Server"), ShouldEqual, "rex") So(response.Header().Get("X-Auth-Server"), ShouldEqual, "rex")

request, _ = http.NewRequest("POST", "/signup", nil)
response = httptest.NewRecorder()
app.ServeHTTP(response, request)
So(response.Code, ShouldEqual, http.StatusAccepted)
So(response.Header().Get("X-Auth-Server"), ShouldEqual, "rex")

So(func() {
app.register("/panic", nil)
}, ShouldPanic)
}) })
} }


app := New() app := New()
app.GET("/", func(w http.ResponseWriter, r *http.Request) { app.GET("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Powered-By", "rex") w.Header().Set("X-Powered-By", "rex")
w.Header().Set("Content-Type", "application/json")
}) })


Convey("rex.GET", t, func() { Convey("rex.GET", t, func() {
app.ServeHTTP(response, request) app.ServeHTTP(response, request)


So(response.Header().Get("X-Powered-By"), ShouldEqual, "rex") So(response.Header().Get("X-Powered-By"), ShouldEqual, "rex")
So(response.Header().Get("Content-Type"), ShouldEqual, "application/json")
})
}

func TestHEAD(t *testing.T) {
app := New()
app.HEAD("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Powered-By", "rex")
})

Convey("rex.HEAD", t, func() {
request, _ := http.NewRequest("HEAD", "/", nil)
response := httptest.NewRecorder()

app.ServeHTTP(response, request)

So(response.Header().Get("X-Powered-By"), ShouldEqual, "rex")
})
}

func TestOPTIONS(t *testing.T) {
app := New()
app.OPTIONS("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Powered-By", "rex")
})

Convey("rex.OPTIONS", t, func() {
request, _ := http.NewRequest("OPTIONS", "/", nil)
response := httptest.NewRecorder()

app.ServeHTTP(response, request)

So(response.Header().Get("X-Powered-By"), ShouldEqual, "rex")
}) })
} }



Loading…
Annulla
Salva