Skip to content

Commit

Permalink
PMM-12375 cleanup the inevntory_metrics_test
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Tymchuk committed Sep 26, 2023
1 parent bc1330e commit bc39c6f
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions managed/services/inventory/inventory_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand All @@ -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)
Expand Down Expand Up @@ -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)
})
}

0 comments on commit bc39c6f

Please sign in to comment.