Move require.NoError() to t.Cleanup()

This commit is contained in:
Ryan Richard 2021-05-24 14:24:09 -07:00
parent b16e84d90a
commit 2014f4623d

View File

@ -43,17 +43,19 @@ func TLSTestServerWithCert(t *testing.T, handler http.HandlerFunc, certificate *
l, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)
serverShutdownChan := make(chan error)
go func() {
// Empty certFile and keyFile will use certs from Server.TLSConfig.
serveErr := server.ServeTLS(l, "", "")
if !errors.Is(serveErr, http.ErrServerClosed) {
t.Log("Got an unexpected error while starting the fake http server!")
require.NoError(t, serveErr)
}
serverShutdownChan <- server.ServeTLS(l, "", "")
}()
t.Cleanup(func() {
_ = server.Close()
serveErr := <-serverShutdownChan
if !errors.Is(serveErr, http.ErrServerClosed) {
t.Log("Got an unexpected error while starting the fake http server!")
require.NoError(t, serveErr)
}
})
return l.Addr().String()