github.com/streamdal/segmentio-kafka-go@v0.4.47-streamdal/saslhandshake_test.go (about) 1 package kafka 2 3 import ( 4 "bufio" 5 "bytes" 6 "reflect" 7 "testing" 8 ) 9 10 func TestSASLHandshakeRequestV0(t *testing.T) { 11 item := saslHandshakeRequestV0{ 12 Mechanism: "SCRAM-SHA-512", 13 } 14 15 b := bytes.NewBuffer(nil) 16 w := &writeBuffer{w: b} 17 item.writeTo(w) 18 19 var found saslHandshakeRequestV0 20 remain, err := (&found).readFrom(bufio.NewReader(b), b.Len()) 21 if err != nil { 22 t.Error(err) 23 t.FailNow() 24 } 25 if remain != 0 { 26 t.Errorf("expected 0 remain, got %v", remain) 27 t.FailNow() 28 } 29 if !reflect.DeepEqual(item, found) { 30 t.Error("expected item and found to be the same") 31 t.FailNow() 32 } 33 } 34 35 func TestSASLHandshakeResponseV0(t *testing.T) { 36 item := saslHandshakeResponseV0{ 37 ErrorCode: 2, 38 EnabledMechanisms: []string{"PLAIN", "SCRAM-SHA-512"}, 39 } 40 41 b := bytes.NewBuffer(nil) 42 w := &writeBuffer{w: b} 43 item.writeTo(w) 44 45 var found saslHandshakeResponseV0 46 remain, err := (&found).readFrom(bufio.NewReader(b), b.Len()) 47 if err != nil { 48 t.Error(err) 49 t.FailNow() 50 } 51 if remain != 0 { 52 t.Errorf("expected 0 remain, got %v", remain) 53 t.FailNow() 54 } 55 if !reflect.DeepEqual(item, found) { 56 t.Error("expected item and found to be the same") 57 t.FailNow() 58 } 59 }