Skip to content

Commit 0e2fff5

Browse files
committed
Add test
1 parent 551a8fd commit 0e2fff5

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

coderd/telemetry/telemetry_test.go

Lines changed: 16 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,31 @@ 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+
func TestTelemetryInstallSource(t *testing.T) {
150+
t.Setenv("CODER_TELEMETRY_INSTALL_SOURCE", "aws_marketplace")
151+
db := databasefake.New()
152+
deployment, _ := collectSnapshot(t, db)
153+
require.Equal(t, "aws_marketplace", deployment.InstallSource)
154+
}
155+
156+
func collectSnapshot(t *testing.T, db database.Store) (*telemetry.Deployment, *telemetry.Snapshot) {
150157
t.Helper()
151-
deployment := make(chan struct{}, 64)
158+
deployment := make(chan *telemetry.Deployment, 64)
152159
snapshot := make(chan *telemetry.Snapshot, 64)
153160
r := chi.NewRouter()
154161
r.Post("/deployment", func(w http.ResponseWriter, r *http.Request) {
155162
require.Equal(t, buildinfo.Version(), r.Header.Get(telemetry.VersionHeader))
156163
w.WriteHeader(http.StatusAccepted)
157-
deployment <- struct{}{}
164+
dd := &telemetry.Deployment{}
165+
err := json.NewDecoder(r.Body).Decode(dd)
166+
require.NoError(t, err)
167+
deployment <- dd
158168
})
159169
r.Post("/snapshot", func(w http.ResponseWriter, r *http.Request) {
160170
require.Equal(t, buildinfo.Version(), r.Header.Get(telemetry.VersionHeader))
@@ -176,6 +186,5 @@ func collectSnapshot(t *testing.T, db database.Store) *telemetry.Snapshot {
176186
})
177187
require.NoError(t, err)
178188
t.Cleanup(reporter.Close)
179-
<-deployment
180-
return <-snapshot
189+
return <-deployment, <-snapshot
181190
}

0 commit comments

Comments
 (0)