git: teach *PktlineWriter.Flush() to respond to nil receiver

This commit is contained in:
Taylor Blau 2017-08-02 13:26:38 -06:00
parent 330e899466
commit a303cb7e27
2 changed files with 8 additions and 0 deletions

@ -87,6 +87,10 @@ func (w *PktlineWriter) Write(p []byte) (int, error) {
// writes the pkt-line's FLUSH packet, to signal that it is done writing this
// chunk of data.
func (w *PktlineWriter) Flush() error {
if w == nil {
return nil
}
if _, err := w.flush(); err != nil {
return err
}

@ -81,6 +81,10 @@ func TestPktlineWriterWritesMultiplePacketsGreaterThanMaxPacketLength(t *testing
assertPacketRead(t, pl, nil)
}
func TestPktlineWriterAllowsFlushesOnNil(t *testing.T) {
assert.NoError(t, (*PktlineWriter)(nil).Flush())
}
func TestPktlineWriterDoesntWrapItself(t *testing.T) {
itself := &PktlineWriter{}
nw := NewPktlineWriter(itself, 0)