11use anyhow:: Context ;
2+ use std:: fmt:: Debug ;
23use testcontainers_modules:: kafka:: apache:: Kafka ;
34use testcontainers_modules:: testcontainers:: core:: ContainerPort ;
45use testcontainers_modules:: testcontainers:: runners:: AsyncRunner ;
@@ -8,6 +9,12 @@ pub struct KafkaContext {
89 kafka_node : ContainerAsync < Kafka > ,
910}
1011
12+ impl Debug for KafkaContext {
13+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
14+ f. debug_struct ( "KafkaContext" ) . finish ( )
15+ }
16+ }
17+
1118impl KafkaContext {
1219 pub async fn new ( ) -> anyhow:: Result < Self > {
1320 let kafka_node = Kafka :: default ( )
@@ -31,3 +38,24 @@ impl KafkaContext {
3138 Ok ( format ! ( "{}:{}" , kafka_host. to_string( ) , kafka_port) )
3239 }
3340}
41+
42+ #[ tokio:: test]
43+ pub async fn test_kafka_context_works ( ) {
44+ let kafka_context_result = KafkaContext :: new ( ) . await ;
45+ let Ok ( kafka_context) = kafka_context_result else {
46+ panic ! (
47+ "Failed to get Kafka context: {}" ,
48+ kafka_context_result. unwrap_err( )
49+ ) ;
50+ } ;
51+
52+ let bootstrap_servers_result = kafka_context. bootstrap_servers ( ) . await ;
53+ let Ok ( bootstrap_servers) = bootstrap_servers_result else {
54+ panic ! (
55+ "Failed to get bootstrap servers: {}" ,
56+ bootstrap_servers_result. unwrap_err( )
57+ ) ;
58+ } ;
59+
60+ assert_ne ! ( bootstrap_servers. len( ) , 0 , "Bootstrap servers empty" ) ;
61+ }
0 commit comments