Skip to content

Commit 928d061

Browse files
committed
Add test
1 parent 551a8fd commit 928d061

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

coderd/telemetry/telemetry_test.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func TestTelemetry(t *testing.T) {
117117
},
118118
})
119119
assert.NoError(t, err)
120-
snapshot := collectSnapshot(t, db)
120+
_, snapshot := collectSnapshot(t, db)
121121
require.Len(t, snapshot.ParameterSchemas, 1)
122122
require.Len(t, snapshot.ProvisionerJobs, 1)
123123
require.Len(t, snapshot.Licenses, 1)
@@ -140,21 +140,32 @@ func TestTelemetry(t *testing.T) {
140140
LoginType: database.LoginTypePassword,
141141
})
142142
require.NoError(t, err)
143-
snapshot := collectSnapshot(t, db)
143+
_, snapshot := collectSnapshot(t, db)
144144
require.Len(t, snapshot.Users, 1)
145145
require.Equal(t, snapshot.Users[0].EmailHashed, "bb44bf07cf9a2db0554bba63a03d822c927deae77df101874496df5a6a3e896d@coder.com")
146146
})
147147
}
148148

149-
func collectSnapshot(t *testing.T, db database.Store) *telemetry.Snapshot {
149+
// nolint:paralleltest
150+
func TestTelemetryInstallSource(t *testing.T) {
151+
t.Setenv("CODER_TELEMETRY_INSTALL_SOURCE", "aws_marketplace")
152+
db := databasefake.New()
153+
deployment, _ := collectSnapshot(t, db)
154+
require.Equal(t, "aws_marketplace", deployment.InstallSource)
155+
}
156+
157+
func collectSnapshot(t *testing.T, db database.Store) (*telemetry.Deployment, *telemetry.Snapshot) {
150158
t.Helper()
151-
deployment := make(chan struct{}, 64)
159+
deployment := make(chan *telemetry.Deployment, 64)
152160
snapshot := make(chan *telemetry.Snapshot, 64)
153161
r := chi.NewRouter()
154162
r.Post("/deployment", func(w http.ResponseWriter, r *http.Request) {
155163
require.Equal(t, buildinfo.Version(), r.Header.Get(telemetry.VersionHeader))
156164
w.WriteHeader(http.StatusAccepted)
157-
deployment <- struct{}{}
165+
dd := &telemetry.Deployment{}
166+
err := json.NewDecoder(r.Body).Decode(dd)
167+
require.NoError(t, err)
168+
deployment <- dd
158169
})
159170
r.Post("/snapshot", func(w http.ResponseWriter, r *http.Request) {
160171
require.Equal(t, buildinfo.Version(), r.Header.Get(telemetry.VersionHeader))
@@ -176,6 +187,5 @@ func collectSnapshot(t *testing.T, db database.Store) *telemetry.Snapshot {
176187
})
177188
require.NoError(t, err)
178189
t.Cleanup(reporter.Close)
179-
<-deployment
180-
return <-snapshot
190+
return <-deployment, <-snapshot
181191
}

0 commit comments

Comments
 (0)