Black Lives Matter. Support the Equal Justice Initiative.

Source file src/internal/poll/fd_posix_test.go

Documentation: internal/poll

     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 aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || windows
     6  // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris windows
     7  
     8  package poll_test
     9  
    10  import (
    11  	. "internal/poll"
    12  	"io"
    13  	"testing"
    14  )
    15  
    16  var eofErrorTests = []struct {
    17  	n        int
    18  	err      error
    19  	fd       *FD
    20  	expected error
    21  }{
    22  	{100, nil, &FD{ZeroReadIsEOF: true}, nil},
    23  	{100, io.EOF, &FD{ZeroReadIsEOF: true}, io.EOF},
    24  	{100, ErrNetClosing, &FD{ZeroReadIsEOF: true}, ErrNetClosing},
    25  	{0, nil, &FD{ZeroReadIsEOF: true}, io.EOF},
    26  	{0, io.EOF, &FD{ZeroReadIsEOF: true}, io.EOF},
    27  	{0, ErrNetClosing, &FD{ZeroReadIsEOF: true}, ErrNetClosing},
    28  
    29  	{100, nil, &FD{ZeroReadIsEOF: false}, nil},
    30  	{100, io.EOF, &FD{ZeroReadIsEOF: false}, io.EOF},
    31  	{100, ErrNetClosing, &FD{ZeroReadIsEOF: false}, ErrNetClosing},
    32  	{0, nil, &FD{ZeroReadIsEOF: false}, nil},
    33  	{0, io.EOF, &FD{ZeroReadIsEOF: false}, io.EOF},
    34  	{0, ErrNetClosing, &FD{ZeroReadIsEOF: false}, ErrNetClosing},
    35  }
    36  
    37  func TestEOFError(t *testing.T) {
    38  	for _, tt := range eofErrorTests {
    39  		actual := tt.fd.EOFError(tt.n, tt.err)
    40  		if actual != tt.expected {
    41  			t.Errorf("eofError(%v, %v, %v): expected %v, actual %v", tt.n, tt.err, tt.fd.ZeroReadIsEOF, tt.expected, actual)
    42  		}
    43  	}
    44  }
    45  

View as plain text