chore: use gofumpt for code formatting
This commit is contained in:
@@ -6,9 +6,7 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrRequestSizeTooSmall = errors.New("message size is too small")
|
||||
)
|
||||
var ErrRequestSizeTooSmall = errors.New("message size is too small")
|
||||
|
||||
func checkRequest(request []byte) (err error) {
|
||||
const minMessageSize = 2 // version number + operation code
|
||||
@@ -28,7 +26,8 @@ var (
|
||||
)
|
||||
|
||||
func checkResponse(response []byte, expectedOperationCode byte,
|
||||
expectedResponseSize uint) (err error) {
|
||||
expectedResponseSize uint,
|
||||
) (err error) {
|
||||
const minResponseSize = 4
|
||||
if len(response) < minResponseSize {
|
||||
return fmt.Errorf("%w: need at least %d bytes and got %d byte(s)",
|
||||
|
||||
@@ -13,7 +13,8 @@ import (
|
||||
// See https://www.ietf.org/rfc/rfc6886.html#section-3.2
|
||||
func (c *Client) ExternalAddress(ctx context.Context, gateway netip.Addr) (
|
||||
durationSinceStartOfEpoch time.Duration,
|
||||
externalIPv4Address netip.Addr, err error) {
|
||||
externalIPv4Address netip.Addr, err error,
|
||||
) {
|
||||
request := []byte{0, 0} // version 0, operationCode 0
|
||||
const responseSize = 12
|
||||
response, err := c.rpc(ctx, gateway, request, responseSize)
|
||||
|
||||
@@ -57,8 +57,7 @@ func Test_Client_ExternalAddress(t *testing.T) {
|
||||
maxRetries: 1,
|
||||
}
|
||||
|
||||
durationSinceStartOfEpoch, externalIPv4Address, err :=
|
||||
client.ExternalAddress(testCase.ctx, testCase.gateway)
|
||||
durationSinceStartOfEpoch, externalIPv4Address, err := client.ExternalAddress(testCase.ctx, testCase.gateway)
|
||||
assert.ErrorIs(t, err, testCase.err)
|
||||
if testCase.err != nil {
|
||||
assert.EqualError(t, err, testCase.errMessage)
|
||||
|
||||
@@ -27,7 +27,8 @@ type udpExchange struct {
|
||||
// port is dynamically assigned by the OS so calling tests
|
||||
// can run in parallel.
|
||||
func launchUDPServer(t *testing.T, exchanges []udpExchange) (
|
||||
remoteAddress *net.UDPAddr) {
|
||||
remoteAddress *net.UDPAddr,
|
||||
) {
|
||||
t.Helper()
|
||||
|
||||
conn, err := net.ListenUDP("udp", nil)
|
||||
|
||||
@@ -21,7 +21,8 @@ func (c *Client) AddPortMapping(ctx context.Context, gateway netip.Addr,
|
||||
protocol string, internalPort, requestedExternalPort uint16,
|
||||
lifetime time.Duration) (durationSinceStartOfEpoch time.Duration,
|
||||
assignedInternalPort, assignedExternalPort uint16, assignedLifetime time.Duration,
|
||||
err error) {
|
||||
err error,
|
||||
) {
|
||||
lifetimeSecondsFloat := lifetime.Seconds()
|
||||
const maxLifetimeSeconds = uint64(^uint32(0))
|
||||
if uint64(lifetimeSecondsFloat) > maxLifetimeSeconds {
|
||||
|
||||
@@ -127,10 +127,9 @@ func Test_Client_AddPortMapping(t *testing.T) {
|
||||
}
|
||||
|
||||
durationSinceStartOfEpoch, assignedInternalPort,
|
||||
assignedExternalPort, assignedLifetime, err :=
|
||||
client.AddPortMapping(testCase.ctx, testCase.gateway,
|
||||
testCase.protocol, testCase.internalPort,
|
||||
testCase.requestedExternalPort, testCase.lifetime)
|
||||
assignedExternalPort, assignedLifetime, err := client.AddPortMapping(testCase.ctx, testCase.gateway,
|
||||
testCase.protocol, testCase.internalPort,
|
||||
testCase.requestedExternalPort, testCase.lifetime)
|
||||
|
||||
assert.Equal(t, testCase.durationSinceStartOfEpoch, durationSinceStartOfEpoch)
|
||||
assert.Equal(t, testCase.assignedInternalPort, assignedInternalPort)
|
||||
|
||||
@@ -18,7 +18,8 @@ var (
|
||||
|
||||
func (c *Client) rpc(ctx context.Context, gateway netip.Addr,
|
||||
request []byte, responseSize uint) (
|
||||
response []byte, err error) {
|
||||
response []byte, err error,
|
||||
) {
|
||||
if gateway.IsUnspecified() || !gateway.IsValid() {
|
||||
return nil, fmt.Errorf("%w", ErrGatewayIPUnspecified)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user