mirror of https://github.com/docker/docs.git
inmem: PipeSender and PipeReceiver return clean nil values
This is necessary because `(*PipeSender)nil` is not equal to `(interface{})nil`. Signed-off-by: Solomon Hykes <solomon@docker.com>
This commit is contained in:
parent
048bed0cd1
commit
1508c1d46f
|
@ -170,7 +170,21 @@ type PipeReceiver struct {
|
|||
}
|
||||
|
||||
func (r *PipeReceiver) Receive(mode int) (*Message, Receiver, Sender, error) {
|
||||
return r.p.receive(mode)
|
||||
msg, pin, pout, err := r.p.receive(mode)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
var (
|
||||
in Receiver
|
||||
out Sender
|
||||
)
|
||||
if pin != nil {
|
||||
in = pin
|
||||
}
|
||||
if pout != nil {
|
||||
out = pout
|
||||
}
|
||||
return msg, in, out, err
|
||||
}
|
||||
|
||||
func (r *PipeReceiver) Close() error {
|
||||
|
@ -189,7 +203,18 @@ type PipeSender struct {
|
|||
}
|
||||
|
||||
func (w *PipeSender) Send(msg *Message, mode int) (Receiver, Sender, error) {
|
||||
return w.p.send(msg, mode)
|
||||
pin, pout, err := w.p.send(msg, mode)
|
||||
var (
|
||||
in Receiver
|
||||
out Sender
|
||||
)
|
||||
if pin != nil {
|
||||
in = pin
|
||||
}
|
||||
if pout != nil {
|
||||
out = pout
|
||||
}
|
||||
return in, out, err
|
||||
}
|
||||
|
||||
func (w *PipeSender) ReceiveFrom(src Receiver) (int, error) {
|
||||
|
|
|
@ -51,34 +51,26 @@ func TestSimpleSend(t *testing.T) {
|
|||
// If any of these conditions are not met, t.Fatal is called and the active
|
||||
// test fails.
|
||||
func assertMode(t *testing.T, r Receiver, w Sender, mode int) {
|
||||
pr, ok := r.(*PipeReceiver)
|
||||
if !ok {
|
||||
t.Fatalf("%v", r)
|
||||
}
|
||||
pw, ok := w.(*PipeSender)
|
||||
if !ok {
|
||||
t.Fatalf("%v", w)
|
||||
}
|
||||
// If mode has the R bit set, r must be non-nil
|
||||
if mode&R != 0 {
|
||||
if pr == nil {
|
||||
t.Fatalf("should be non-nil: %#v", pr)
|
||||
if r == nil {
|
||||
t.Fatalf("should be non-nil: %#v", r)
|
||||
}
|
||||
// Otherwise it must be nil.
|
||||
} else {
|
||||
if pr != nil {
|
||||
t.Fatalf("should be nil: %#v", pr)
|
||||
if r != nil {
|
||||
t.Fatalf("should be nil: %#v", r)
|
||||
}
|
||||
}
|
||||
// If mode has the W bit set, w must be non-nil
|
||||
if mode&W != 0 {
|
||||
if pw == nil {
|
||||
t.Fatalf("should be non-nil: %#v", pw)
|
||||
if w == nil {
|
||||
t.Fatalf("should be non-nil: %#v", w)
|
||||
}
|
||||
// Otherwise it must be nil.
|
||||
} else {
|
||||
if pw != nil {
|
||||
t.Fatalf("should be nil: %#v", pw)
|
||||
if w != nil {
|
||||
t.Fatalf("should be nil: %#v", w)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue