Я бы предположил, что app.Run
блокирует, поскольку http.ListenAndServe
делает, и в этом случае вам, вероятно, нужно сделать:
var _ = BeforeSuite(func() {
app = &app.Application{}
go func() {
app.Run(":8080") // runs http.ListenAndServe on given address
}()
})
Как правило, вы бы не слушали порт для ваших юнит-тестов, вместо этого вы должны сделать что-то вроде этого:
var _ = Describe("Example", func() {
Context("When calling '/example' endpoint...", func() {
req, err := http.NewRequest("GET", "http://localhost:8080/example", nil)
// We create a ResponseRecorder (which satisfies http.ResponseWriter) to record the response.
rr := httptest.NewRecorder()
handler := http.HandlerFunc(app.ExampleHandler)
// Our handlers satisfy http.Handler, so we can call their ServeHTTP method
// directly and pass in our Request and ResponseRecorder.
handler.ServeHTTP(rr, req)
It("Should get response 200 OK", func() {
Expect(rr.Result().Status).To(Equal("200 OK"))
})
})