From da5be64c9f1db8b3a3d7ffa9c566cd1ad521f626 Mon Sep 17 00:00:00 2001 From: Kevin Mulvey Date: Fri, 29 May 2015 07:29:33 -0400 Subject: [PATCH] test standard router --- gin_integration_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/gin_integration_test.go b/gin_integration_test.go index 47d1e10..1ec764f 100644 --- a/gin_integration_test.go +++ b/gin_integration_test.go @@ -4,6 +4,7 @@ import ( "bufio" "bytes" "fmt" + "io/ioutil" "net" "net/http" "testing" @@ -12,6 +13,31 @@ import ( "github.com/stretchr/testify/assert" ) +func TestRun(t *testing.T) { + buffer := new(bytes.Buffer) + router := New() + go func() { + router.Use(LoggerWithWriter(buffer)) + router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") }) + router.Run(":5150") + }() + // have to wait for the goroutine to start and run the server + // otherwise the main thread will complete + time.Sleep(5 * time.Millisecond) + + resp, err := http.Get("http://localhost:5150/example") + if err != nil { + t.FailNow() + } + defer resp.Body.Close() + body, ioerr := ioutil.ReadAll(resp.Body) + if ioerr != nil { + t.FailNow() + } + assert.Equal(t, "it worked", body, "resp body should match") + assert.Equal(t, "200 OK", resp.Status, "should get a 200") +} + func TestUnixSocket(t *testing.T) { buffer := new(bytes.Buffer) router := New()