@@ -705,6 +705,42 @@ func TestManagerCreateACLs(t *testing.T) {
705705 })
706706}
707707
708+ func TestListTopics (t * testing.T ) {
709+ cluster , commonConfig := newFakeCluster (t )
710+ m , err := NewManager (ManagerConfig {CommonConfig : commonConfig })
711+ require .NoError (t , err )
712+ t .Cleanup (func () { m .Close () })
713+ var metadataRequest * kmsg.MetadataRequest
714+ cluster .ControlKey (kmsg .Metadata .Int16 (), func (req kmsg.Request ) (kmsg.Response , error , bool ) {
715+ metadataRequest = req .(* kmsg.MetadataRequest )
716+ cluster .KeepControl ()
717+ return & kmsg.MetadataResponse {
718+ Version : metadataRequest .Version ,
719+ Brokers : []kmsg.MetadataResponseBroker {},
720+ Topics : []kmsg.MetadataResponseTopic {{
721+ Topic : kmsg .StringPtr ("name_space-topic1" ),
722+ Partitions : []kmsg.MetadataResponseTopicPartition {{Partition : 1 }, {Partition : 2 }},
723+ }, {
724+ Topic : kmsg .StringPtr ("name_space-topic2" ),
725+ Partitions : []kmsg.MetadataResponseTopicPartition {{Partition : 3 }},
726+ ErrorCode : kerr .UnknownTopicOrPartition .Code ,
727+ }, {
728+ Topic : kmsg .StringPtr ("name_space-topic3" ),
729+ Partitions : []kmsg.MetadataResponseTopicPartition {{Partition : 4 }},
730+ }, {
731+ Topic : kmsg .StringPtr ("name_space-mytopic" ),
732+ Partitions : []kmsg.MetadataResponseTopicPartition {{Partition : 1 }},
733+ }, {
734+ Topic : kmsg .StringPtr ("rnd-topic" ),
735+ Partitions : []kmsg.MetadataResponseTopicPartition {{Partition : 4 }},
736+ }},
737+ }, nil , true
738+ })
739+ topics , err := m .ListTopics (context .Background (), "name_space" )
740+ assert .EqualError (t , err , "name_space-topic2 UNKNOWN_TOPIC_OR_PARTITION: This server does not host this topic-partition." )
741+ assert .Equal (t , []string {"name_space-mytopic" , "name_space-topic1" , "name_space-topic3" }, topics )
742+ }
743+
708744func newFakeCluster (t testing.TB ) (* kfake.Cluster , CommonConfig ) {
709745 cluster , err := kfake .NewCluster (
710746 // Just one broker to simplify dealing with sharded requests.
0 commit comments