unix: test anyToSockaddr without creating actual socket

Test_anyToSockaddr on linux needs to create a socket with the given
domain, type and protocol in order to test anyToSockaddr. Depending on
kernel version, permission and other factors, a given combination might
not be available on the system that runs the test, as is e.g. the case
for AF_CAN/SOCK_DGRAM/CAN_J1939 on several builders after CL 272767.

The only reason to create the socket is to be able to get the socket
protocol in anyToSockaddr using GetsockoptInt(..., SO_PROTOCOL). Move
this implementation into a wrapper func which can be overriden in tests
to with a func unconditionally returning the protocol under test. This
makes the test less dependent on the system it runs on and should fix
the builders broken by CL 272767.

While at it also removed the unused SocketSpec type in
syscall_internal_bsd_test.go and remove an unnecessary error var
declaration.

Change-Id: Ie8754cf795fa96980b29ae43777f698cd86ae863
Reviewed-on: https://go-review.googlesource.com/c/sys/+/274046
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
4 files changed
tree: 6b9e34eb9999a03cf54c73935a43769b79854038
  1. cpu/
  2. internal/
  3. plan9/
  4. unix/
  5. windows/
  6. .gitattributes
  7. .gitignore
  8. AUTHORS
  9. codereview.cfg
  10. CONTRIBUTING.md
  11. CONTRIBUTORS
  12. go.mod
  13. LICENSE
  14. PATENTS
  15. README.md
README.md

sys

This repository holds supplemental Go packages for low-level interactions with the operating system.

Download/Install

The easiest way to install is to run go get -u golang.org/x/sys. You can also manually git clone the repository to $GOPATH/src/golang.org/x/sys.

Report Issues / Send Patches

This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see https://golang.org/doc/contribute.html.

The main issue tracker for the sys repository is located at https://github.com/golang/go/issues. Prefix your issue with “x/sys:” in the subject line, so it is easy to find.