New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to write request test ? #55
Comments
Please check some of the unit tests at #37. Is this what you were looking for? |
Thanks for point out the #37. in main.go func GetMainEngine() *gin.Engine {
r := gin.Default()
v1 := r.Group("/v1")
{
v1.POST("/login", model.Login)
v1.POST("/logou", model.Logout)
v1.POST("/signup", model.Signup)
}
return r
}
func main() {
GetMainEngine().Run(":8080")
} in the main_test.go func TestUserRegAndLogin(t *testing.T) {
setupDB()
defer clearDB()
ts := httptest.NewServer(GetMainEngine())
... Other will be same. And Close the issue. |
@kzjeef can you expand the "... Other will be same." part to have a complete answer? |
@ernsheong you saved me |
@ernsheong I,m new and first use issues.How to write test? I want to test 'Get'.This is a traditional MVC.I just copied controller. import ( func main() {
}` `package router import ( func NewRouter() *gin.Engine { `package controller import ( type BaseController struct { } type SkelController struct { func NewSkelController() *SkelController { func (ts *SkelController)newService() *service.SkelService { func (ts *SkelController) Get(ctx *gin.Context) {
} func (ts *BaseController) ReplyOk(ctx *gin.Context, data interface{}) { func (ts *BaseController) ReplyFail(ctx *gin.Context, err interface{}) { type ByIdReq struct { type ByFieldReq struct { |
Use std and http handler can write following test case, but how to do similar thing in gin ?
I think the main point should be
how to create a request and response and fill it into gin's Context structure
...The text was updated successfully, but these errors were encountered: