@@ -212,9 +212,28 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom
212212 }
213213
214214 // 8. Wait until Redpanda is ready to serve requests.
215+ waitHTTP := wait .ForHTTP (defaultAdminAPIPort ).
216+ WithStatusCodeMatcher (func (status int ) bool {
217+ return status == http .StatusNotFound
218+ })
219+
220+ var tlsConfig * tls.Config
221+ if settings .EnableTLS {
222+ cert , err := tls .X509KeyPair (settings .cert , settings .key )
223+ if err != nil {
224+ return c , fmt .Errorf ("failed to create admin client with cert: %w" , err )
225+ }
226+ caCertPool := x509 .NewCertPool ()
227+ caCertPool .AppendCertsFromPEM (settings .cert )
228+ tlsConfig = & tls.Config {
229+ Certificates : []tls.Certificate {cert },
230+ RootCAs : caCertPool ,
231+ }
232+ waitHTTP = waitHTTP .WithTLS (true , tlsConfig )
233+ }
215234 err = wait .ForAll (
216235 wait .ForListeningPort (defaultKafkaAPIPort ),
217- wait . ForListeningPort ( defaultAdminAPIPort ) ,
236+ waitHTTP ,
218237 wait .ForListeningPort (defaultSchemaRegistryPort ),
219238 wait .ForLog ("Successfully started Redpanda!" ),
220239 ).WaitUntilReady (ctx , ctr )
@@ -237,21 +256,12 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom
237256 adminAPIUrl := fmt .Sprintf ("%s://%v:%d" , c .urlScheme , hostIP , adminAPIPort .Int ())
238257 adminCl := NewAdminAPIClient (adminAPIUrl )
239258 if settings .EnableTLS {
240- cert , err := tls .X509KeyPair (settings .cert , settings .key )
241- if err != nil {
242- return c , fmt .Errorf ("failed to create admin client with cert: %w" , err )
243- }
244- caCertPool := x509 .NewCertPool ()
245- caCertPool .AppendCertsFromPEM (settings .cert )
246259 adminCl = adminCl .WithHTTPClient (& http.Client {
247260 Timeout : 5 * time .Second ,
248261 Transport : & http.Transport {
249262 ForceAttemptHTTP2 : true ,
250263 TLSHandshakeTimeout : 10 * time .Second ,
251- TLSClientConfig : & tls.Config {
252- Certificates : []tls.Certificate {cert },
253- RootCAs : caCertPool ,
254- },
264+ TLSClientConfig : tlsConfig ,
255265 },
256266 })
257267 }
0 commit comments