Skip to content

Instantly share code, notes, and snippets.

@steevehook
Created January 2, 2020 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steevehook/d73a6362bd865aece9606ec29b210116 to your computer and use it in GitHub Desktop.
Save steevehook/d73a6362bd865aece9606ec29b210116 to your computer and use it in GitHub Desktop.
func (s *someSuite) newServer(handler http.Handler) (*httptest.Server, func()) {
done := make(chan struct{})
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
s.NotPanics(func() { handler.ServeHTTP(w, r) })
close(done)
}))
closeFunc := func() {
server.Close()
<-done
}
return server, closeFunc
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment