github.com/deanMdreon/kafka-go@v0.4.32/protocol/response_test.go (about) 1 package protocol 2 3 import ( 4 "bytes" 5 "errors" 6 "io" 7 "strings" 8 "testing" 9 ) 10 11 func TestReadResponseUnexpectedTLSDetection(t *testing.T) { 12 var buf bytes.Buffer 13 14 buf.Write([]byte{tlsAlertByte, 0x03, 0x03, 10, 0, 0, 0}) 15 16 correlationID, _, err := ReadResponse(&buf, ApiVersions, 0) 17 if !errors.Is(err, io.ErrUnexpectedEOF) { 18 t.Fatalf("expected an io.ErrUnexpectedEOF from ReadResponse got %v", err) 19 } 20 21 if !strings.Contains(err.Error(), "broker appears to be expecting TLS") { 22 t.Fatalf("expected error messae to contain %s got %s", "broker appears to be expecting TLS", err.Error()) 23 } 24 25 if correlationID != 0 { 26 t.Fatalf("expected correlationID of 0 got %d", correlationID) 27 } 28 }