Skip to content

Commit b8a969d

Browse files
committed
Fix tests
1 parent 0c6d00e commit b8a969d

File tree

2 files changed

+15
-26
lines changed

2 files changed

+15
-26
lines changed

enterprise/coderd/license/metricscollector_test.go

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@ package license_test
33
import (
44
"encoding/json"
55
"os"
6-
"reflect"
76
"testing"
87

98
"github.com/aws/smithy-go/ptr"
109
"github.com/prometheus/client_golang/prometheus"
11-
"github.com/stretchr/testify/assert"
1210
"github.com/stretchr/testify/require"
1311

1412
"github.com/coder/coder/v2/codersdk"
1513
"github.com/coder/coder/v2/enterprise/coderd/license"
16-
"github.com/coder/coder/v2/testutil"
1714
)
1815

1916
func TestCollectLicenseMetrics(t *testing.T) {
@@ -39,9 +36,7 @@ func TestCollectLicenseMetrics(t *testing.T) {
3936
})
4037

4138
// When
42-
closeFunc, err := sut.Collect(ctx)
43-
require.NoError(t, err)
44-
t.Cleanup(closeFunc)
39+
registry.Register(sut)
4540

4641
// Then
4742
goldenFile, err := os.ReadFile("testdata/license-metrics.json")
@@ -52,26 +47,19 @@ func TestCollectLicenseMetrics(t *testing.T) {
5247

5348
collected := map[string]int{}
5449

55-
assert.Eventually(t, func() bool {
56-
metrics, err := registry.Gather()
57-
assert.NoError(t, err)
58-
59-
if len(metrics) < 1 {
60-
return false
61-
}
50+
metrics, err := registry.Gather()
51+
require.NoError(t, err)
6252

63-
for _, metric := range metrics {
64-
switch metric.GetName() {
65-
case "coderd_license_active_users", "coderd_license_user_limit":
66-
for _, m := range metric.Metric {
67-
collected[m.Label[0].GetName()+"="+m.Label[0].GetValue()+":"+metric.GetName()] = int(m.Gauge.GetValue())
68-
}
69-
default:
70-
require.FailNowf(t, "unexpected metric collected", "metric: %s", metric.GetName())
53+
for _, metric := range metrics {
54+
switch metric.GetName() {
55+
case "coderd_license_active_users", "coderd_license_limit_users", "coderd_license_user_limit_enabled":
56+
for _, m := range metric.Metric {
57+
collected[metric.GetName()] = int(m.Gauge.GetValue())
7158
}
59+
default:
60+
require.FailNowf(t, "unexpected metric collected", "metric: %s", metric.GetName())
7261
}
73-
return reflect.DeepEqual(golden, collected)
74-
}, testutil.WaitShort, testutil.IntervalFast)
62+
}
7563

76-
assert.EqualValues(t, golden, collected)
64+
require.EqualValues(t, golden, collected)
7765
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2-
"entitled=true:coderd_license_active_users": 4,
3-
"entitled=true:coderd_license_user_limit": 7
2+
"coderd_license_active_users": 4,
3+
"coderd_license_limit_users": 7,
4+
"coderd_license_user_limit_enabled": 1
45
}

0 commit comments

Comments
 (0)