Files
LearnGO/go/pkg/mod/github.com/jackc/pgproto3/v2@v2.3.3/query_test.go
T
2024-09-19 21:38:24 -04:00

21 lines
541 B
Go

package pgproto3_test
import (
"testing"
"github.com/jackc/pgproto3/v2"
"github.com/stretchr/testify/require"
)
func TestQueryBiggerThanMaxMessageBodyLen(t *testing.T) {
t.Parallel()
// Maximum allowed size. 4 bytes for size and 1 byte for 0 terminated string.
_, err := (&pgproto3.Query{String: string(make([]byte, pgproto3.MaxMessageBodyLen-5))}).Encode(nil)
require.NoError(t, err)
// 1 byte too big
_, err = (&pgproto3.Query{String: string(make([]byte, pgproto3.MaxMessageBodyLen-4))}).Encode(nil)
require.Error(t, err)
}