MCPcopy Index your code
hub / github.com/coder/coder / newRestartableTestServer

Function newRestartableTestServer

enterprise/coderd/coderd_test.go:992–1025  ·  view source on GitHub ↗
(t *testing.T, options *coderdenttest.Options)

Source from the content-addressed store, hash-verified

990}
991
992func 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
1027func (s *restartableTestServer) Stop(t *testing.T) {
1028 t.Helper()

Callers 1

Calls 10

startWithFirstUserMethod · 0.95
HelperMethod · 0.65
WriteMethod · 0.65
StartMethod · 0.65
CleanupMethod · 0.65
ParseMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
WriteHeaderMethod · 0.45
ServeHTTPMethod · 0.45

Tested by

no test coverage detected