9
9
"testing"
10
10
"time"
11
11
12
+ "github.com/google/go-cmp/cmp"
12
13
"github.com/google/uuid"
13
14
"github.com/prometheus/client_golang/prometheus"
14
15
io_prometheus_client"github.com/prometheus/client_model/go"
@@ -110,7 +111,7 @@ func TestCollectInsights(t *testing.T) {
110
111
UserID :user .UserID ,
111
112
WorkspaceID :workspace .ID ,
112
113
AgentID :resources [0 ].Agents [0 ].ID ,
113
- AccessMethod :"terminal " ,
114
+ AccessMethod :"path " ,
114
115
SlugOrPort :"golden-slug" ,
115
116
SessionID :uuid .New (),
116
117
SessionStartedAt :time .Now ().Add (- 3 * time .Minute ),
@@ -163,13 +164,16 @@ func TestCollectInsights(t *testing.T) {
163
164
require .NoError (t ,err )
164
165
165
166
collected := map [string ]int {}
166
- assert .Eventuallyf (t ,func ()bool {
167
+ ok := assert .Eventuallyf (t ,func ()bool {
167
168
// When
168
169
metrics ,err := registry .Gather ()
169
- require .NoError (t ,err )
170
+ if ! assert .NoError (t ,err ) {
171
+ return false
172
+ }
170
173
171
174
// Then
172
175
for _ ,metric := range metrics {
176
+ t .Logf ("metric: %s: %#v" ,metric .GetName (),metric )
173
177
switch metric .GetName () {
174
178
case "coderd_insights_applications_usage_seconds" ,"coderd_insights_templates_active_users" ,"coderd_insights_parameters" :
175
179
for _ ,m := range metric .Metric {
@@ -180,12 +184,16 @@ func TestCollectInsights(t *testing.T) {
180
184
collected [key ]= int (m .Gauge .GetValue ())
181
185
}
182
186
default :
183
- require . FailNowf (t ,"unexpected metric collected" ,"metric: %s" ,metric .GetName ())
187
+ assert . Failf (t ,"unexpected metric collected" ,"metric: %s" ,metric .GetName ())
184
188
}
185
189
}
186
190
187
191
return insightsMetricsAreEqual (golden ,collected )
188
- },testutil .WaitMedium ,testutil .IntervalFast ,"template insights are inconsistent with golden files, got: %v" ,collected )
192
+ },testutil .WaitMedium ,testutil .IntervalFast ,"template insights are inconsistent with golden files" )
193
+ if ! ok {
194
+ diff := cmp .Diff (golden ,collected )
195
+ assert .Empty (t ,diff ,"template insights are inconsistent with golden files (-golden +collected)" )
196
+ }
189
197
}
190
198
191
199
func metricLabelAsString (m * io_prometheus_client.Metric )string {