]> Sergey Matveev's repositories - btrtrc.git/blobdiff - peerconn_test.go
Break PeerConn status into more lines and improve pex status
[btrtrc.git] / peerconn_test.go
index 23d32286cd66b82ca86cd3d04b51d6e6f77fca5c..42f8fe273131b29dda29d4d7e666975d2858e023 100644 (file)
@@ -4,12 +4,13 @@ import (
        "encoding/binary"
        "errors"
        "fmt"
-       "golang.org/x/time/rate"
        "io"
        "net"
        "sync"
        "testing"
 
+       "golang.org/x/time/rate"
+
        "github.com/frankban/quicktest"
        qt "github.com/frankban/quicktest"
        "github.com/stretchr/testify/require"
@@ -317,3 +318,15 @@ func TestReceiveLargeRequest(t *testing.T) {
        c.Check(pc.onReadRequest(req, false), qt.IsNil)
        c.Check(pc.messageWriter.writeBuffer.Len(), qt.Equals, 17)
 }
+
+func TestChunkOverflowsPiece(t *testing.T) {
+       c := qt.New(t)
+       check := func(begin, length, limit pp.Integer, expected bool) {
+               c.Check(chunkOverflowsPiece(ChunkSpec{begin, length}, limit), qt.Equals, expected)
+       }
+       check(2, 3, 1, true)
+       check(2, pp.IntegerMax, 1, true)
+       check(2, pp.IntegerMax, 3, true)
+       check(2, pp.IntegerMax, pp.IntegerMax, true)
+       check(2, pp.IntegerMax-2, pp.IntegerMax, false)
+}