Skip to content

Commit

Permalink
test: add unit test for AWS Cloudwatch scaler with multiple dimensions
Browse files Browse the repository at this point in the history
Signed-off-by: Zbynek Roubalik <[email protected]>
  • Loading branch information
zroubalik committed Nov 6, 2024
1 parent ca9d48d commit 4df176b
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions pkg/scalers/aws_cloudwatch_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,38 @@ func TestCloudwatchParseMetadata(t *testing.T) {
}
}

func TestAWSCloudwatchScalerMultipleDimensions(t *testing.T) {
meta := map[string]string{
"namespace": "AWS/SQS",
"dimensionName": "QueueName;Region",
"dimensionValue": "queue1;us-west-2",
"metricName": "ApproximateNumberOfMessagesVisible",
"targetMetricValue": "5",
"minMetricValue": "1",
"metricStat": "Average",
"awsRegion": "us-west-2",
}

config := &scalersconfig.ScalerConfig{
TriggerMetadata: meta,
ResolvedEnv: testAWSCloudwatchResolvedEnv,
AuthParams: testAWSAuthentication,
}

awsMeta, err := parseAwsCloudwatchMetadata(config)
if err != nil {
t.Fatalf("Expected no error, got %v", err)
}

if assert.Equal(t, 2, len(awsMeta.DimensionName), "Expected two dimension names") &&
assert.Equal(t, 2, len(awsMeta.DimensionValue), "Expected two dimension values") {
assert.Equal(t, "QueueName", awsMeta.DimensionName[0], "First dimension name should be QueueName")
assert.Equal(t, "Region", awsMeta.DimensionName[1], "Second dimension name should be Region")
assert.Equal(t, "queue1", awsMeta.DimensionValue[0], "First dimension value should be queue1")
assert.Equal(t, "us-west-2", awsMeta.DimensionValue[1], "Second dimension value should be us-west-2")
}
}

func TestAWSCloudwatchGetMetricSpecForScaling(t *testing.T) {
for _, testData := range awsCloudwatchMetricIdentifiers {
ctx := context.Background()
Expand Down

0 comments on commit 4df176b

Please sign in to comment.