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

Function TestUserTailnetTelemetry

coderd/workspaceagents_test.go:3032–3159  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3030}
3031
3032func TestUserTailnetTelemetry(t *testing.T) {
3033 t.Parallel()
3034
3035 telemetryData := &codersdk.CoderDesktopTelemetry{
3036 DeviceOS: "Windows",
3037 DeviceID: "device001",
3038 CoderDesktopVersion: "0.22.1",
3039 }
3040 fullHeader, err := json.Marshal(telemetryData)
3041 require.NoError(t, err)
3042
3043 testCases := []struct {
3044 name string
3045 headers map[string]string
3046 // only used for DeviceID, DeviceOS, CoderDesktopVersion
3047 expected telemetry.UserTailnetConnection
3048 }{
3049 {
3050 name: "no header",
3051 headers: map[string]string{},
3052 expected: telemetry.UserTailnetConnection{},
3053 },
3054 {
3055 name: "full header",
3056 headers: map[string]string{
3057 codersdk.CoderDesktopTelemetryHeader: string(fullHeader),
3058 },
3059 expected: telemetry.UserTailnetConnection{
3060 DeviceOS: ptr.Ref("Windows"),
3061 DeviceID: ptr.Ref("device001"),
3062 CoderDesktopVersion: ptr.Ref("0.22.1"),
3063 },
3064 },
3065 {
3066 name: "empty header",
3067 headers: map[string]string{
3068 codersdk.CoderDesktopTelemetryHeader: "",
3069 },
3070 expected: telemetry.UserTailnetConnection{},
3071 },
3072 {
3073 name: "invalid header",
3074 headers: map[string]string{
3075 codersdk.CoderDesktopTelemetryHeader: "{\"device_os",
3076 },
3077 expected: telemetry.UserTailnetConnection{},
3078 },
3079 }
3080
3081 // nolint: paralleltest // no longer need to reinitialize loop vars in go 1.22
3082 for _, tc := range testCases {
3083 t.Run(tc.name, func(t *testing.T) {
3084 t.Parallel()
3085
3086 ctx := testutil.Context(t, testutil.WaitLong)
3087 logger := testutil.Logger(t)
3088
3089 fTelemetry := newFakeTelemetryReporter(ctx, t, 200)

Callers

nothing calls this directly

Calls 15

RefFunction · 0.92
ContextFunction · 0.92
LoggerFunction · 0.92
NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
RoleTemplateAdminFunction · 0.92
NowFunction · 0.92
ReadBodyAsErrorFunction · 0.92
TryReceiveFunction · 0.92
newFakeTelemetryReporterFunction · 0.85
requireEqualOrBothNilFunction · 0.85

Tested by

no test coverage detected