Add request/version resource

This commit is contained in:
Héctor Hurtado
2020-09-08 15:27:51 +02:00
parent 092dc741a3
commit 9988d0e0d4
3 changed files with 71 additions and 4 deletions
+60 -4
View File
@@ -206,6 +206,22 @@ func TestGetRequestHost200sOnHappyPath(t *testing.T) {
}
}
func TestGetRequestHostSetsOctectStreamContentType(t *testing.T) {
h := model.Handler{
Request: httptest.NewRequest("POST", "/", nil),
Writer: httptest.NewRecorder(),
}
r := httptest.NewRequest("GET", "/not-important-here", nil)
w := httptest.NewRecorder()
getRequestHost(w, r, &h)
res := w.Result()
if res.Header.Get("Content-Type") != "application/octet-stream" {
t.Error("Content Type mismatch")
}
}
func TestGetRequestHostReturnsTheCorrectHostname(t *testing.T) {
h := model.Handler{
Request: httptest.NewRequest("POST", "http://www.foo.bar:8080/", nil),
@@ -222,7 +238,7 @@ func TestGetRequestHostReturnsTheCorrectHostname(t *testing.T) {
}
}
func TestGetRequestHostSetsOctectStreamContentType(t *testing.T) {
func TestGetRequestVersion200sOnHappyPath(t *testing.T) {
h := model.Handler{
Request: httptest.NewRequest("POST", "/", nil),
Writer: httptest.NewRecorder(),
@@ -230,14 +246,48 @@ func TestGetRequestHostSetsOctectStreamContentType(t *testing.T) {
r := httptest.NewRequest("GET", "/not-important-here", nil)
w := httptest.NewRecorder()
getRequestHost(w, r, &h)
getRequestVersion(w, r, &h)
res := w.Result()
if res.Header.Get("Content-Type") != "application/octet-stream" {
t.Error("Content Type mismatch")
if res.StatusCode != http.StatusOK {
t.Errorf("Status code mismatch. Expected: %d, got: %d", http.StatusOK, res.StatusCode)
}
}
func TestGetRequestVersionSetsOctectStreamContentType(t *testing.T) {
h := model.Handler{
Request: httptest.NewRequest("POST", "/", nil),
Writer: httptest.NewRecorder(),
}
r := httptest.NewRequest("GET", "/not-important-here", nil)
w := httptest.NewRecorder()
getRequestVersion(w, r, &h)
res := w.Result()
if ct := res.Header.Get("Content-Type"); ct != "application/octet-stream" {
t.Errorf("Content Type mismatch. Expected: %v, got: %v", "application/octet-stream", ct)
}
}
func TestGetRequestVersionReturnsTheCorrectHttpVersion(t *testing.T) {
h := model.Handler{
Request: httptest.NewRequest("POST", "http://www.foo.bar:8080/", nil),
Writer: httptest.NewRecorder(),
}
r := httptest.NewRequest("GET", "/not-important-here", nil)
w := httptest.NewRecorder()
getRequestVersion(w, r, &h)
res := w.Result()
if body, _ := ioutil.ReadAll(res.Body); string(body) != "HTTP/1.1" {
t.Errorf("Version mismatch. Expected %v, got %v", "HTTP/1.1", string(body))
}
}
// DOING #85: /request/remote
func TestGetRequestPath200sOnHappyPath(t *testing.T) {
h := model.Handler{
Request: httptest.NewRequest("POST", "/", nil),
@@ -302,6 +352,8 @@ func TestGetRequestPathDoesntReturnQueryStringParams(t *testing.T) {
}
}
// DOING #113: /request/ssl/client/i/dn
func createMuxRequest(pattern, url, method string, content io.Reader) (req *http.Request) {
m := mux.NewRouter()
m.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) { req = r })
@@ -589,6 +641,8 @@ func TestGetRequestHeadersReturnsTheFirstCorrectMatchValue(t *testing.T) {
}
}
// DOING #78: /request/headers/Host /request/headers/host
func TestGetRequestCookies200sOnHappyPath(t *testing.T) {
h := model.Handler{
Request: httptest.NewRequest("GET", "/", nil),
@@ -1005,6 +1059,8 @@ func TestGetRequestFileContent500sWhenHandlerRequestErrors(t *testing.T) {
}
}
// DOING #10: /route/id
func TestSetResponseStatus200sOnHappyPath(t *testing.T) {
h := model.Handler{
Request: httptest.NewRequest("POST", "/", nil),