diff --git a/managed/services/inventory/inventory_metrics_test.go b/managed/services/inventory/inventory_metrics_test.go index 939ccc7b07..9c2be89e02 100644 --- a/managed/services/inventory/inventory_metrics_test.go +++ b/managed/services/inventory/inventory_metrics_test.go @@ -33,30 +33,6 @@ import ( ) func TestNewInventoryMetricsCollector(t *testing.T) { - metricsMock := &mockInventoryMetrics{} - inventoryCollector := NewInventoryMetricsCollector(metricsMock) - - agentMetrics := []Metric{ - { - labels: []string{"A1", string(models.PMMAgentType), "S1", "N1", "NN1", "PA1", strconv.Itoa(1), "V1"}, - value: float64(1), - }, - } - - nodeMetrics := []Metric{ - { - labels: []string{"N1", string(models.GenericNodeType), "N1", "C1"}, - value: float64(1), - }, - } - - serviceMetrics := []Metric{ - { - labels: []string{"C1", string(models.ProxySQLServiceType), "N1"}, - value: float64(1), - }, - } - t.Run("Metrics returns inventory metrics", func(t *testing.T) { client := http.Client{} @@ -80,6 +56,34 @@ func TestNewInventoryMetricsCollector(t *testing.T) { }) t.Run("Collector", func(t *testing.T) { + metricsMock := &mockInventoryMetrics{} + metricsMock.Test(t) + + t.Cleanup(func() { metricsMock.AssertExpectations(t) }) + + inventoryCollector := NewInventoryMetricsCollector(metricsMock) + + agentMetrics := []Metric{ + { + labels: []string{"A1", string(models.PMMAgentType), "S1", "N1", "NN1", "PA1", strconv.Itoa(1), "V1"}, + value: float64(1), + }, + } + + nodeMetrics := []Metric{ + { + labels: []string{"N1", string(models.GenericNodeType), "N1", "C1"}, + value: float64(1), + }, + } + + serviceMetrics := []Metric{ + { + labels: []string{"C1", string(models.ProxySQLServiceType), "N1"}, + value: float64(1), + }, + } + metricsMock.On("GetAgentMetrics", mock.Anything).Return(agentMetrics, nil) metricsMock.On("GetNodeMetrics", mock.Anything).Return(nodeMetrics, nil) metricsMock.On("GetServiceMetrics", mock.Anything).Return(serviceMetrics, nil) @@ -122,7 +126,5 @@ func TestNewInventoryMetricsCollector(t *testing.T) { "pmm_managed_inventory_services"); err != nil { t.Errorf("Unexpected collecting result:\n%s", err) } - - metricsMock.AssertExpectations(t) }) }