(t *testing.T, options *coderdenttest.Options)
| 990 | } |
| 991 | |
| 992 | func newRestartableTestServer(t *testing.T, options *coderdenttest.Options) (*codersdk.Client, codersdk.CreateFirstUserResponse, *restartableTestServer) { |
| 993 | t.Helper() |
| 994 | if options == nil { |
| 995 | options = &coderdenttest.Options{} |
| 996 | } |
| 997 | |
| 998 | s := &restartableTestServer{ |
| 999 | options: options, |
| 1000 | } |
| 1001 | srv := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 1002 | s.mu.Lock() |
| 1003 | api := s.api |
| 1004 | s.mu.Unlock() |
| 1005 | |
| 1006 | if api == nil { |
| 1007 | w.WriteHeader(http.StatusBadGateway) |
| 1008 | _, _ = w.Write([]byte("server is not started")) |
| 1009 | return |
| 1010 | } |
| 1011 | api.AGPL.RootHandler.ServeHTTP(w, r) |
| 1012 | })) |
| 1013 | s.rl = &restartableListener{Listener: srv.Listener} |
| 1014 | srv.Listener = s.rl |
| 1015 | srv.Start() |
| 1016 | t.Cleanup(srv.Close) |
| 1017 | |
| 1018 | u, err := url.Parse(srv.URL) |
| 1019 | require.NoError(t, err, "failed to parse server URL") |
| 1020 | s.options.AccessURL = u |
| 1021 | |
| 1022 | client, firstUser := s.startWithFirstUser(t) |
| 1023 | client.URL = u |
| 1024 | return client, firstUser, s |
| 1025 | } |
| 1026 | |
| 1027 | func (s *restartableTestServer) Stop(t *testing.T) { |
| 1028 | t.Helper() |
no test coverage detected