(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func TestCollector_Add(t *testing.T) { |
| 17 | t.Parallel() |
| 18 | |
| 19 | // given |
| 20 | agentsGauge := prometheusmetrics.NewCachedGaugeVec(prometheus.NewGaugeVec(prometheus.GaugeOpts{ |
| 21 | Namespace: "coderd", |
| 22 | Subsystem: "agents", |
| 23 | Name: "up", |
| 24 | Help: "The number of active agents per workspace.", |
| 25 | }, []string{"username", "workspace_name"})) |
| 26 | |
| 27 | // when |
| 28 | agentsGauge.WithLabelValues(prometheusmetrics.VectorOperationAdd, 7, "first user", "my workspace") |
| 29 | agentsGauge.WithLabelValues(prometheusmetrics.VectorOperationAdd, 23, "second user", "your workspace") |
| 30 | agentsGauge.WithLabelValues(prometheusmetrics.VectorOperationAdd, 1, "first user", "my workspace") |
| 31 | agentsGauge.WithLabelValues(prometheusmetrics.VectorOperationAdd, 25, "second user", "your workspace") |
| 32 | agentsGauge.Commit() |
| 33 | |
| 34 | // then |
| 35 | ch := make(chan prometheus.Metric, 2) |
| 36 | agentsGauge.Collect(ch) |
| 37 | |
| 38 | metrics := collectAndSortMetrics(t, agentsGauge, 2) |
| 39 | |
| 40 | assert.Equal(t, "first user", metrics[0].Label[0].GetValue()) // Username |
| 41 | assert.Equal(t, "my workspace", metrics[0].Label[1].GetValue()) // Workspace name |
| 42 | assert.Equal(t, 8, int(metrics[0].Gauge.GetValue())) // Metric value |
| 43 | |
| 44 | assert.Equal(t, "second user", metrics[1].Label[0].GetValue()) // Username |
| 45 | assert.Equal(t, "your workspace", metrics[1].Label[1].GetValue()) // Workspace name |
| 46 | assert.Equal(t, 48, int(metrics[1].Gauge.GetValue())) // Metric value |
| 47 | } |
| 48 | |
| 49 | func TestCollector_Set(t *testing.T) { |
| 50 | t.Parallel() |
nothing calls this directly
no test coverage detected