gobuffalo / buffalo

Rapid Web Development w/ Go
http://gobuffalo.io
MIT License
8.07k stars 573 forks source link

bug: missing port in address in testing #2391

Closed shambel-amare closed 8 months ago

shambel-amare commented 9 months ago

Description

Description

the issue raises when i am testing endpoints that is in a grouping, working code: app = buffalo.New(buffalo.Options{ Env: ENV, SessionStore: sessions.Null{}, PreWares: []buffalo.PreWare{ cors.Default().Handler, }, SessionName: "_uloapi_session", Logger: dl, }) app.GET("/health", HealthHandler) test code: ` type ActionSuite struct { suite.Action } // health test func Test_ActionSuite(t testing.T) { envy.Load("../.env") envy.Set("GO_ENV", "test") app := App() app.Env = "test" action := suite.NewAction(app) //if err != nil { // t.Fatal(err) //}

as := &ActionSuite{
    Action: action,
}
suite.Run(t, as)

}

func (as *ActionSuite) Test_HealthHandler() { envy.Set("GOENV", "test") tests := []struct { name string body healthResponse }{ { name: "empty", body: healthResponse{}, }, } for , test := range tests { as.Run(test.name, func() {

        res := as.JSON("/health").Get()
        data := healthResponse{}
        res.Bind(&data)

        as.Equal(http.StatusOK, res.Code)
        as.Equal("application/json; charset=utf-8", res.Header().Get("Content-Type"))
        as.Equal("ok", data.API)
        as.Equal(true, data.DB)
        //as.Regexp("v0.0.0", data.Version)
        as.Equal("development", data.Env)
        //as.True(strings.HasPrefix(data.Version, "v0.0.0"))
    })
}

} the above test passes `

Expected Behavior

modified working code(working from postman): app = buffalo.New(buffalo.Options{ Env: ENV, SessionStore: sessions.Null{}, PreWares: []buffalo.PreWare{ cors.Default().Handler, }, SessionName: "_uloapi_session", Logger: dl, }) app.GET("/", HomeHandler) // changes to group api:=app.Group("/v1") api.GET("/health", HealthHandler) test code: ` type ActionSuite struct { suite.Action } // health test func Test_ActionSuite(t testing.T) { envy.Load("../.env") envy.Set("GO_ENV", "test") app := App() app.Env = "test" action := suite.NewAction(app) //if err != nil { // t.Fatal(err) //}

as := &ActionSuite{
    Action: action,
}
suite.Run(t, as)

}

func (as *ActionSuite) Test_HealthHandler() { envy.Set("GOENV", "test") tests := []struct { name string body healthResponse }{ { name: "empty", body: healthResponse{}, }, } for , test := range tests { as.Run(test.name, func() {

        // path of test updated 
        res := as.JSON("/v1/health").Get()
        data := healthResponse{}
        res.Bind(&data)

        as.Equal(http.StatusOK, res.Code)
        as.Equal("application/json; charset=utf-8", res.Header().Get("Content-Type"))
        as.Equal("ok", data.API)
        as.Equal(true, data.DB)
        //as.Regexp("v0.0.0", data.Version)
        as.Equal("development", data.Env)
        //as.True(strings.HasPrefix(data.Version, "v0.0.0"))
    })
}

} the above test is expected to pass

Actual Behavior

error: missing port in address

To Reproduce

No response

Additional Context

Details

``` Paste the output of `buffalo info` here! ```
github-actions[bot] commented 8 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment. Otherwise, this will be closed in 7 days.

github-actions[bot] commented 8 months ago

This issue was closed because it has been stalled for 30+7 days with no activity.