Move require.NoError() to t.Cleanup()
This commit is contained in:
parent
b16e84d90a
commit
2014f4623d
@ -43,17 +43,19 @@ func TLSTestServerWithCert(t *testing.T, handler http.HandlerFunc, certificate *
|
|||||||
l, err := net.Listen("tcp", "127.0.0.1:0")
|
l, err := net.Listen("tcp", "127.0.0.1:0")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
serverShutdownChan := make(chan error)
|
||||||
go func() {
|
go func() {
|
||||||
// Empty certFile and keyFile will use certs from Server.TLSConfig.
|
// Empty certFile and keyFile will use certs from Server.TLSConfig.
|
||||||
serveErr := server.ServeTLS(l, "", "")
|
serverShutdownChan <- 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)
|
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
_ = server.Close()
|
_ = 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()
|
return l.Addr().String()
|
||||||
|
Loading…
Reference in New Issue
Block a user