Skip to content

Commit

Permalink
Add a unit test to check the tags field mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
zmoog committed Aug 28, 2023
1 parent f066926 commit cde009c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion x-pack/metricbeat/module/azure/billing/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func TestEventMapping(t *testing.T) {
name := "test"
billingAccountId := "123"
startDate := time.Time{}
tagName := "team"
tagValue := "obs-cloud-monitoring"

//
// Usage Details
Expand All @@ -49,6 +51,9 @@ func TestEventMapping(t *testing.T) {
ID: &ID,
Kind: &kind,
Properties: &props,
Tags: map[string]*string{
tagName: &tagValue,
},
}

//
Expand Down Expand Up @@ -102,15 +107,23 @@ func TestEventMapping(t *testing.T) {
// Check the results
//
for _, event := range events {
// if is an usage event
if ok, _ := event.MetricSetFields.HasKey("department_name"); ok {
//
// The event is a usage detail
//
val1, _ := event.MetricSetFields.GetValue("account_name")
assert.Equal(t, val1, &name)
val2, _ := event.MetricSetFields.GetValue("product")
assert.Equal(t, val2, &name)
val3, _ := event.MetricSetFields.GetValue("department_name")
assert.Equal(t, val3, &name)
tags, _ := event.ModuleFields.GetValue("resource.tags")
assert.Equal(t, tags, map[string]*string{tagName: &tagValue})

} else {
//
// The event is a forecast
//

// Check the actual cost
isActual, _ := event.MetricSetFields.HasKey("actual_cost")
Expand Down

0 comments on commit cde009c

Please sign in to comment.