(t *testing.T)
| 16 | import "testing" |
| 17 | |
| 18 | func TestCollectorFunc(t *testing.T) { |
| 19 | testDesc := NewDesc( |
| 20 | "test_metric", |
| 21 | "A test metric", |
| 22 | nil, nil, |
| 23 | ) |
| 24 | |
| 25 | cf := CollectorFunc(func(ch chan<- Metric) { |
| 26 | ch <- MustNewConstMetric( |
| 27 | testDesc, |
| 28 | GaugeValue, |
| 29 | 42.0, |
| 30 | ) |
| 31 | }) |
| 32 | |
| 33 | ch := make(chan Metric, 1) |
| 34 | cf.Collect(ch) |
| 35 | close(ch) |
| 36 | |
| 37 | metric := <-ch |
| 38 | if metric == nil { |
| 39 | t.Fatal("Expected metric, got nil") |
| 40 | } |
| 41 | |
| 42 | descCh := make(chan *Desc, 1) |
| 43 | cf.Describe(descCh) |
| 44 | close(descCh) |
| 45 | |
| 46 | desc := <-descCh |
| 47 | if desc == nil { |
| 48 | t.Fatal("Expected desc, got nil") |
| 49 | } |
| 50 | |
| 51 | if desc.String() != testDesc.String() { |
| 52 | t.Fatalf("Expected %s, got %s", testDesc.String(), desc.String()) |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | func TestCollectorFuncWithRegistry(t *testing.T) { |
| 57 | reg := NewPedanticRegistry() |
nothing calls this directly
no test coverage detected