github.com/pion/dtls/v2@v2.2.12/errors_errno_test.go (about)

     1  // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
     2  // SPDX-License-Identifier: MIT
     3  
     4  //go:build aix || darwin || dragonfly || freebsd || linux || nacl || nacljs || netbsd || openbsd || solaris || windows
     5  // +build aix darwin dragonfly freebsd linux nacl nacljs netbsd openbsd solaris windows
     6  
     7  // For systems having syscall.Errno.
     8  // The build target must be same as errors_errno.go.
     9  
    10  package dtls
    11  
    12  import (
    13  	"errors"
    14  	"net"
    15  	"testing"
    16  )
    17  
    18  func TestErrorsTemporary(t *testing.T) {
    19  	addrListen, errListen := net.ResolveUDPAddr("udp", "localhost:0")
    20  	if errListen != nil {
    21  		t.Fatalf("Unexpected error: %v", errListen)
    22  	}
    23  	// Server is not listening.
    24  	conn, errDial := net.DialUDP("udp", nil, addrListen)
    25  	if errDial != nil {
    26  		t.Fatalf("Unexpected error: %v", errDial)
    27  	}
    28  
    29  	_, _ = conn.Write([]byte{0x00}) // trigger
    30  	_, err := conn.Read(make([]byte, 10))
    31  	_ = conn.Close()
    32  
    33  	if err == nil {
    34  		t.Skip("ECONNREFUSED is not set by system")
    35  	}
    36  
    37  	var ne net.Error
    38  	if !errors.As(netError(err), &ne) {
    39  		t.Fatalf("netError must return net.Error")
    40  	}
    41  
    42  	if ne.Timeout() {
    43  		t.Errorf("%v must not be timeout error", err)
    44  	}
    45  	if !ne.Temporary() { //nolint:staticcheck
    46  		t.Errorf("%v must be temporary error", err)
    47  	}
    48  }