From 1126a6a9cf2d991f86447756258f69f952c9f909 Mon Sep 17 00:00:00 2001 From: Daniel Adam Date: Thu, 4 Apr 2024 12:29:01 +0200 Subject: [PATCH 1/2] Update golangci-lint configuration and fix issues --- .golangci.yml | 27 +++---- dtls/client_test.go | 18 ++--- dtls/server/session.go | 2 +- dtls/server_test.go | 9 ++- message/codes/codes_test.go | 2 +- message/options.go | 2 +- message/pool/message.go | 51 +++++++------ message/status/status_test.go | 8 +- net/blockwise/blockwise.go | 2 +- .../limitParallelRequests_test.go | 5 +- net/connUDP_internal_test.go | 2 +- net/conn_test.go | 3 +- net/tlslistener_test.go | 12 +-- tcp/client_test.go | 18 ++--- tcp/clientobserve_test.go | 7 +- tcp/server_test.go | 11 +-- test/net/uri.go | 2 +- udp/client/conn_test.go | 76 +++++++++---------- udp/client/observe_test.go | 7 +- udp/client_test.go | 16 ++-- udp/server_test.go | 21 ++--- 21 files changed, 155 insertions(+), 146 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index aaf335db..bfceb7fc 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -8,9 +8,6 @@ linters-settings: gomoddirectives: replace-allow-list: - github.com/pion/dtls/v2 - testifylint: - disable: - - go-require linters: enable: @@ -19,12 +16,13 @@ linters: - bidichk # Checks for dangerous unicode character sequences - bodyclose # Checks whether HTTP response body is closed successfully # - copyloopvar # Detects places where loop variables are copied - - decorder # check declaration order and count of types, constants, variables and functions + - decorder # Check declaration order and count of types, constants, variables and functions - dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) - dupl # Tool for code clone detection - - durationcheck # check for two durations multiplied together + - dupword # A linter that checks for duplicate words in the source code (usually miswritten) + - durationcheck # Check for two durations multiplied together - errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases - - errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occations, where the check for the returned error can be omitted. + - errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted. - errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`. - errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. - execinquery # Execinquery is a linter about query string checker in Query function which reads your Go src files and warning it finds. @@ -56,12 +54,15 @@ linters: - loggercheck # Checks key value pairs for common logger libraries (kitlog,klog,logr,zap). - mirror # Reports wrong mirror patterns of bytes/strings usage - misspell # Finds commonly misspelled English words in comments + - nakedret # Finds naked returns in functions greater than a specified function length + - nestif # Reports deeply nested if statements - nilerr # Finds the code that returns nil even if it checks that the error is not nil. - nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value. - noctx # noctx finds sending http request without context.Context - nolintlint # Reports ill-formed or insufficient nolint directives - nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL - perfsprint # Checks that fmt.Sprintf can be replaced with a faster alternative. + - prealloc # Finds slice declarations that could potentially be preallocated - predeclared # find code that shadows one of Go's predeclared identifiers - protogetter # Reports direct reads from proto message fields when getters should be used. - revive # golint replacement, finds style mistakes @@ -70,6 +71,7 @@ linters: - spancheck # Checks for mistakes with OpenTelemetry/Census spans - staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks - stylecheck # Stylecheck is a replacement for golint + - tagliatelle # Checks the struct tags. - tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17 - testifylint # Checks usage of github.com/stretchr/testify. - tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes @@ -102,18 +104,14 @@ linters: - maintidx # maintidx measures the maintainability index of each function. - makezero # Finds slice declarations with non-zero initial length - maligned # Tool to detect Go structs that would take less memory if their fields were sorted - - nakedret # Finds naked returns in functions greater than a specified function length - - nestif # Reports deeply nested if statements - nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity - nonamedreturns # Reports all named returns - paralleltest # paralleltest detects missing usage of t.Parallel() method in your Go test - - prealloc # Finds slice declarations that could potentially be preallocated - promlinter # Check Prometheus metrics naming via promlint - rowserrcheck # checks whether Err of rows is checked successfully - sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed. - - structcheck # Finds unused struct fields - tagalign # Check that struct tags are well aligned. - - tagliatelle # Checks the struct tags. + - testableexamples # linter checks if examples are testable (have an expected output) - testpackage # linter that makes you use a separate _test package - thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers - varnamelen # checks that the length of a variable's name matches its scope @@ -127,11 +125,12 @@ issues: - path: _test\.go linters: - dupl + - dupword - forcetypeassert - gosec - gocyclo - gocognit - - perfsprint + - nakedret - path: ^test/.*\.go linters: @@ -140,7 +139,6 @@ issues: - gosec - gocyclo - gocognit - - perfsprint - path: example_test\.go text: "exitAfterDefer" @@ -163,3 +161,6 @@ issues: # # Fix found issues (if it's supported by the linter). # fix: true + +run: + go: "1.20" diff --git a/dtls/client_test.go b/dtls/client_test.go index 968c2bb5..60526191 100644 --- a/dtls/client_test.go +++ b/dtls/client_test.go @@ -111,7 +111,7 @@ func TestConnGet(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := dtls.Dial(l.Addr().String(), dtlsCfg) @@ -204,7 +204,7 @@ func TestConnGetSeparateMessage(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := dtls.Dial(l.Addr().String(), dtlsCfg, options.WithHandlerFunc(func(_ *responsewriter.ResponseWriter[*client.Conn], r *pool.Message) { @@ -330,7 +330,7 @@ func TestConnPost(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := dtls.Dial(l.Addr().String(), dtlsCfg) @@ -465,7 +465,7 @@ func TestConnPut(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := dtls.Dial(l.Addr().String(), dtlsCfg) @@ -577,7 +577,7 @@ func TestConnDelete(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := dtls.Dial(l.Addr().String(), dtlsCfg) @@ -637,7 +637,7 @@ func TestConnPing(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := dtls.Dial(l.Addr().String(), dtlsCfg) @@ -682,7 +682,7 @@ func TestConnHandeShakeFailure(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() dtlsCfgClient := &piondtls.Config{ @@ -738,7 +738,7 @@ func TestClientInactiveMonitor(t *testing.T) { go func() { defer serverWg.Done() errS := sd.Serve(ld) - require.NoError(t, errS) + assert.NoError(t, errS) }() defer func() { sd.Stop() @@ -798,7 +798,7 @@ func TestClientKeepAliveMonitor(t *testing.T) { } } defer c.Close() - require.NoError(t, errA) + assert.NoError(t, errA) } }() defer func() { diff --git a/dtls/server/session.go b/dtls/server/session.go index f1584aa0..0dd4ec67 100644 --- a/dtls/server/session.go +++ b/dtls/server/session.go @@ -112,7 +112,7 @@ func (s *Session) WriteMessage(req *pool.Message) error { } // WriteMulticastMessage sends multicast to the remote multicast address. -// Currently it is not implemented - is is just satisfy golang udp/client/Session interface. +// Currently it is not implemented - is just satisfy golang udp/client/Session interface. func (s *Session) WriteMulticastMessage(*pool.Message, *net.UDPAddr, ...coapNet.MulticastOption) error { return errors.New("multicast messages not implemented for DTLS") } diff --git a/dtls/server_test.go b/dtls/server_test.go index ca559556..30324fbc 100644 --- a/dtls/server_test.go +++ b/dtls/server_test.go @@ -25,6 +25,7 @@ import ( "github.com/plgd-dev/go-coap/v3/pkg/runner/periodic" "github.com/plgd-dev/go-coap/v3/udp/client" "github.com/plgd-dev/go-coap/v3/udp/coder" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/atomic" "golang.org/x/sync/semaphore" @@ -67,7 +68,7 @@ func TestServerCleanUpConns(t *testing.T) { go func() { defer wg.Done() errS := sd.Serve(ld) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := dtls.Dial(ld.Addr().String(), dtlsCfg) @@ -174,7 +175,7 @@ func TestServerSetContextValueWithPKI(t *testing.T) { defer sd.Stop() go func() { errS := sd.Serve(ld) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := dtls.Dial(ld.Addr().String(), clientCgf) @@ -233,7 +234,7 @@ func TestServerInactiveMonitor(t *testing.T) { go func() { defer serverWg.Done() errS := sd.Serve(ld) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := dtls.Dial(ld.Addr().String(), clientCgf) @@ -305,7 +306,7 @@ func TestServerKeepAliveMonitor(t *testing.T) { go func() { defer serverWg.Done() errS := sd.Serve(ld) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := piondtls.Dial("udp4", &net.UDPAddr{IP: []byte{127, 0, 0, 1}, Port: ld.Addr().(*net.UDPAddr).Port}, clientCgf) diff --git a/message/codes/codes_test.go b/message/codes/codes_test.go index 5a9c9142..ce469fde 100644 --- a/message/codes/codes_test.go +++ b/message/codes/codes_test.go @@ -73,7 +73,7 @@ func TestUnmarshalJSONMarshalUnmarshal(t *testing.T) { } func TestCodeToString(t *testing.T) { - var strCodes []string + strCodes := make([]string, 0, len(codeToString)) for _, val := range codeToString { strCodes = append(strCodes, val) } diff --git a/message/options.go b/message/options.go index b162f9a7..945c291c 100644 --- a/message/options.go +++ b/message/options.go @@ -265,7 +265,7 @@ func (options Options) SetBytes(buf []byte, id OptionID, data []byte) (Options, return options.Set(Option{ID: id, Value: buf[:len(data)]}), len(data), nil } -// AddBytes appends bytes of a option option to options. +// AddBytes appends bytes of a option to options. // // Returns modified options, number of used buf bytes and error if occurs. func (options Options) AddBytes(buf []byte, id OptionID, data []byte) (Options, int, error) { diff --git a/message/pool/message.go b/message/pool/message.go index a19f020e..82327243 100644 --- a/message/pool/message.go +++ b/message/pool/message.go @@ -603,33 +603,34 @@ func (r *Message) Clone(msg *Message) error { msg.SetMessageID(r.MessageID()) msg.SetControlMessage(r.ControlMessage()) - if r.Body() != nil { - buf := bytes.NewBuffer(nil) - n, err := r.Body().Seek(0, io.SeekCurrent) - if err != nil { - return err - } - _, err = r.body.Seek(0, io.SeekStart) - if err != nil { - return err - } - _, err = io.Copy(buf, r.Body()) - if err != nil { - var errs *multierror.Error - errs = multierror.Append(errs, err) - _, errS := r.Body().Seek(n, io.SeekStart) - if errS != nil { - errs = multierror.Append(errs, errS) - } - return errs.ErrorOrNil() - } - _, err = r.Body().Seek(n, io.SeekStart) - if err != nil { - return err + if r.Body() == nil { + return nil + } + buf := bytes.NewBuffer(nil) + n, err := r.Body().Seek(0, io.SeekCurrent) + if err != nil { + return err + } + _, err = r.body.Seek(0, io.SeekStart) + if err != nil { + return err + } + _, err = io.Copy(buf, r.Body()) + if err != nil { + var errs *multierror.Error + errs = multierror.Append(errs, err) + _, errS := r.Body().Seek(n, io.SeekStart) + if errS != nil { + errs = multierror.Append(errs, errS) } - r := bytes.NewReader(buf.Bytes()) - msg.SetBody(r) + return errs.ErrorOrNil() + } + _, err = r.Body().Seek(n, io.SeekStart) + if err != nil { + return err } + body := bytes.NewReader(buf.Bytes()) + msg.SetBody(body) return nil } diff --git a/message/status/status_test.go b/message/status/status_test.go index 6a744830..ee752a3e 100644 --- a/message/status/status_test.go +++ b/message/status/status_test.go @@ -2,7 +2,7 @@ package status import ( "context" - "fmt" + "errors" "testing" "github.com/plgd-dev/go-coap/v3/message/codes" @@ -15,7 +15,7 @@ func TestStatus(t *testing.T) { require.True(t, ok) require.Equal(t, OK, s.Code()) - _, ok = FromError(fmt.Errorf("test")) + _, ok = FromError(errors.New("test")) require.False(t, ok) msg := pool.NewMessage(context.TODO()) @@ -42,7 +42,7 @@ func TestStatus(t *testing.T) { err = FromContextError(context.DeadlineExceeded) require.Equal(t, Timeout, Code(err)) - err = FromContextError(fmt.Errorf("test")) + err = FromContextError(errors.New("test")) require.Equal(t, Unknown, Code(err)) - require.Equal(t, Unknown, Code(fmt.Errorf("test"))) + require.Equal(t, Unknown, Code(errors.New("test"))) } diff --git a/net/blockwise/blockwise.go b/net/blockwise/blockwise.go index 0157d692..a8dd4968 100644 --- a/net/blockwise/blockwise.go +++ b/net/blockwise/blockwise.go @@ -796,7 +796,7 @@ func (b *BlockWise[C]) processReceivedMessage(w *responsewriter.ResponseWriter[C return fmt.Errorf("cannot get payload: %w", err) } off := num * szx.Size() - if off == payloadSize { + if off == payloadSize { //nolint:nestif payloadSize, err = copyToPayloadFromOffset(r, payloadFile, off) if err != nil { return fmt.Errorf("cannot copy data to payload: %w", err) diff --git a/net/client/limitParallelRequests/limitParallelRequests_test.go b/net/client/limitParallelRequests/limitParallelRequests_test.go index a33e2c21..e4ebd9d3 100644 --- a/net/client/limitParallelRequests/limitParallelRequests_test.go +++ b/net/client/limitParallelRequests/limitParallelRequests_test.go @@ -9,6 +9,7 @@ import ( "github.com/plgd-dev/go-coap/v3/message/codes" "github.com/plgd-dev/go-coap/v3/message/pool" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/atomic" ) @@ -146,7 +147,7 @@ func TestLimitParallelRequestsDo(t *testing.T) { go func(r *pool.Message) { defer wg.Done() _, err := c.Do(r) - require.Error(t, err) + assert.Error(t, err) }(req) } wg.Wait() @@ -269,7 +270,7 @@ func TestLimitParallelRequestsDoObserve(t *testing.T) { _, err := c.DoObserve(r, func(*pool.Message) { // do nothing }) - require.Error(t, err) + assert.Error(t, err) }(req) } wg.Wait() diff --git a/net/connUDP_internal_test.go b/net/connUDP_internal_test.go index 0f122edd..5e1cf901 100644 --- a/net/connUDP_internal_test.go +++ b/net/connUDP_internal_test.go @@ -208,7 +208,7 @@ func TestUDPConnwriteMulticastWithContext(t *testing.T) { go func() { b := make([]byte, 1024) n, _, errR := c2.ReadWithContext(ctx, b) - require.NoError(t, errR) + assert.NoError(t, errR) if n > 0 { b = b[:n] assert.Equal(t, payload, b) diff --git a/net/conn_test.go b/net/conn_test.go index 16c16756..93e7d476 100644 --- a/net/conn_test.go +++ b/net/conn_test.go @@ -5,6 +5,7 @@ import ( "net" "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -58,7 +59,7 @@ func TestConnWriteWithContext(t *testing.T) { b := make([]byte, len(helloWorld)) _ = c.ReadFullWithContext(ctx, b) err = c.Close() - require.NoError(t, err) + assert.NoError(t, err) } }() diff --git a/net/tlslistener_test.go b/net/tlslistener_test.go index 56e356eb..5c9576c3 100644 --- a/net/tlslistener_test.go +++ b/net/tlslistener_test.go @@ -97,7 +97,7 @@ func TestTLSListenerAcceptWithContext(t *testing.T) { for i := 0; i < len(tests); i++ { time.Sleep(time.Millisecond * 200) cert, err := tls.X509KeyPair(CertPEMBlock, KeyPEMBlock) - require.NoError(t, err) + assert.NoError(t, err) c, err := tls.DialWithDialer(&net.Dialer{ Timeout: time.Millisecond * 400, @@ -109,10 +109,10 @@ func TestTLSListenerAcceptWithContext(t *testing.T) { continue } _, err = c.Write([]byte("hello")) - require.NoError(t, err) + assert.NoError(t, err) time.Sleep(time.Millisecond * 200) err = c.Close() - require.NoError(t, err) + assert.NoError(t, err) } }() @@ -183,7 +183,7 @@ func TestTLSListenerCheckForInfinitLoop(t *testing.T) { for i := 0; i < len(tests); i++ { time.Sleep(time.Millisecond * 200) cert, err := tls.X509KeyPair(CertPEMBlock, KeyPEMBlock) - require.NoError(t, err) + assert.NoError(t, err) func() { conn, err := net.Dial("tcp", listener.Addr().String()) if err != nil { @@ -194,14 +194,14 @@ func TestTLSListenerCheckForInfinitLoop(t *testing.T) { Certificates: []tls.Certificate{cert}, VerifyPeerCertificate: func([][]byte, [][]*x509.Certificate) error { errC := conn.Close() - require.NoError(t, errC) + assert.NoError(t, errC) return nil }, }) ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*300) defer cancel() err = tlsConn.HandshakeContext(ctx) - require.Error(t, err) + assert.Error(t, err) }() } }() diff --git a/tcp/client_test.go b/tcp/client_test.go index 5a02cea7..9cdec13b 100644 --- a/tcp/client_test.go +++ b/tcp/client_test.go @@ -96,7 +96,7 @@ func TestConnGet(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := Dial(l.Addr().String()) @@ -226,7 +226,7 @@ func TestConnPost(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := Dial(l.Addr().String()) @@ -354,7 +354,7 @@ func TestConnPut(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := Dial(l.Addr().String()) @@ -459,7 +459,7 @@ func TestConnDelete(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := Dial(l.Addr().String()) @@ -511,7 +511,7 @@ func TestConnPing(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := Dial(l.Addr().String()) @@ -566,7 +566,7 @@ func TestClientInactiveMonitor(t *testing.T) { go func() { defer serverWg.Done() errS := sd.Serve(ld) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := Dial( @@ -640,7 +640,7 @@ func TestClientKeepAliveMonitor(t *testing.T) { go func() { defer serverWg.Done() errS := sd.Serve(ld) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := Dial( @@ -725,7 +725,7 @@ func TestConnRequestMonitorCloseConnection(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := Dial(l.Addr().String(), @@ -807,7 +807,7 @@ func TestConnRequestMonitorDropRequest(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := Dial(l.Addr().String(), diff --git a/tcp/clientobserve_test.go b/tcp/clientobserve_test.go index 4c2297b2..cc9c83ef 100644 --- a/tcp/clientobserve_test.go +++ b/tcp/clientobserve_test.go @@ -15,6 +15,7 @@ import ( "github.com/plgd-dev/go-coap/v3/net/responsewriter" "github.com/plgd-dev/go-coap/v3/options" "github.com/plgd-dev/go-coap/v3/tcp/client" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -164,7 +165,7 @@ func TestConnObserve(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := Dial(l.Addr().String()) @@ -281,7 +282,7 @@ func TestConnObserveNotSupported(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := Dial(l.Addr().String()) @@ -382,7 +383,7 @@ func TestConnObserveCancel(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := Dial(l.Addr().String()) diff --git a/tcp/server_test.go b/tcp/server_test.go index cb2c64ed..124bd992 100644 --- a/tcp/server_test.go +++ b/tcp/server_test.go @@ -24,6 +24,7 @@ import ( "github.com/plgd-dev/go-coap/v3/tcp" "github.com/plgd-dev/go-coap/v3/tcp/client" "github.com/plgd-dev/go-coap/v3/tcp/coder" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/atomic" "golang.org/x/sync/semaphore" @@ -62,7 +63,7 @@ func TestServerCleanUpConns(t *testing.T) { go func() { defer wg.Done() errS := sd.Serve(ld) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := tcp.Dial(ld.Addr().String()) @@ -166,7 +167,7 @@ func TestServerSetContextValueWithPKI(t *testing.T) { defer sd.Stop() go func() { errS := sd.Serve(ld) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := tcp.Dial(ld.Addr().String(), options.WithTLS(clientCgf)) @@ -226,7 +227,7 @@ func TestServerInactiveMonitor(t *testing.T) { go func() { defer serverWg.Done() errS := sd.Serve(ld) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := tcp.Dial( @@ -297,7 +298,7 @@ func TestServerKeepAliveMonitor(t *testing.T) { go func() { defer serverWg.Done() errS := sd.Serve(ld) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := net.Dial("tcp", ld.Addr().String()) @@ -349,7 +350,7 @@ func TestCheckForLossOrder(t *testing.T) { go func() { defer wg.Done() errS := sd.Serve(ld) - require.NoError(t, errS) + assert.NoError(t, errS) }() defer func() { sd.Stop() diff --git a/test/net/uri.go b/test/net/uri.go index 82ae47c4..7957295e 100644 --- a/test/net/uri.go +++ b/test/net/uri.go @@ -48,7 +48,7 @@ func RandomValidURLString(n, maxSegmentLen int) string { } } - // ensure that at at least every maxSegmentLen-th character is '/', otherwise + // ensure that at least every maxSegmentLen-th character is '/', otherwise // SetPath will fail with invalid path error index := 0 for { diff --git a/udp/client/conn_test.go b/udp/client/conn_test.go index 49a4153e..4c70d6a6 100644 --- a/udp/client/conn_test.go +++ b/udp/client/conn_test.go @@ -67,7 +67,7 @@ func TestConnDeduplication(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := udp.Dial(l.LocalAddr().String(), @@ -152,7 +152,7 @@ func TestConnDeduplicationRetransmission(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := udp.Dial(l.LocalAddr().String(), @@ -268,7 +268,7 @@ func testParallelConnGet(t *testing.T, numParallel int) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := udp.Dial(l.LocalAddr().String()) @@ -289,19 +289,19 @@ func testParallelConnGet(t *testing.T, numParallel int) { defer cancel() got, err := cc.Get(ctx, tt.args.path, tt.args.opts...) if tt.wantErr { - require.Error(t, err) + assert.Error(t, err) return } - require.NoError(t, err) - require.Equal(t, tt.wantCode, got.Code()) + assert.NoError(t, err) + assert.Equal(t, tt.wantCode, got.Code()) if tt.wantContentFormat != nil { ct, err := got.ContentFormat() - require.NoError(t, err) - require.Equal(t, *tt.wantContentFormat, ct) + assert.NoError(t, err) + assert.Equal(t, *tt.wantContentFormat, ct) buf := bytes.NewBuffer(nil) _, err = buf.ReadFrom(got.Body()) - require.NoError(t, err) - require.Equal(t, tt.wantPayload, buf.Bytes()) + assert.NoError(t, err) + assert.Equal(t, tt.wantPayload, buf.Bytes()) } }() } @@ -369,7 +369,7 @@ func TestConnGetSeparateMessage(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := udp.Dial(l.LocalAddr().String(), options.WithHandlerFunc(func(_ *responsewriter.ResponseWriter[*client.Conn], r *pool.Message) { @@ -488,7 +488,7 @@ func testConnPost(t *testing.T, numParallel int) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := udp.Dial(l.LocalAddr().String()) @@ -507,19 +507,19 @@ func testConnPost(t *testing.T, numParallel int) { defer cancel() got, err := cc.Post(ctx, tt.args.path, tt.args.contentFormat, tt.args.payload, tt.args.opts...) if tt.wantErr { - require.Error(t, err) + assert.Error(t, err) return } - require.NoError(t, err) - require.Equal(t, tt.wantCode, got.Code()) + assert.NoError(t, err) + assert.Equal(t, tt.wantCode, got.Code()) if tt.wantContentFormat != nil { ct, err := got.ContentFormat() - require.NoError(t, err) - require.Equal(t, *tt.wantContentFormat, ct) + assert.NoError(t, err) + assert.Equal(t, *tt.wantContentFormat, ct) buf := bytes.NewBuffer(nil) _, err = buf.ReadFrom(got.Body()) - require.NoError(t, err) - require.Equal(t, tt.wantPayload, buf.Bytes()) + assert.NoError(t, err) + assert.Equal(t, tt.wantPayload, buf.Bytes()) } }() } @@ -631,7 +631,7 @@ func testConnPut(t *testing.T, numParallel int) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := udp.Dial(l.LocalAddr().String()) @@ -649,19 +649,19 @@ func testConnPut(t *testing.T, numParallel int) { defer cancel() got, err := cc.Put(ctx, tt.args.path, tt.args.contentFormat, tt.args.payload, tt.args.opts...) if tt.wantErr { - require.Error(t, err) + assert.Error(t, err) return } - require.NoError(t, err) - require.Equal(t, tt.wantCode, got.Code()) + assert.NoError(t, err) + assert.Equal(t, tt.wantCode, got.Code()) if tt.wantContentFormat != nil { ct, err := got.ContentFormat() - require.NoError(t, err) - require.Equal(t, *tt.wantContentFormat, ct) + assert.NoError(t, err) + assert.Equal(t, *tt.wantContentFormat, ct) buf := bytes.NewBuffer(nil) _, err = buf.ReadFrom(got.Body()) - require.NoError(t, err) - require.Equal(t, tt.wantPayload, buf.Bytes()) + assert.NoError(t, err) + assert.Equal(t, tt.wantPayload, buf.Bytes()) } }() } @@ -750,7 +750,7 @@ func testConnDelete(t *testing.T, numParallel int) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := udp.Dial(l.LocalAddr().String()) @@ -771,19 +771,19 @@ func testConnDelete(t *testing.T, numParallel int) { defer cancel() got, err := cc.Delete(ctx, tt.args.path, tt.args.opts...) if tt.wantErr { - require.Error(t, err) + assert.Error(t, err) return } - require.NoError(t, err) - require.Equal(t, tt.wantCode, got.Code()) + assert.NoError(t, err) + assert.Equal(t, tt.wantCode, got.Code()) if tt.wantContentFormat != nil { ct, err := got.ContentFormat() - require.NoError(t, err) - require.Equal(t, *tt.wantContentFormat, ct) + assert.NoError(t, err) + assert.Equal(t, *tt.wantContentFormat, ct) buf := bytes.NewBuffer(nil) _, err = buf.ReadFrom(got.Body()) - require.NoError(t, err) - require.Equal(t, tt.wantPayload, buf.Bytes()) + assert.NoError(t, err) + assert.Equal(t, tt.wantPayload, buf.Bytes()) } }() } @@ -817,7 +817,7 @@ func TestConnPing(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := udp.Dial(l.LocalAddr().String()) @@ -890,7 +890,7 @@ func TestConnRequestMonitorCloseConnection(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := udp.Dial(l.LocalAddr().String(), @@ -972,7 +972,7 @@ func TestConnRequestMonitorDropRequest(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := udp.Dial(l.LocalAddr().String(), diff --git a/udp/client/observe_test.go b/udp/client/observe_test.go index c005457b..1a2864f2 100644 --- a/udp/client/observe_test.go +++ b/udp/client/observe_test.go @@ -15,6 +15,7 @@ import ( "github.com/plgd-dev/go-coap/v3/options" "github.com/plgd-dev/go-coap/v3/udp" "github.com/plgd-dev/go-coap/v3/udp/client" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -157,7 +158,7 @@ func TestConnObserve(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := udp.Dial(l.LocalAddr().String()) @@ -280,7 +281,7 @@ func TestConnObserveNotSupported(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := udp.Dial(l.LocalAddr().String()) @@ -376,7 +377,7 @@ func TestConnObserveCancel(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := udp.Dial(l.LocalAddr().String()) diff --git a/udp/client_test.go b/udp/client_test.go index f577bbb7..654677d4 100644 --- a/udp/client_test.go +++ b/udp/client_test.go @@ -141,7 +141,7 @@ func TestConnGet(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := Dial(l.LocalAddr().String()) @@ -241,7 +241,7 @@ func TestConnGetSeparateMessage(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := Dial(l.LocalAddr().String(), options.WithHandlerFunc(func(_ *responsewriter.ResponseWriter[*client.Conn], r *pool.Message) { @@ -363,7 +363,7 @@ func TestConnPost(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := Dial(l.LocalAddr().String()) @@ -493,7 +493,7 @@ func TestConnPut(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := Dial(l.LocalAddr().String()) @@ -600,7 +600,7 @@ func TestConnDelete(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := Dial(l.LocalAddr().String()) @@ -652,7 +652,7 @@ func TestConnPing(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := Dial(l.LocalAddr().String()) @@ -699,7 +699,7 @@ func TestClientInactiveMonitor(t *testing.T) { go func() { defer serverWg.Done() errS := sd.Serve(ld) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := Dial( @@ -763,7 +763,7 @@ func TestClientKeepAliveMonitor(t *testing.T) { return } } - require.NoError(t, errR) + assert.NoError(t, errR) } }() diff --git a/udp/server_test.go b/udp/server_test.go index 5c2f3814..0a2a1fed 100644 --- a/udp/server_test.go +++ b/udp/server_test.go @@ -22,6 +22,7 @@ import ( "github.com/plgd-dev/go-coap/v3/udp" "github.com/plgd-dev/go-coap/v3/udp/client" "github.com/plgd-dev/go-coap/v3/udp/server" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/atomic" "golang.org/x/sync/semaphore" @@ -70,7 +71,7 @@ func TestServerDiscoverIotivity(t *testing.T) { go func() { defer wg.Done() errS := sd.Serve(ld) - require.NoError(t, errS) + assert.NoError(t, errS) }() ctx, cancel := context.WithTimeout(context.Background(), timeout) @@ -169,7 +170,7 @@ func TestServerDiscover(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() ld, err := coapNet.NewListenUDP("udp4", "") @@ -186,7 +187,7 @@ func TestServerDiscover(t *testing.T) { go func() { defer wg.Done() errS := sd.Serve(ld) - require.NoError(t, errS) + assert.NoError(t, errS) }() for _, tt := range tests { @@ -233,7 +234,7 @@ func TestServerCleanUpConns(t *testing.T) { go func() { defer wg.Done() errS := sd.Serve(ld) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := udp.Dial(ld.LocalAddr().String()) @@ -294,7 +295,7 @@ func TestServerInactiveMonitor(t *testing.T) { go func() { defer serverWg.Done() errS := sd.Serve(ld) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := udp.Dial( @@ -366,7 +367,7 @@ func TestServerKeepAliveMonitor(t *testing.T) { go func() { defer serverWg.Done() errS := sd.Serve(ld) - require.NoError(t, errS) + assert.NoError(t, errS) }() cc, err := udp.Dial( @@ -402,7 +403,7 @@ func TestServerNewClient(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() return s, func() { s.Stop() @@ -479,7 +480,7 @@ func TestCheckForLossOrder(t *testing.T) { go func() { defer wg.Done() errS := sd.Serve(ld) - require.NoError(t, errS) + assert.NoError(t, errS) }() defer func() { sd.Stop() @@ -534,7 +535,7 @@ func TestServerReconnectNewClient(t *testing.T) { go func() { defer wg.Done() errS := s.Serve(l) - require.NoError(t, errS) + assert.NoError(t, errS) }() return s, func() { s.Stop() @@ -621,7 +622,7 @@ func TestMuxPath(t *testing.T) { s := udp.NewServer(options.WithMux(r)) go func() { errL := s.Serve(l) - require.NoError(t, errL) + assert.NoError(t, errL) }() type args struct { From fa142666f9bdab02295f1b7aa216930497f7fd92 Mon Sep 17 00:00:00 2001 From: Daniel Adam Date: Thu, 4 Apr 2024 12:29:48 +0200 Subject: [PATCH 2/2] Update module golang.org/x/net to v0.23.0 --- go.mod | 2 +- go.sum | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index b62a51f1..5dfda01a 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/stretchr/testify v1.9.0 go.uber.org/atomic v1.11.0 golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 - golang.org/x/net v0.22.0 + golang.org/x/net v0.23.0 golang.org/x/sync v0.6.0 ) diff --git a/go.sum b/go.sum index 8f2f329c..4e82725a 100644 --- a/go.sum +++ b/go.sum @@ -43,8 +43,9 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= -golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= +golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=