MCPcopy Create free account
hub / github.com/cli/cli / TestServiceCopiesRecordedEvents

Function TestServiceCopiesRecordedEvents

internal/telemetry/service_test.go:13–35  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestServiceCopiesRecordedEvents(t *testing.T) {
14 t.Cleanup(stubDeviceID("test-device"))
15
16 // Given a recorded event
17 var payload SendTelemetryPayload
18 service := NewService(func(p SendTelemetryPayload) { payload = p })
19 event := ghtelemetry.Event{
20 Type: "command_invocation",
21 Dimensions: ghtelemetry.Dimensions{"command": "gh issue create"},
22 Measures: ghtelemetry.Measures{"count": 1},
23 }
24 service.Record(event)
25
26 // When the original maps are mutated before delivery
27 event.Dimensions["command"] = "changed"
28 event.Measures["count"] = 2
29 service.Finish()
30
31 // Then the recorded values are unchanged
32 require.Len(t, payload.Events, 1)
33 assert.Equal(t, "gh issue create", payload.Events[0].Dimensions["command"])
34 assert.Equal(t, int64(1), payload.Events[0].Measures["count"])
35}
36
37func TestServicePromotesAllEventsBeforeCompletion(t *testing.T) {
38 t.Cleanup(stubDeviceID("test-device"))

Callers

nothing calls this directly

Calls 6

FinishMethod · 0.95
stubDeviceIDFunction · 0.85
NewServiceFunction · 0.85
EqualMethod · 0.80
RecordMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected