Skip to content

Commit 886f992

Browse files
committed
test(clusterloader2): add unit test for ConvertSampleToHistogram
This PR adds a missing unit test for the ConvertSampleToHistogram function in clusterloader2's measurement utilities, improving overall test coverage.
1 parent 2413e41 commit 886f992

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

clusterloader2/pkg/measurement/util/histogram_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,24 @@ func TestHistogramQuantile(t *testing.T) {
150150
}
151151
}
152152
}
153+
154+
func TestConvertSampleToHistogram(t *testing.T) {
155+
sample := &model.Sample{
156+
Metric: model.Metric{
157+
"name": "test_metric",
158+
model.BucketLabel: "1.0",
159+
},
160+
Value: 5,
161+
}
162+
hist := NewHistogram(nil)
163+
ConvertSampleToHistogram(sample, hist)
164+
165+
expectedLabels := map[string]string{"name": "test_metric"}
166+
if !reflect.DeepEqual(hist.Labels, expectedLabels) {
167+
t.Errorf("expected labels %v, got %v", expectedLabels, hist.Labels)
168+
}
169+
170+
if hist.Buckets["1.0"] != 5 {
171+
t.Errorf("expected bucket 1.0 to have value 5, got %d", hist.Buckets["1.0"])
172+
}
173+
}

0 commit comments

Comments
 (0)