I have started learning Golang and I created a simple application with Gin and there are two lines (in main function) that I am not able to test for having a 100% of coverage:
func setupRouter() *gin.Engine {
fmt.Println("Starting application...")
router := gin.Default()
router.GET("/permissions", getPermissionsRoute)
router.GET("/permission/:id", getPermissionByIDRoute)
router.POST("/permission", createPermissionRoute)
router.PUT("/permission", updatePermissionRoute)
router.DELETE("/permission/:id", deletePermissionByIDRoute)
return router
}
var callSetupRouter = setupRouter
func main() {
router := callSetupRouter()
router.Run(":9090")
}
Since the return type of setupRouter is a pointer to an Engine struct, I did not find a way to mock the function for returning a pointer to an Engine struct with the method Run mocked. Any ideas? Thanks in advance.