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

Function Test_wrapTransportWithTelemetryHeader

cli/root_internal_test.go:212–240  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

210}
211
212func Test_wrapTransportWithTelemetryHeader(t *testing.T) {
213 t.Parallel()
214
215 rt := wrapTransportWithTelemetryHeader(roundTripper(func(req *http.Request) (*http.Response, error) {
216 return &http.Response{
217 Body: io.NopCloser(nil),
218 }, nil
219 }), &serpent.Invocation{
220 Command: &serpent.Command{
221 Use: "test",
222 Options: serpent.OptionSet{{
223 Name: "bananas",
224 Description: "hey",
225 }},
226 },
227 })
228 req := httptest.NewRequest(http.MethodGet, "http://example.com", nil)
229 res, err := rt.RoundTrip(req)
230 require.NoError(t, err)
231 defer res.Body.Close()
232 resp := req.Header.Get(codersdk.CLITelemetryHeader)
233 require.NotEmpty(t, resp)
234 data, err := base64.StdEncoding.DecodeString(resp)
235 require.NoError(t, err)
236 var ti telemetry.Invocation
237 err = json.Unmarshal(data, &ti)
238 require.NoError(t, err)
239 require.Equal(t, ti.Command, "test")
240}
241
242//nolint:tparallel,paralleltest // This test modifies environment variables.
243func TestPrintDeprecatedOptions(t *testing.T) {

Callers

nothing calls this directly

Calls 9

NotEmptyMethod · 0.80
DecodeStringMethod · 0.80
roundTripperFuncType · 0.70
CloseMethod · 0.65
GetMethod · 0.65
RoundTripMethod · 0.45
UnmarshalMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected