diff --git a/metricproviders/datadog/datadogV2_test.go b/metricproviders/datadog/datadogV2_test.go index e89bcb7654..0d73b3f8c8 100644 --- a/metricproviders/datadog/datadogV2_test.go +++ b/metricproviders/datadog/datadogV2_test.go @@ -460,86 +460,3 @@ func TestRunSuiteV2(t *testing.T) { } } - -func TestValidateIncomingProps(t *testing.T) { - tests := []struct { - name string - metric *v1alpha1.DatadogMetric - expectedErrorMessage string - }{ - { - name: "query and queries missing", - metric: &v1alpha1.DatadogMetric{ - ApiVersion: "v1", - Query: "", - Queries: nil, - }, - expectedErrorMessage: "Must have either a query or queries", - }, - { - name: "both query and queries", - metric: &v1alpha1.DatadogMetric{ - ApiVersion: "v1", - Query: "foo", - Queries: map[string]string{"a": "how much wood could a wood chuck chuck"}, - }, - expectedErrorMessage: "Cannot have both a query and queries", - }, - { - name: "queries with v1 api", - metric: &v1alpha1.DatadogMetric{ - ApiVersion: "v1", - Queries: map[string]string{"a": "how much wood could a wood chuck chuck"}, - }, - expectedErrorMessage: "Query is empty. API Version v1 only supports using the query parameter in your Analysis Template.", - }, - { - name: "formula/queries with wrong apiVersion", - metric: &v1alpha1.DatadogMetric{ - ApiVersion: "v1", - Queries: map[string]string{"a": "how much wood could a wood chuck chuck"}, - Formula: "a + b", - }, - expectedErrorMessage: "Query is empty. API Version v1 only supports using the query parameter in your Analysis Template.", - }, - { - name: "formula without queries", - metric: &v1alpha1.DatadogMetric{ - ApiVersion: "v1", - Formula: "foo / bar", - Query: "foo", - }, - expectedErrorMessage: "Formula are only valid when queries are set", - }, - { - name: "valid simple query with v2", - metric: &v1alpha1.DatadogMetric{ - ApiVersion: "v2", - Query: "foo", - }, - expectedErrorMessage: "", - }, - { - name: "valid queries with v2", - metric: &v1alpha1.DatadogMetric{ - ApiVersion: "v2", - Query: "", - Queries: map[string]string{"a": "how much wood could a wood chuck chuck"}, - Formula: "a + b", - }, - expectedErrorMessage: "", - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - err := validateIncomingProps(test.metric) - if test.expectedErrorMessage != "" { - assert.Error(t, err) - assert.Contains(t, err.Error(), test.expectedErrorMessage) - } else { - assert.NoError(t, err) - } - }) - } -} diff --git a/metricproviders/datadog/datadog_test.go b/metricproviders/datadog/datadog_test.go index c0b2b64750..87446aeb29 100644 --- a/metricproviders/datadog/datadog_test.go +++ b/metricproviders/datadog/datadog_test.go @@ -7,6 +7,7 @@ import ( "os" "testing" + "github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1" "github.com/stretchr/testify/assert" apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/client-go/kubernetes/scheme" @@ -53,3 +54,86 @@ func TestDatadogSpecDefaults(t *testing.T) { assert.Equal(t, "\"5m\"", defaultInterval, "Default version should be v1") }) } + +func TestValidateIncomingProps(t *testing.T) { + tests := []struct { + name string + metric *v1alpha1.DatadogMetric + expectedErrorMessage string + }{ + { + name: "query and queries missing", + metric: &v1alpha1.DatadogMetric{ + ApiVersion: "v1", + Query: "", + Queries: nil, + }, + expectedErrorMessage: "Must have either a query or queries", + }, + { + name: "both query and queries", + metric: &v1alpha1.DatadogMetric{ + ApiVersion: "v1", + Query: "foo", + Queries: map[string]string{"a": "how much wood could a wood chuck chuck"}, + }, + expectedErrorMessage: "Cannot have both a query and queries", + }, + { + name: "queries with v1 api", + metric: &v1alpha1.DatadogMetric{ + ApiVersion: "v1", + Queries: map[string]string{"a": "how much wood could a wood chuck chuck"}, + }, + expectedErrorMessage: "Query is empty. API Version v1 only supports using the query parameter in your Analysis Template.", + }, + { + name: "formula/queries with wrong apiVersion", + metric: &v1alpha1.DatadogMetric{ + ApiVersion: "v1", + Queries: map[string]string{"a": "how much wood could a wood chuck chuck"}, + Formula: "a + b", + }, + expectedErrorMessage: "Query is empty. API Version v1 only supports using the query parameter in your Analysis Template.", + }, + { + name: "formula without queries", + metric: &v1alpha1.DatadogMetric{ + ApiVersion: "v1", + Formula: "foo / bar", + Query: "foo", + }, + expectedErrorMessage: "Formula are only valid when queries are set", + }, + { + name: "valid simple query with v2", + metric: &v1alpha1.DatadogMetric{ + ApiVersion: "v2", + Query: "foo", + }, + expectedErrorMessage: "", + }, + { + name: "valid queries with v2", + metric: &v1alpha1.DatadogMetric{ + ApiVersion: "v2", + Query: "", + Queries: map[string]string{"a": "how much wood could a wood chuck chuck"}, + Formula: "a + b", + }, + expectedErrorMessage: "", + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + err := validateIncomingProps(test.metric) + if test.expectedErrorMessage != "" { + assert.Error(t, err) + assert.Contains(t, err.Error(), test.expectedErrorMessage) + } else { + assert.NoError(t, err) + } + }) + } +}