MCPcopy
hub / github.com/jackc/pgx / TestStartupMessage

Function TestStartupMessage

pgproto3/backend_test.go:64–138  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

62}
63
64func TestStartupMessage(t *testing.T) {
65 t.Parallel()
66
67 t.Run("valid StartupMessage 3.0", func(t *testing.T) {
68 want := &pgproto3.StartupMessage{
69 ProtocolVersion: pgproto3.ProtocolVersion30,
70 Parameters: map[string]string{"username": "tester"},
71 }
72 dst, err := want.Encode([]byte{})
73 require.NoError(t, err)
74
75 server := &interruptReader{}
76 server.push(dst)
77
78 backend := pgproto3.NewBackend(server, nil)
79
80 msg, err := backend.ReceiveStartupMessage()
81 require.NoError(t, err)
82 require.Equal(t, want, msg)
83 })
84
85 t.Run("valid StartupMessage 3.2", func(t *testing.T) {
86 want := &pgproto3.StartupMessage{
87 ProtocolVersion: pgproto3.ProtocolVersion32,
88 Parameters: map[string]string{"username": "tester"},
89 }
90 dst, err := want.Encode([]byte{})
91 require.NoError(t, err)
92
93 server := &interruptReader{}
94 server.push(dst)
95
96 backend := pgproto3.NewBackend(server, nil)
97
98 msg, err := backend.ReceiveStartupMessage()
99 require.NoError(t, err)
100 require.Equal(t, want, msg)
101 })
102
103 t.Run("invalid packet length", func(t *testing.T) {
104 wantErr := "invalid length of startup packet"
105 tests := []struct {
106 name string
107 packetLen uint32
108 }{
109 {
110 name: "large packet length",
111 // Since the StartupMessage contains the "Length of message contents
112 // in bytes, including self", the max startup packet length is actually
113 // 10000+4. Therefore, let's go past the limit with 10005
114 packetLen: 10005,
115 },
116 {
117 name: "short packet length",
118 packetLen: 3,
119 },
120 }
121 for _, tt := range tests {

Callers

nothing calls this directly

Calls 7

EncodeMethod · 0.95
pushMethod · 0.95
ReceiveStartupMessageMethod · 0.95
NewBackendFunction · 0.92
AppendUint32Function · 0.92
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected