github.com/segmentio/kafka-go@v0.4.48-0.20240318174348-3f6244eb34fd/saslauthenticate_test.go (about) 1 package kafka 2 3 import ( 4 "bufio" 5 "bytes" 6 "reflect" 7 "testing" 8 ) 9 10 func TestSASLAuthenticateRequestV0(t *testing.T) { 11 item := saslAuthenticateRequestV0{ 12 Data: []byte("\x00user\x00pass"), 13 } 14 15 b := bytes.NewBuffer(nil) 16 w := &writeBuffer{w: b} 17 item.writeTo(w) 18 19 var found saslAuthenticateRequestV0 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 TestSASLAuthenticateResponseV0(t *testing.T) { 36 item := saslAuthenticateResponseV0{ 37 ErrorCode: 2, 38 ErrorMessage: "Message", 39 Data: []byte("bytes"), 40 } 41 42 b := bytes.NewBuffer(nil) 43 w := &writeBuffer{w: b} 44 item.writeTo(w) 45 46 var found saslAuthenticateResponseV0 47 remain, err := (&found).readFrom(bufio.NewReader(b), b.Len()) 48 if err != nil { 49 t.Error(err) 50 t.FailNow() 51 } 52 if remain != 0 { 53 t.Errorf("expected 0 remain, got %v", remain) 54 t.FailNow() 55 } 56 if !reflect.DeepEqual(item, found) { 57 t.Error("expected item and found to be the same") 58 t.FailNow() 59 } 60 }