neterror_linux_test.go 912 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. package neterror
  4. import (
  5. "errors"
  6. "net"
  7. "os"
  8. "syscall"
  9. "testing"
  10. )
  11. func TestTreatAsLostUDP(t *testing.T) {
  12. tests := []struct {
  13. name string
  14. err error
  15. want bool
  16. }{
  17. {"nil", nil, false},
  18. {"non-nil", errors.New("foo"), false},
  19. {"eperm", syscall.EPERM, true},
  20. {
  21. name: "operror",
  22. err: &net.OpError{
  23. Op: "write",
  24. Err: &os.SyscallError{
  25. Syscall: "sendto",
  26. Err: syscall.EPERM,
  27. },
  28. },
  29. want: true,
  30. },
  31. {
  32. name: "host_unreach",
  33. err: &net.OpError{
  34. Op: "write",
  35. Err: &os.SyscallError{
  36. Syscall: "sendto",
  37. Err: syscall.EHOSTUNREACH,
  38. },
  39. },
  40. want: false,
  41. },
  42. }
  43. for _, tt := range tests {
  44. t.Run(tt.name, func(t *testing.T) {
  45. if got := TreatAsLostUDP(tt.err); got != tt.want {
  46. t.Errorf("got = %v; want %v", got, tt.want)
  47. }
  48. })
  49. }
  50. }