github.com/QuangHoangHao/kafka-go@v0.4.36/deletetopics_test.go (about) 1 package kafka 2 3 import ( 4 "bufio" 5 "bytes" 6 "context" 7 "reflect" 8 "testing" 9 ) 10 11 func TestClientDeleteTopics(t *testing.T) { 12 client, shutdown := newLocalClient() 13 defer shutdown() 14 15 topic := makeTopic() 16 createTopic(t, topic, 1) 17 18 res, err := client.DeleteTopics(context.Background(), &DeleteTopicsRequest{ 19 Topics: []string{topic}, 20 }) 21 22 if err != nil { 23 t.Fatal(err) 24 } 25 26 if err := res.Errors[topic]; err != nil { 27 t.Error(err) 28 } 29 } 30 31 func TestDeleteTopicsResponseV1(t *testing.T) { 32 item := deleteTopicsResponseV0{ 33 TopicErrorCodes: []deleteTopicsResponseV0TopicErrorCode{ 34 { 35 Topic: "a", 36 ErrorCode: 7, 37 }, 38 }, 39 } 40 41 b := bytes.NewBuffer(nil) 42 w := &writeBuffer{w: b} 43 item.writeTo(w) 44 45 var found deleteTopicsResponseV0 46 remain, err := (&found).readFrom(bufio.NewReader(b), b.Len()) 47 if err != nil { 48 t.Fatal(err) 49 } 50 if remain != 0 { 51 t.Fatalf("expected 0 remain, got %v", remain) 52 } 53 if !reflect.DeepEqual(item, found) { 54 t.Fatal("expected item and found to be the same") 55 } 56 }