(t *testing.T, socketPath string, handlers []handler)
| 112 | } |
| 113 | |
| 114 | func muxServer(t *testing.T, socketPath string, handlers []handler) { |
| 115 | t.Helper() |
| 116 | _ = os.Remove(socketPath) |
| 117 | require.NoError(t, os.MkdirAll(filepath.Dir(socketPath), 0o755)) |
| 118 | listener, err := net.Listen("unix", socketPath) |
| 119 | require.NoError(t, err) |
| 120 | mux := http.NewServeMux() |
| 121 | for _, h := range handlers { |
| 122 | mux.Handle(h.pattern, h.handler) |
| 123 | } |
| 124 | |
| 125 | server := &http.Server{Handler: mux} |
| 126 | |
| 127 | go func() { |
| 128 | _ = server.Serve(listener) |
| 129 | }() |
| 130 | |
| 131 | t.Cleanup(func() { |
| 132 | shutdownCtx, cancel := context.WithTimeout(t.Context(), 5*time.Second) |
| 133 | defer cancel() |
| 134 | |
| 135 | _ = server.Shutdown(shutdownCtx) |
| 136 | _ = listener.Close() |
| 137 | _ = os.RemoveAll(socketPath) |
| 138 | }) |
| 139 | } |
| 140 | |
| 141 | func wrapHandler(pattern string, h http.Handler) handler { |
| 142 | return handler{pattern: pattern, handler: h} |
no test coverage detected