Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions clusterloader2/pkg/measurement/util/histogram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,24 @@ func TestHistogramQuantile(t *testing.T) {
}
}
}

func TestConvertSampleToHistogram(t *testing.T) {
sample := &model.Sample{
Metric: model.Metric{
"name": "test_metric",
model.BucketLabel: "1.0",
},
Value: 5,
}
Comment on lines +155 to +161

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to cover the ConvertSampleToHistogram function with UTs, let's use the table driven tests like other tests from this file. Additionally we should add a test case for multi-bucket sample set

hist := NewHistogram(nil)
ConvertSampleToHistogram(sample, hist)

expectedLabels := map[string]string{"name": "test_metric"}
if !reflect.DeepEqual(hist.Labels, expectedLabels) {
t.Errorf("expected labels %v, got %v", expectedLabels, hist.Labels)
}

if hist.Buckets["1.0"] != 5 {
t.Errorf("expected bucket 1.0 to have value 5, got %d", hist.Buckets["1.0"])
}
}