|
| 1 | +package scrape_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/prometheus/prometheus/model/labels" |
| 7 | + "github.com/stretchr/testify/require" |
| 8 | + |
| 9 | + "github.com/pedro-stanaka/prom-scrape-analyzer/pkg/scrape" |
| 10 | +) |
| 11 | + |
| 12 | +func TestSeriesSet_Cardinality(t *testing.T) { |
| 13 | + seriesSet := scrape.SeriesSet{ |
| 14 | + 1: {Name: "series1"}, |
| 15 | + 2: {Name: "series2"}, |
| 16 | + } |
| 17 | + |
| 18 | + expected := 2 |
| 19 | + require.Equal(t, expected, seriesSet.Cardinality(), "Cardinality() should return the correct number of series") |
| 20 | +} |
| 21 | + |
| 22 | +func TestSeriesSet_MetricTypeString(t *testing.T) { |
| 23 | + seriesSet := scrape.SeriesSet{ |
| 24 | + 1: {Name: "series1", Type: "gauge"}, |
| 25 | + 2: {Name: "series2", Type: "counter"}, |
| 26 | + } |
| 27 | + |
| 28 | + expected := "gauge|counter" |
| 29 | + require.Equal(t, expected, seriesSet.MetricTypeString(), "MetricTypeString() should return the correct metric types") |
| 30 | +} |
| 31 | + |
| 32 | +func TestSeriesSet_CreatedTS(t *testing.T) { |
| 33 | + seriesSet := scrape.SeriesSet{ |
| 34 | + 1: {Name: "series1", CreatedTimestamp: 1620000000}, |
| 35 | + 2: {Name: "series2", CreatedTimestamp: 1620000001}, |
| 36 | + } |
| 37 | + |
| 38 | + expected := int64(1620000000) |
| 39 | + require.Equal(t, expected, seriesSet.CreatedTS(), "CreatedTS() should return the correct created timestamp") |
| 40 | +} |
| 41 | + |
| 42 | +func TestSeriesSet_LabelNames(t *testing.T) { |
| 43 | + seriesSet := scrape.SeriesSet{ |
| 44 | + 1: {Name: "series1", Labels: labels.Labels{{Name: "label1"}, {Name: "label2"}}}, |
| 45 | + 2: {Name: "series2", Labels: labels.Labels{{Name: "label2"}, {Name: "label3"}}}, |
| 46 | + } |
| 47 | + |
| 48 | + expected := "label1|label2|label3" |
| 49 | + require.Equal(t, expected, seriesSet.LabelNames(), "LabelNames() should return the correct label names") |
| 50 | +} |
| 51 | + |
| 52 | +func TestSeriesSet_LabelStats(t *testing.T) { |
| 53 | + seriesSet := scrape.SeriesSet{ |
| 54 | + 1: {Name: "series1", Labels: labels.Labels{{Name: "label1", Value: "foo"}, {Name: "label2", Value: "bar"}}}, |
| 55 | + 2: {Name: "series2", Labels: labels.Labels{{Name: "label2", Value: "baz"}, {Name: "label3", Value: "qux"}}}, |
| 56 | + 3: {Name: "series3", Labels: labels.Labels{{Name: "label2", Value: "baz"}, {Name: "label3", Value: "qua"}}}, |
| 57 | + } |
| 58 | + |
| 59 | + expected := scrape.LabelStatsSlice{ |
| 60 | + {Name: "label1", DistinctValues: 1}, |
| 61 | + {Name: "label2", DistinctValues: 2}, |
| 62 | + {Name: "label3", DistinctValues: 2}, |
| 63 | + } |
| 64 | + got := seriesSet.LabelStats() |
| 65 | + |
| 66 | + require.Len(t, got, len(expected), "LabelStats() should return the correct number of label stats") |
| 67 | + require.EqualValues(t, expected, got, "LabelStats() should return the correct label stats") |
| 68 | +} |
0 commit comments