| 1 |
// Copyright 2012 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
//go:build unix || windows |
| 6 |
|
| 7 |
package poll_test |
| 8 |
|
| 9 |
import ( |
| 10 |
. "internal/poll" |
| 11 |
"io" |
| 12 |
"testing" |
| 13 |
) |
| 14 |
|
| 15 |
var eofErrorTests = []struct { |
| 16 |
n int |
| 17 |
err error |
| 18 |
fd *FD |
| 19 |
expected error |
| 20 |
}{ |
| 21 |
{100, nil, &FD{ZeroReadIsEOF: true}, nil}, |
| 22 |
{100, io.EOF, &FD{ZeroReadIsEOF: true}, io.EOF}, |
| 23 |
{100, ErrNetClosing, &FD{ZeroReadIsEOF: true}, ErrNetClosing}, |
| 24 |
{0, nil, &FD{ZeroReadIsEOF: true}, io.EOF}, |
| 25 |
{0, io.EOF, &FD{ZeroReadIsEOF: true}, io.EOF}, |
| 26 |
{0, ErrNetClosing, &FD{ZeroReadIsEOF: true}, ErrNetClosing}, |
| 27 |
|
| 28 |
{100, nil, &FD{ZeroReadIsEOF: false}, nil}, |
| 29 |
{100, io.EOF, &FD{ZeroReadIsEOF: false}, io.EOF}, |
| 30 |
{100, ErrNetClosing, &FD{ZeroReadIsEOF: false}, ErrNetClosing}, |
| 31 |
{0, nil, &FD{ZeroReadIsEOF: false}, nil}, |
| 32 |
{0, io.EOF, &FD{ZeroReadIsEOF: false}, io.EOF}, |
| 33 |
{0, ErrNetClosing, &FD{ZeroReadIsEOF: false}, ErrNetClosing}, |
| 34 |
} |
| 35 |
|
| 36 |
func TestEOFError(t *testing.T) { |
| 37 |
for _, tt := range eofErrorTests { |
| 38 |
actual := tt.fd.EOFError(tt.n, tt.err) |
| 39 |
if actual != tt.expected { |
| 40 |
t.Errorf("eofError(%v, %v, %v): expected %v, actual %v", tt.n, tt.err, tt.fd.ZeroReadIsEOF, tt.expected, actual) |
| 41 |
} |
| 42 |
} |
| 43 |
} |