Skip to content

Commit 1987233

Browse files
author
Steven Swartz
committed
Add another unit test for NewConstHistogramWithCreatedTimestamp
Signed-off-by: Steven Swartz <[email protected]>
1 parent 0220baf commit 1987233

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

prometheus/histogram_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,3 +1271,28 @@ func TestHistogramVecCreatedTimestampWithDeletes(t *testing.T) {
12711271
now = now.Add(1 * time.Hour)
12721272
expectCTsForMetricVecValues(t, histogramVec.MetricVec, dto.MetricType_HISTOGRAM, expected)
12731273
}
1274+
1275+
func TestNewConstHistogramWithCreatedTimestamp(t *testing.T) {
1276+
metricDesc := NewDesc(
1277+
"sample_value",
1278+
"sample value",
1279+
nil,
1280+
nil,
1281+
)
1282+
buckets := map[float64]uint64{25: 100, 50: 200}
1283+
createdTs := time.Unix(1719670764, 123)
1284+
1285+
h, err := NewConstHistogramWithCreatedTimestamp(metricDesc, 100, 200, buckets, createdTs)
1286+
if err != nil {
1287+
t.Fatal(err)
1288+
}
1289+
1290+
var metric dto.Metric
1291+
if err := h.Write(&metric); err != nil {
1292+
t.Fatal(err)
1293+
}
1294+
1295+
if metric.Histogram.CreatedTimestamp.AsTime().UnixMicro() != createdTs.UnixMicro() {
1296+
t.Errorf("Expected created timestamp %v, got %v", createdTs, &metric.Histogram.CreatedTimestamp)
1297+
}
1298+
}

0 commit comments

Comments
 (0)