diff --git a/gin_integration_test.go b/gin_integration_test.go index 72bcec7e..baad1fca 100644 --- a/gin_integration_test.go +++ b/gin_integration_test.go @@ -144,31 +144,31 @@ func TestRunWithPort(t *testing.T) { } func TestUnixSocket(t *testing.T) { - router := New() + router := New() - unixTestSocket := "/tmp/unix_unit_test" + unixTestSocket := "/tmp/unix_unit_test" - defer os.Remove(unixTestSocket) + defer os.Remove(unixTestSocket) - go func() { - router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") }) - assert.NoError(t, router.RunUnix(unixTestSocket)) - }() - // have to wait for the goroutine to start and run the server - // otherwise the main thread will complete - time.Sleep(5 * time.Millisecond) + go func() { + router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") }) + assert.NoError(t, router.RunUnix(unixTestSocket)) + }() + // have to wait for the goroutine to start and run the server + // otherwise the main thread will complete + time.Sleep(5 * time.Millisecond) - c, err := net.Dial("unix", unixTestSocket) - assert.NoError(t, err) + c, err := net.Dial("unix", unixTestSocket) + assert.NoError(t, err) - fmt.Fprint(c, "GET /example HTTP/1.0\r\n\r\n") - scanner := bufio.NewScanner(c) - var response string - for scanner.Scan() { - response += scanner.Text() - } - assert.Contains(t, response, "HTTP/1.0 200", "should get a 200") - assert.Contains(t, response, "it worked", "resp body should match") + fmt.Fprint(c, "GET /example HTTP/1.0\r\n\r\n") + scanner := bufio.NewScanner(c) + var response string + for scanner.Scan() { + response += scanner.Text() + } + assert.Contains(t, response, "HTTP/1.0 200", "should get a 200") + assert.Contains(t, response, "it worked", "resp body should match") } func TestBadUnixSocket(t *testing.T) {