mirror of
https://github.com/gortc/stun.git
synced 2025-09-26 20:41:36 +08:00
all: fix golangci-lint warnings
This commit is contained in:
@@ -90,6 +90,9 @@ issues:
|
||||
- linters: [godot]
|
||||
source: "\\/\\/\\s+}"
|
||||
|
||||
- linters: [gci]
|
||||
source: "#nosec"
|
||||
|
||||
linters:
|
||||
enable-all: true
|
||||
disable:
|
||||
@@ -102,6 +105,10 @@ linters:
|
||||
- gomnd
|
||||
- goerr113
|
||||
- testpackage
|
||||
- errorlint
|
||||
- wrapcheck
|
||||
- exhaustivestruct
|
||||
- nlreturn
|
||||
|
||||
run:
|
||||
skip-dirs:
|
||||
|
@@ -442,11 +442,9 @@ func TestDial(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() {
|
||||
if err = c.Close(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}()
|
||||
if err = c.Close(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDialError(t *testing.T) {
|
||||
@@ -455,6 +453,7 @@ func TestDialError(t *testing.T) {
|
||||
t.Fatal("error expected")
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientCloseErr(t *testing.T) {
|
||||
response := MustBuild(TransactionID, BindingSuccess)
|
||||
response.Encode()
|
||||
@@ -472,11 +471,9 @@ func TestClientCloseErr(t *testing.T) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer func() {
|
||||
if err, ok := c.Close().(CloseErr); !ok || err.AgentErr != io.ErrUnexpectedEOF {
|
||||
t.Error("unexpected close err")
|
||||
}
|
||||
}()
|
||||
if err, ok := c.Close().(CloseErr); !ok || err.AgentErr != io.ErrUnexpectedEOF {
|
||||
t.Error("unexpected close err")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithNoConnClose(t *testing.T) {
|
||||
@@ -618,13 +615,15 @@ func TestClientFinalizer(t *testing.T) {
|
||||
}
|
||||
clientFinalizer(c)
|
||||
reader := bufio.NewScanner(buf)
|
||||
var lines int
|
||||
var expectedLines = []string{
|
||||
"client: called finalizer on non-closed client: client not initialized",
|
||||
"client: called finalizer on non-closed client",
|
||||
"client: called finalizer on non-closed client: failed to close: " +
|
||||
"<nil> (connection), unexpected EOF (agent)",
|
||||
}
|
||||
var (
|
||||
lines int
|
||||
expectedLines = []string{
|
||||
"client: called finalizer on non-closed client: client not initialized",
|
||||
"client: called finalizer on non-closed client",
|
||||
"client: called finalizer on non-closed client: failed to close: " +
|
||||
"<nil> (connection), unexpected EOF (agent)",
|
||||
}
|
||||
)
|
||||
for reader.Scan() {
|
||||
if reader.Text() != expectedLines[lines] {
|
||||
t.Error(reader.Text(), "!=", expectedLines[lines])
|
||||
@@ -855,6 +854,7 @@ func TestClient_DoConcurrent(t *testing.T) {
|
||||
1, 5, 10, 25, 100, 500,
|
||||
} {
|
||||
t.Run(fmt.Sprintf("%d", concurrency), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
testClientDoConcurrent(t, concurrency)
|
||||
})
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ import (
|
||||
|
||||
var (
|
||||
workers = flag.Int("w", runtime.GOMAXPROCS(0), "concurrent workers")
|
||||
addr = flag.String("addr", fmt.Sprintf("localhost"), "target address")
|
||||
addr = flag.String("addr", "localhost", "target address")
|
||||
port = flag.Int("port", stun.DefaultPort, "target port")
|
||||
duration = flag.Duration("d", time.Minute, "benchmark duration")
|
||||
network = flag.String("net", "udp", "protocol to use (udp, tcp)")
|
||||
|
@@ -13,9 +13,7 @@ import (
|
||||
"gortc.io/stun"
|
||||
)
|
||||
|
||||
var (
|
||||
server = flag.String("server", fmt.Sprintf("gortc.io:3478"), "Stun server address")
|
||||
)
|
||||
var server = flag.String("server", "gortc.io:3478", "Stun server address")
|
||||
|
||||
const (
|
||||
udp = "udp4"
|
||||
|
6
fuzz.go
6
fuzz.go
@@ -7,9 +7,7 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var (
|
||||
m = New()
|
||||
)
|
||||
var m = New()
|
||||
|
||||
// FuzzMessage is go-fuzz endpoint for message.
|
||||
func FuzzMessage(data []byte) int {
|
||||
@@ -96,7 +94,7 @@ func FuzzSetters(data []byte) int {
|
||||
{new(MappedAddress), AttrMappedAddress},
|
||||
{new(Realm), AttrRealm},
|
||||
}
|
||||
var firstByte = byte(0)
|
||||
firstByte := byte(0)
|
||||
if len(data) > 0 {
|
||||
firstByte = data[0]
|
||||
}
|
||||
|
@@ -102,6 +102,7 @@ func BenchmarkMessageIntegrity_AddTo(b *testing.B) {
|
||||
m.Reset()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMessageIntegrity_Check(b *testing.B) {
|
||||
m := new(Message)
|
||||
// TODO: Find a way to make this test zero-alloc without excessive pre-alloc.
|
||||
|
@@ -416,7 +416,7 @@ const (
|
||||
var (
|
||||
// Binding request message type.
|
||||
BindingRequest = NewType(MethodBinding, ClassRequest)
|
||||
// Binding success response message type
|
||||
// Binding success response message type.
|
||||
BindingSuccess = NewType(MethodBinding, ClassSuccessResponse)
|
||||
// Binding error response message type.
|
||||
BindingError = NewType(MethodBinding, ClassErrorResponse)
|
||||
|
@@ -64,7 +64,7 @@ func BenchmarkMessage_Write(b *testing.B) {
|
||||
}
|
||||
|
||||
func TestMessageType_Value(t *testing.T) {
|
||||
var tests = []struct {
|
||||
tests := []struct {
|
||||
in MessageType
|
||||
out uint16
|
||||
}{
|
||||
@@ -82,7 +82,7 @@ func TestMessageType_Value(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMessageType_ReadValue(t *testing.T) {
|
||||
var tests = []struct {
|
||||
tests := []struct {
|
||||
in uint16
|
||||
out MessageType
|
||||
}{
|
||||
@@ -100,7 +100,7 @@ func TestMessageType_ReadValue(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMessageType_ReadWriteValue(t *testing.T) {
|
||||
var tests = []MessageType{
|
||||
tests := []MessageType{
|
||||
{Method: MethodBinding, Class: ClassRequest},
|
||||
{Method: MethodBinding, Class: ClassSuccessResponse},
|
||||
{Method: MethodBinding, Class: ClassErrorResponse},
|
||||
@@ -197,8 +197,10 @@ func TestMessage_AttrLengthLessThanHeader(t *testing.T) {
|
||||
|
||||
func TestMessage_AttrSizeLessThanLength(t *testing.T) {
|
||||
mType := MessageType{Method: MethodBinding, Class: ClassRequest}
|
||||
messageAttribute := RawAttribute{Length: 4,
|
||||
Value: []byte{1, 2, 3, 4}, Type: 0x1,
|
||||
messageAttribute := RawAttribute{
|
||||
Length: 4,
|
||||
Value: []byte{1, 2, 3, 4},
|
||||
Type: 0x1,
|
||||
}
|
||||
messageAttributes := Attributes{
|
||||
messageAttribute,
|
||||
@@ -497,7 +499,7 @@ func TestIsMessage(t *testing.T) {
|
||||
NewSoftware("software").AddTo(m)
|
||||
m.WriteHeader()
|
||||
|
||||
var tt = [...]struct {
|
||||
tt := [...]struct {
|
||||
in []byte
|
||||
out bool
|
||||
}{
|
||||
@@ -506,9 +508,11 @@ func TestIsMessage(t *testing.T) {
|
||||
{[]byte{1, 2, 4}, false}, // 2
|
||||
{[]byte{1, 2, 4, 5, 6, 7, 8, 9, 20}, false}, // 3
|
||||
{m.Raw, true}, // 5
|
||||
{[]byte{0, 0, 0, 0, 33, 18,
|
||||
{[]byte{
|
||||
0, 0, 0, 0, 33, 18,
|
||||
164, 66, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0}, true}, // 6
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
}, true}, // 6
|
||||
}
|
||||
for i, v := range tt {
|
||||
if got := IsMessage(v.in); got != v.out {
|
||||
|
Reference in New Issue
Block a user