| 1 | package metrics |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/czerwonk/bird_exporter/protocol" |
| 7 | "github.com/stretchr/testify/assert" |
| 8 | ) |
| 9 | |
| 10 | func TestLabelNames(t *testing.T) { |
| 11 | s := NewDefaultLabelStrategy(true, `(\w+\s*)=(\s*\w+)`) |
| 12 | labels := s.LabelNames(&protocol.Protocol{ |
| 13 | Name: "test", |
| 14 | Description: " foo = bar x: y", |
| 15 | ImportFilter: "in", |
| 16 | ExportFilter: "out", |
| 17 | IPVersion: "6", |
| 18 | Proto: protocol.BGP, |
| 19 | }) |
| 20 | |
| 21 | expected := []string{"name", "proto", "ip_version", "import_filter", "export_filter", "foo"} |
| 22 | assert.Equal(t, expected, labels) |
| 23 | } |
| 24 | |
| 25 | func TestLabelValues(t *testing.T) { |
| 26 | s := NewDefaultLabelStrategy(true, `(\w+\s*)=(\s*\w+)`) |
| 27 | values := s.LabelValues(&protocol.Protocol{ |
| 28 | Name: "test", |
| 29 | Description: " foo = bar x: y", |
| 30 | ImportFilter: "in", |
| 31 | ExportFilter: "out", |
| 32 | IPVersion: "6", |
| 33 | Proto: protocol.BGP, |
| 34 | }) |
| 35 | |
| 36 | expected := []string{"test", "BGP", "6", "in", "out", "bar"} |
| 37 | assert.Equal(t, expected, values) |
| 38 | } |