joao-r-reis commented on code in PR #1920:
URL: 
https://github.com/apache/cassandra-gocql-driver/pull/1920#discussion_r2572284642


##########
protocol_negotiation_test.go:
##########
@@ -0,0 +1,179 @@
+//go:build all || unit
+// +build all unit
+
+package gocql
+
+import (
+       "context"
+       "encoding/binary"
+       "fmt"
+       "slices"
+       "testing"
+       "time"
+
+       "github.com/stretchr/testify/require"
+)
+
+type requestHandlerForProtocolNegotiationTest struct {
+       supportedProtocolVersions []protoVersion
+       supportedBetaProtocols    []protoVersion
+}
+
+func (r *requestHandlerForProtocolNegotiationTest) 
supportsBetaProtocol(version protoVersion) bool {
+       return slices.Contains(r.supportedBetaProtocols, version)
+}
+
+func (r *requestHandlerForProtocolNegotiationTest) supportsProtocol(version 
protoVersion) bool {
+       return slices.Contains(r.supportedProtocolVersions, version)
+}
+
+func (r *requestHandlerForProtocolNegotiationTest) hasBetaFlag(header 
*frameHeader) bool {
+       return header.flags&flagBetaProtocol == flagBetaProtocol
+}
+
+func (r *requestHandlerForProtocolNegotiationTest) 
createBetaFlagUnsetProtocolErrorMessage(version protoVersion) string {
+       return fmt.Sprintf("Beta version of the protocol used (%d/v%d-beta), 
but USE_BETA flag is unset", version, version)
+}
+
+func (r *requestHandlerForProtocolNegotiationTest) handle(_ *TestServer, 
reqFrame, respFrame *framer) error {
+       // If a client uses beta protocol, but the USE_BETA flag is not set, we 
respond with an error
+       if r.supportsBetaProtocol(reqFrame.header.version) && 
!r.hasBetaFlag(reqFrame.header) {
+               respFrame.writeHeader(0, opError, reqFrame.header.stream)
+               respFrame.writeInt(ErrCodeProtocol)
+               
respFrame.writeString(r.createBetaFlagUnsetProtocolErrorMessage(reqFrame.header.version))
+               return nil
+       }
+
+       // if a client uses an unsupported protocol version, we respond with an 
error
+       if !r.supportsProtocol(reqFrame.header.version) {
+               respFrame.writeHeader(0, opError, reqFrame.header.stream)

Review Comment:
   Oh I'm sorry I thought it was replying with stream id 0, in that case then 
can you add a test case where the response stream id is 0 and the request 
stream id is not 0?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to