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

Function mockTelemetryServer

cli/server_test.go:2639–2668  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2637}
2638
2639func mockTelemetryServer(t *testing.T) (*url.URL, chan *telemetry.Deployment, chan *telemetry.Snapshot) {
2640 t.Helper()
2641 deployment := make(chan *telemetry.Deployment, 64)
2642 snapshot := make(chan *telemetry.Snapshot, 64)
2643 r := chi.NewRouter()
2644 r.Post("/deployment", func(w http.ResponseWriter, r *http.Request) {
2645 require.Equal(t, buildinfo.Version(), r.Header.Get(telemetry.VersionHeader))
2646 dd := &telemetry.Deployment{}
2647 err := json.NewDecoder(r.Body).Decode(dd)
2648 require.NoError(t, err)
2649 deployment <- dd
2650 // Ensure the header is sent only after deployment is sent
2651 w.WriteHeader(http.StatusAccepted)
2652 })
2653 r.Post("/snapshot", func(w http.ResponseWriter, r *http.Request) {
2654 require.Equal(t, buildinfo.Version(), r.Header.Get(telemetry.VersionHeader))
2655 ss := &telemetry.Snapshot{}
2656 err := json.NewDecoder(r.Body).Decode(ss)
2657 require.NoError(t, err)
2658 snapshot <- ss
2659 // Ensure the header is sent only after snapshot is sent
2660 w.WriteHeader(http.StatusAccepted)
2661 })
2662 server := httptest.NewServer(r)
2663 t.Cleanup(server.Close)
2664 serverURL, err := url.Parse(server.URL)
2665 require.NoError(t, err)
2666
2667 return serverURL, deployment, snapshot
2668}
2669
2670// startIgnoringPostgresQueryCancel starts the Invocation, but excludes PostgreSQL query canceled and context
2671// cancellation errors. This prevents flakes in tests that only assert things that happen before PostgreSQL is fully

Callers 2

TestServerFunction · 0.70

Calls 7

VersionFunction · 0.92
HelperMethod · 0.65
GetMethod · 0.65
CleanupMethod · 0.65
ParseMethod · 0.65
EqualMethod · 0.45
WriteHeaderMethod · 0.45

Tested by

no test coverage detected