'Run http.ListenAndServe() On Tests using stretchr/testify suite Stop Test From Proceed
I'm trying to create integration tests for my REST API application which I made using gorilla/mux, gorm.io and golang-migrate/v4
For the tests I'm using testify.
My SetupSuite() in my integration_Test.go is like this:
func (s *ReceiptServiceTestSuite) SetupSuite() {
s.Require().NoError(godotenv.Load("test.env"))
s.Require().NoError(database.Connect())
s.db = database.DB
s.m = database.M
router.HandleRequests()
}
And my router.HandleRequests() is like this:
func HandleRequests() {
router := mux.NewRouter()
router.Use(middleware)
// lots of router.HandleFunc()
http.ListenAndServe(":8080", router)
}
The thing is: if I remove router.HandleRequests() from the SetupSuite(), all my database tests run normally, but if I try to http.ListenAndServe() the test workflow stop and nothing happens.
I believe that I should use goroutines with router.HandleRequests() so it can run parallel with the tests, I just can't figure it out how to do it.
For further information, here is the project repository, and I don't know if it is relevant, but I'm running two postgres instances using docker-compose, one for the project to run and another for the tests.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
