package httpd import ( "encoding/json" "net/http/httptest" "strings" "testing" "github.com/barerepo/server/internal/config" ) func TestALargeFileClientIsToldWhyRatherThanGivenA404(t *testing.T) { for _, path := range []string{ "/john/johnbot/info/lfs/objects/batch", "/john/johnbot.git/info/lfs/objects/batch", "/john/johnbot/info/lfs", } { r, ok := parseGitPath(path) if !ok || !r.LFS { t.Fatalf("parseGitPath(%q) did not recognise a large file request", path) } if r.Owner != "john" || r.Name != "johnbot" { t.Errorf("parseGitPath(%q) read %s/%s", path, r.Owner, r.Name) } } s := &Server{Cfg: config.Default()} w := httptest.NewRecorder() s.refuseLFS(w) if w.Code != 501 { t.Errorf("answered %d, want 501", w.Code) } if got := w.Header().Get("Content-Type"); got != "application/vnd.git-lfs+json" { t.Errorf("content type is %q, which git-lfs will not read as its own", got) } var body struct { Message string `json:"message"` } if err := json.Unmarshal(w.Body.Bytes(), &body); err != nil { t.Fatalf("the body is not json git-lfs can read: %v", err) } if !strings.Contains(body.Message, "off on this server") { t.Errorf("the message does not say why: %q", body.Message) } }