Implement Phase 4 test coverage
This commit is contained in:
@@ -2,6 +2,7 @@ package app
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"testing"
|
||||
)
|
||||
@@ -17,6 +18,9 @@ func TestParseGitPath(t *testing.T) {
|
||||
if _, _, _, ok := parseGitPath("/bad/path"); ok {
|
||||
t.Fatal("expected invalid path")
|
||||
}
|
||||
if _, _, _, ok := parseGitPath("/too/many/parts.git/info/refs"); ok {
|
||||
t.Fatal("expected invalid owner/repo path")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGitService(t *testing.T) {
|
||||
@@ -28,4 +32,34 @@ func TestGitService(t *testing.T) {
|
||||
if got := gitService(req); got != "git-receive-pack" {
|
||||
t.Fatalf("unexpected receive-pack service: %q", got)
|
||||
}
|
||||
req = &http.Request{Method: http.MethodGet, URL: &url.URL{Path: "/alice/demo.git/info/refs"}}
|
||||
if got := gitService(req); got != "git-upload-pack" {
|
||||
t.Fatalf("default service = %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteCGIResponse(t *testing.T) {
|
||||
rr := httptest.NewRecorder()
|
||||
writeCGIResponse(rr, []byte("Status: 201 Created\r\nContent-Type: text/plain\r\nX-Test: one\r\n\r\nbody"))
|
||||
if rr.Code != http.StatusCreated {
|
||||
t.Fatalf("status = %d", rr.Code)
|
||||
}
|
||||
if rr.Header().Get("Content-Type") != "text/plain" || rr.Header().Get("X-Test") != "one" {
|
||||
t.Fatalf("unexpected headers: %#v", rr.Header())
|
||||
}
|
||||
if rr.Body.String() != "body" {
|
||||
t.Fatalf("body = %q", rr.Body.String())
|
||||
}
|
||||
|
||||
rr = httptest.NewRecorder()
|
||||
writeCGIResponse(rr, []byte("Content-Type: text/plain\n\nplain"))
|
||||
if rr.Code != http.StatusOK || rr.Body.String() != "plain" {
|
||||
t.Fatalf("status/body = %d/%q", rr.Code, rr.Body.String())
|
||||
}
|
||||
|
||||
rr = httptest.NewRecorder()
|
||||
writeCGIResponse(rr, []byte("raw"))
|
||||
if rr.Body.String() != "raw" {
|
||||
t.Fatalf("raw body = %q", rr.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user