Skip to content

Commit

Permalink
Tidy data tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zmoog committed Apr 29, 2024
1 parent 6ff4d37 commit 2dadc87
Showing 1 changed file with 82 additions and 52 deletions.
134 changes: 82 additions & 52 deletions x-pack/metricbeat/module/azure/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,13 @@ func TestMapToKeyValuePoints(t *testing.T) {
resourceSubId := "test"
timeGrain := "PT1M"

t.Run("test multiple aggregation types", func(t *testing.T) {
t.Run("test single aggregation type (single config)", func(t *testing.T) {

metrics := []Metric{{
Namespace: namespace,
Names: []string{"test"},
Aggregations: "Minimum,Maximum,Average",
Values: []MetricValue{
{name: metricName, min: &minValue, timestamp: timestamp},
{name: metricName, max: &maxValue, timestamp: timestamp},
{name: metricName, avg: &avgValue, timestamp: timestamp},
{name: metricName, total: &totalValue, timestamp: timestamp},
{name: metricName, count: &countValue, timestamp: timestamp},
},
Namespace: namespace,
Names: []string{"test"},
Aggregations: "min",
Values: []MetricValue{{name: metricName, min: &minValue, timestamp: timestamp}},
TimeGrain: timeGrain,
ResourceId: resourceId,
ResourceSubId: resourceSubId,
Expand All @@ -92,52 +87,12 @@ func TestMapToKeyValuePoints(t *testing.T) {
ResourceSubId: resourceSubId,
Dimensions: map[string]interface{}{},
},
{
Key: fmt.Sprintf("%s.%s", metricName, "max"),
Value: &maxValue,
Namespace: namespace,
TimeGrain: timeGrain,
Timestamp: timestamp,
ResourceId: resourceId,
ResourceSubId: resourceSubId,
Dimensions: map[string]interface{}{},
},
{
Key: fmt.Sprintf("%s.%s", metricName, "avg"),
Value: &avgValue,
Namespace: namespace,
TimeGrain: timeGrain,
Timestamp: timestamp,
ResourceId: resourceId,
ResourceSubId: resourceSubId,
Dimensions: map[string]interface{}{},
},
{
Key: fmt.Sprintf("%s.%s", metricName, "total"),
Value: &totalValue,
Namespace: namespace,
TimeGrain: timeGrain,
Timestamp: timestamp,
ResourceId: resourceId,
ResourceSubId: resourceSubId,
Dimensions: map[string]interface{}{},
},
{
Key: fmt.Sprintf("%s.%s", metricName, "count"),
Value: &countValue,
Namespace: namespace,
TimeGrain: timeGrain,
Timestamp: timestamp,
ResourceId: resourceId,
ResourceSubId: resourceSubId,
Dimensions: map[string]interface{}{},
},
}

assert.Equal(t, expected, actual)
})

t.Run("test single aggregation types", func(t *testing.T) {
t.Run("test single aggregation types (multiple configs)", func(t *testing.T) {

metrics := []Metric{{
Namespace: namespace,
Expand Down Expand Up @@ -236,4 +191,79 @@ func TestMapToKeyValuePoints(t *testing.T) {

assert.Equal(t, expected, actual)
})

t.Run("test multiple aggregation types (multiple configs)", func(t *testing.T) {
metrics := []Metric{{
Namespace: namespace,
Names: []string{"test"},
Aggregations: "Minimum,Maximum,Average,Total,Count",
Values: []MetricValue{
{name: metricName, min: &minValue, timestamp: timestamp},
{name: metricName, max: &maxValue, timestamp: timestamp},
{name: metricName, avg: &avgValue, timestamp: timestamp},
{name: metricName, total: &totalValue, timestamp: timestamp},
{name: metricName, count: &countValue, timestamp: timestamp},
},
TimeGrain: timeGrain,
ResourceId: resourceId,
ResourceSubId: resourceSubId,
}}

actual := mapToKeyValuePoints(metrics)

expected := []KeyValuePoint{
{
Key: fmt.Sprintf("%s.%s", metricName, "min"),
Value: &minValue,
Namespace: namespace,
TimeGrain: timeGrain,
Timestamp: timestamp,
ResourceId: resourceId,
ResourceSubId: resourceSubId,
Dimensions: map[string]interface{}{},
},
{
Key: fmt.Sprintf("%s.%s", metricName, "max"),
Value: &maxValue,
Namespace: namespace,
TimeGrain: timeGrain,
Timestamp: timestamp,
ResourceId: resourceId,
ResourceSubId: resourceSubId,
Dimensions: map[string]interface{}{},
},
{
Key: fmt.Sprintf("%s.%s", metricName, "avg"),
Value: &avgValue,
Namespace: namespace,
TimeGrain: timeGrain,
Timestamp: timestamp,
ResourceId: resourceId,
ResourceSubId: resourceSubId,
Dimensions: map[string]interface{}{},
},
{
Key: fmt.Sprintf("%s.%s", metricName, "total"),
Value: &totalValue,
Namespace: namespace,
TimeGrain: timeGrain,
Timestamp: timestamp,
ResourceId: resourceId,
ResourceSubId: resourceSubId,
Dimensions: map[string]interface{}{},
},
{
Key: fmt.Sprintf("%s.%s", metricName, "count"),
Value: &countValue,
Namespace: namespace,
TimeGrain: timeGrain,
Timestamp: timestamp,
ResourceId: resourceId,
ResourceSubId: resourceSubId,
Dimensions: map[string]interface{}{},
},
}

assert.Equal(t, expected, actual)
})
}

0 comments on commit 2dadc87

Please sign in to comment.