Commit 9680c1a2 authored by ZJ van de Weg's avatar ZJ van de Weg Committed by iv

Incorporate feedback

parent 6782117d
......@@ -28,24 +28,26 @@ func (d *diff) Inject(w http.ResponseWriter, r *http.Request, sendData string) {
log.Printf("SendDiff: sending diff between %q and %q for %q", params.ShaFrom, params.ShaTo, r.URL.Path)
gitShowCmd := gitCommand("", "git", "--git-dir="+params.RepoPath, "diff", params.ShaFrom, params.ShaTo)
stdout, err := gitShowCmd.StdoutPipe()
gitDiffCmd := gitCommand("", "git", "--git-dir="+params.RepoPath, "diff", params.ShaFrom, params.ShaTo)
stdout, err := gitDiffCmd.StdoutPipe()
if err != nil {
helper.Fail500(w, fmt.Errorf("SendDiff: git diff %q %q stdout: %v", params.ShaFrom, params.ShaTo, err))
helper.Fail500(w, fmt.Errorf("SendDiff: create stdout pipe: %v", err))
return
}
if err := gitShowCmd.Start(); err != nil {
helper.Fail500(w, fmt.Errorf("SendDiff: git diff %q %q stdout: %v", params.ShaFrom, params.ShaTo, err))
if err := gitDiffCmd.Start(); err != nil {
helper.Fail500(w, fmt.Errorf("SendDiff: start %v: %v", gitDiffCmd, err))
return
}
defer helper.CleanUpProcessGroup(gitShowCmd)
defer helper.CleanUpProcessGroup(gitDiffCmd)
w.Header().Del("Content-Length")
if _, err := io.Copy(w, stdout); err != nil {
helper.LogError(fmt.Errorf("SendDiff: git diff %q %q stdout: %v", err))
helper.LogError(fmt.Errorf("SendDiff: copy %v stdout: %v", gitDiffCmd, err))
return
}
if err := gitShowCmd.Wait(); err != nil {
helper.LogError(fmt.Errorf("SendDiff: git diff %q %q stdout: %v", err))
if err := gitDiffCmd.Wait(); err != nil {
helper.LogError(fmt.Errorf("SendDiff: wait for %v: %v", gitDiffCmd, err))
return
}
}
......@@ -632,10 +632,10 @@ func TestGetGitDiff(t *testing.T) {
w.Header().Set(headerKey, "git-diff:"+encodedJSON)
return
})
defer ts.Close()
ws := startWorkhorseServer(ts.URL)
defer ts.Close()
defer ws.Close()
resourcePath := "/something"
resp, err := http.Get(ws.URL + resourcePath)
......@@ -658,6 +658,11 @@ func TestGetGitDiff(t *testing.T) {
if !strings.HasPrefix(string(body), "diff --git a/README b/README") {
t.Fatalf("diff --git a/README b/README, got %q", body)
}
bodyLengthBytes := len(body)
if bodyLengthBytes != 155 {
t.Fatal("Expected the body to consist of 155 bytes, got %v", bodyLengthBytes)
}
}
func setupStaticFile(fpath, content string) error {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment