diff options
author | John Cai <jcai@gitlab.com> | 2019-03-15 20:12:54 +0300 |
---|---|---|
committer | John Cai <jcai@gitlab.com> | 2019-03-15 20:12:54 +0300 |
commit | 76f60bee9929c13bbaf474d0a5fc4317897024d6 (patch) | |
tree | 0db5ed2753069cd81eaa07fbf46acca53b6d8d55 | |
parent | e0a17ab8618dd3c6a69a89e5fedcff41de848a0d (diff) | |
parent | 85a57c4c943e28e0ecf4a777e0d094380c341968 (diff) |
Merge branch 'pktline-bytes-written' into 'master'
Fix "bytes written" count in pktline.WriteString
See merge request gitlab-org/gitaly!1129
-rw-r--r-- | changelogs/unreleased/pktline-bytes-written.yml | 5 | ||||
-rw-r--r-- | internal/git/pktline/pkt_line_test.go | 8 | ||||
-rw-r--r-- | internal/git/pktline/pktline.go | 5 |
3 files changed, 12 insertions, 6 deletions
diff --git a/changelogs/unreleased/pktline-bytes-written.yml b/changelogs/unreleased/pktline-bytes-written.yml new file mode 100644 index 000000000..8caccbe2d --- /dev/null +++ b/changelogs/unreleased/pktline-bytes-written.yml @@ -0,0 +1,5 @@ +--- +title: Fix "bytes written" count in pktline.WriteString +merge_request: 1129 +author: +type: fixed diff --git a/internal/git/pktline/pkt_line_test.go b/internal/git/pktline/pkt_line_test.go index 25e2e799d..3024a31d1 100644 --- a/internal/git/pktline/pkt_line_test.go +++ b/internal/git/pktline/pkt_line_test.go @@ -138,14 +138,16 @@ func TestWriteString(t *testing.T) { for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { w := &bytes.Buffer{} - _, err := WriteString(w, tc.in) + n, err := WriteString(w, tc.in) if tc.fail { require.Error(t, err) - } else { - require.NoError(t, err) + return } + require.NoError(t, err) + require.Equal(t, len(tc.in), n, "number of bytes written reported by WriteString") + require.Equal(t, tc.out, w.String()) }) } diff --git a/internal/git/pktline/pktline.go b/internal/git/pktline/pktline.go index 8cb59239b..75eb490f9 100644 --- a/internal/git/pktline/pktline.go +++ b/internal/git/pktline/pktline.go @@ -3,8 +3,6 @@ package pktline // Utility functions for working with the Git pkt-line format. See // https://github.com/git/git/blob/master/Documentation/technical/protocol-common.txt -// TODO add tests https://gitlab.com/gitlab-org/gitaly/issues/1340 - import ( "bufio" "bytes" @@ -49,7 +47,8 @@ func WriteString(w io.Writer, str string) (int, error) { return 0, fmt.Errorf("string too large: %d bytes", len(str)) } - return fmt.Fprintf(w, "%04x%s", pktLen, str) + _, err := fmt.Fprintf(w, "%04x%s", pktLen, str) + return len(str), err } // WriteFlush writes a pkt flush packet. |