@@ -85,7 +85,7 @@ func TestTelemetry(t *testing.T) {
85
85
assert .NoError (t , err )
86
86
_ , _ = dbgen .WorkspaceProxy (t , db , database.WorkspaceProxy {})
87
87
88
- _ , snapshot := collectSnapshot (t , db )
88
+ _ , snapshot := collectSnapshot (t , db , nil )
89
89
require .Len (t , snapshot .ProvisionerJobs , 1 )
90
90
require .Len (t , snapshot .Licenses , 1 )
91
91
require .Len (t , snapshot .Templates , 1 )
@@ -110,21 +110,32 @@ func TestTelemetry(t *testing.T) {
110
110
_ = dbgen .User (t , db , database.User {
111
111
112
112
})
113
- _ , snapshot := collectSnapshot (t , db )
113
+ _ , snapshot := collectSnapshot (t , db , nil )
114
114
require .Len (t , snapshot .Users , 1 )
115
115
require .Equal (t , snapshot .Users [0 ].EmailHashed , "bb44bf07cf9a2db0554bba63a03d822c927deae77df101874496df5a6a3e896d@coder.com" )
116
116
})
117
+ t .Run ("Experiments" , func (t * testing.T ) {
118
+ t .Parallel ()
119
+
120
+ const expName = "my-experiment"
121
+ exps := []string {expName }
122
+ _ , snapshot := collectSnapshot (t , dbmem .New (), func (opts telemetry.Options ) telemetry.Options {
123
+ opts .Experiments = exps
124
+ return opts
125
+ })
126
+ require .Equal (t , []telemetry.Experiment {{Name : expName }}, snapshot .Experiments )
127
+ })
117
128
}
118
129
119
130
// nolint:paralleltest
120
131
func TestTelemetryInstallSource (t * testing.T ) {
121
132
t .Setenv ("CODER_TELEMETRY_INSTALL_SOURCE" , "aws_marketplace" )
122
133
db := dbmem .New ()
123
- deployment , _ := collectSnapshot (t , db )
134
+ deployment , _ := collectSnapshot (t , db , nil )
124
135
require .Equal (t , "aws_marketplace" , deployment .InstallSource )
125
136
}
126
137
127
- func collectSnapshot (t * testing.T , db database.Store ) (* telemetry.Deployment , * telemetry.Snapshot ) {
138
+ func collectSnapshot (t * testing.T , db database.Store , addOptionsFn func ( opts telemetry. Options ) telemetry. Options ) (* telemetry.Deployment , * telemetry.Snapshot ) {
128
139
t .Helper ()
129
140
deployment := make (chan * telemetry.Deployment , 64 )
130
141
snapshot := make (chan * telemetry.Snapshot , 64 )
@@ -149,12 +160,17 @@ func collectSnapshot(t *testing.T, db database.Store) (*telemetry.Deployment, *t
149
160
t .Cleanup (server .Close )
150
161
serverURL , err := url .Parse (server .URL )
151
162
require .NoError (t , err )
152
- reporter , err := telemetry . New ( telemetry.Options {
163
+ options := telemetry.Options {
153
164
Database : db ,
154
165
Logger : slogtest .Make (t , nil ).Leveled (slog .LevelDebug ),
155
166
URL : serverURL ,
156
167
DeploymentID : uuid .NewString (),
157
- })
168
+ }
169
+ if addOptionsFn != nil {
170
+ options = addOptionsFn (options )
171
+ }
172
+
173
+ reporter , err := telemetry .New (options )
158
174
require .NoError (t , err )
159
175
t .Cleanup (reporter .Close )
160
176
return <- deployment , <- snapshot
0 commit comments