These are chat archives for gin-gonic/gin

3rd
Mar 2015
Pavel Pavlenko
@pavlik
Mar 03 2015 11:22

Hello everyone! I need help. How to write tests (with default go test package) for testing web api written with Gin. I googled examples, but didn’t find anything.
In other web api test examples I see that first step is

server = httptest.NewServer(whatToPassHere???)

my test file: https://github.com/kodi0/goblog/blob/pavlik/server/app_test.go

P.S. I’m go_newbie & doing first steps.

Pavel Pavlenko
@pavlik
Mar 03 2015 11:32
Thanks @msoedov. One more question: what doing func New() in 315 string of this example?
Alex Miasoiedov
@msoedov
Mar 03 2015 11:34
it creating new gin instance, in another words it the same as gin.Default() in your app.go code
Pavel Pavlenko
@pavlik
Mar 03 2015 11:37
Can you explain why we can create gin.Default() instance with only New()?
Alex Miasoiedov
@msoedov
Mar 03 2015 11:45
I would recommend you to create func App() *gin.Engine where you will set up Routes, Db session etc..
and then you will able to call this function inside main() and in your unittests
Pavel Pavlenko
@pavlik
Mar 03 2015 11:53
Thanks for idea!
Alex Miasoiedov
@msoedov
Mar 03 2015 11:55
your welcome