mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix a bug in Output.Write, and improve testing coverage of error cases.
This commit is contained in:
parent
3553a803e3
commit
35d54c6655
2 changed files with 23 additions and 1 deletions
|
@ -89,7 +89,7 @@ func (o *Output) Write(p []byte) (n int, err error) {
|
||||||
firstErr = err
|
firstErr = err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return len(p), err
|
return len(p), firstErr
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close unregisters all destinations and waits for all background
|
// Close unregisters all destinations and waits for all background
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -208,6 +209,27 @@ func TestOutputAdd(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestOutputWriteError(t *testing.T) {
|
||||||
|
o := NewOutput()
|
||||||
|
buf := &bytes.Buffer{}
|
||||||
|
o.Add(buf)
|
||||||
|
r, w := io.Pipe()
|
||||||
|
input := "Hello there"
|
||||||
|
expectedErr := fmt.Errorf("This is an error")
|
||||||
|
r.CloseWithError(expectedErr)
|
||||||
|
o.Add(w)
|
||||||
|
n, err := o.Write([]byte(input))
|
||||||
|
if err != expectedErr {
|
||||||
|
t.Fatalf("Output.Write() should return the first error encountered, if any")
|
||||||
|
}
|
||||||
|
if buf.String() != input {
|
||||||
|
t.Fatalf("Output.Write() should attempt write on all destinations, even after encountering an error")
|
||||||
|
}
|
||||||
|
if n != len(input) {
|
||||||
|
t.Fatalf("Output.Write() should return the size of the input if it successfully writes to at least one destination")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestInputAddEmpty(t *testing.T) {
|
func TestInputAddEmpty(t *testing.T) {
|
||||||
i := NewInput()
|
i := NewInput()
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
|
|
Loading…
Add table
Reference in a new issue