Skip to content

Commit

Permalink
Add test for Directory Services
Browse files Browse the repository at this point in the history
  • Loading branch information
RuslanMustaev committed Dec 3, 2024
1 parent f835fdd commit f6dd5c7
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions pkg/job/maxdimassociator/associator_ds_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package maxdimassociator

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/config"
"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/logging"
"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/model"
)

var directory = &model.TaggedResource{
ARN: "arn:aws:ds::012345678901:directory/d-abc123",
Namespace: "AWS/DirectoryService",
}

func TestAssociatorDS(t *testing.T) {
type args struct {
dimensionRegexps []model.DimensionsRegexp
resources []*model.TaggedResource
metric *model.Metric
}

type testCase struct {
name string
args args
expectedSkip bool
expectedResource *model.TaggedResource
}

testcases := []testCase{
{
name: "should match Virtual Interface with VirtualInterfaceId dimension",
args: args{
dimensionRegexps: config.SupportedServices.GetService("AWS/DirectoryService").ToModelDimensionsRegexp(),
resources: []*model.TaggedResource{directory},
metric: &model.Metric{
MetricName: "Current Bandwidth",
Namespace: "AWS/DirectoryService",
Dimensions: []model.Dimension{
{Name: "Metric Category", Value: "NTDS"},
{Name: "Domain Controller IP", Value: "123.123.123.123"},
{Name: "Directory ID", Value: "d-abc123"},
},
},
},
expectedSkip: false,
expectedResource: directory,
},
}

for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
associator := NewAssociator(logging.NewNopLogger(), tc.args.dimensionRegexps, tc.args.resources)
res, skip := associator.AssociateMetricToResource(tc.args.metric)
require.Equal(t, tc.expectedSkip, skip)
require.Equal(t, tc.expectedResource, res)
})
}
}

0 comments on commit f6dd5c7

Please sign in to comment.