(t *testing.T)
| 246 | } |
| 247 | |
| 248 | func TestUnixSocket(t *testing.T) { |
| 249 | router := New() |
| 250 | |
| 251 | unixTestSocket := filepath.Join(os.TempDir(), "unix_unit_test") |
| 252 | |
| 253 | defer os.Remove(unixTestSocket) |
| 254 | |
| 255 | go func() { |
| 256 | router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") }) |
| 257 | assert.NoError(t, router.RunUnix(unixTestSocket)) |
| 258 | }() |
| 259 | // have to wait for the goroutine to start and run the server |
| 260 | // otherwise the main thread will complete |
| 261 | time.Sleep(5 * time.Millisecond) |
| 262 | |
| 263 | c, err := net.Dial("unix", unixTestSocket) |
| 264 | require.NoError(t, err) |
| 265 | |
| 266 | fmt.Fprint(c, "GET /example HTTP/1.0\r\n\r\n") |
| 267 | scanner := bufio.NewScanner(c) |
| 268 | var responseBuilder strings.Builder |
| 269 | for scanner.Scan() { |
| 270 | responseBuilder.WriteString(scanner.Text()) |
| 271 | } |
| 272 | response := responseBuilder.String() |
| 273 | assert.Contains(t, response, "HTTP/1.0 200", "should get a 200") |
| 274 | assert.Contains(t, response, "it worked", "resp body should match") |
| 275 | } |
| 276 | |
| 277 | func TestBadUnixSocket(t *testing.T) { |
| 278 | router := New() |
nothing calls this directly
no test coverage detected