mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-18 23:12:17 +08:00
Update gin_integration_test.go
TestUnixSocket fails if you run it twice in a row. This is due to the unix socket file persisting. Added defer to clean up. Whats unclear is the following test TestBadUnixSocket I suspect is just looking for cruft maybe from a prior test or defaults not working, I have not enough background to say.
This commit is contained in:
parent
be4ba7d9df
commit
bcb29d74c1
@ -144,27 +144,31 @@ func TestRunWithPort(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestUnixSocket(t *testing.T) {
|
func TestUnixSocket(t *testing.T) {
|
||||||
router := New()
|
router := New()
|
||||||
|
|
||||||
go func() {
|
unixTestSocket := "/tmp/unix_unit_test"
|
||||||
router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
|
|
||||||
assert.NoError(t, router.RunUnix("/tmp/unix_unit_test"))
|
|
||||||
}()
|
|
||||||
// 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", "/tmp/unix_unit_test")
|
defer os.Remove(unixTestSocket)
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
fmt.Fprint(c, "GET /example HTTP/1.0\r\n\r\n")
|
go func() {
|
||||||
scanner := bufio.NewScanner(c)
|
router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
|
||||||
var response string
|
assert.NoError(t, router.RunUnix(unixTestSocket))
|
||||||
for scanner.Scan() {
|
}()
|
||||||
response += scanner.Text()
|
// have to wait for the goroutine to start and run the server
|
||||||
}
|
// otherwise the main thread will complete
|
||||||
assert.Contains(t, response, "HTTP/1.0 200", "should get a 200")
|
time.Sleep(5 * time.Millisecond)
|
||||||
assert.Contains(t, response, "it worked", "resp body should match")
|
|
||||||
|
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")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBadUnixSocket(t *testing.T) {
|
func TestBadUnixSocket(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user