Files
grafana/pkg/tsdb/cloudwatch/metric_data_input_builder_test.go
T
Nathan Vērzemnieks 560be84dc8 [release-12.0.5] Backport aws-sdk-go-v2 update and subsequent fixes (#111243)
* CloudWatch: Backport aws-sdk-go-v2 update from external plugin (#107136)

(cherry picked from a18ea34688)

* Datasources: Update grafana-aws-sdk for new sigv4 middleware and aws-sdk-go v1 removal (#107522)

(cherry picked from commit 66d9a33cc9)

* CloudWatch: Fix proxy transport issue (#107807)

(cherry picked from c3eeb1fcd9)

* CloudWatch: Fix http client handling + assume role bug (#107893)

(cherry picked from commit f34a9fc0c2)

* CloudWatch: Use default region when query region is unset (#109089)

(cherry picked from commit 5f4097a159)

* CloudWatch: Fix handling region for legacy alerts (#109217)

(cherry picked from commit 2bf9aea8ef)

* Update go.mod owners

---------

Co-authored-by: Isabella Siu <Isabella.siu@grafana.com>
2025-09-19 12:46:40 +02:00

45 lines
1.2 KiB
Go

package cloudwatch
import (
"context"
"testing"
"time"
"github.com/aws/aws-sdk-go-v2/aws"
cloudwatchtypes "github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models"
)
func TestMetricDataInputBuilder(t *testing.T) {
now := time.Now()
tests := []struct {
name string
timezoneUTCOffset string
expectedLabelOptions *cloudwatchtypes.LabelOptions
}{
{name: "when timezoneUTCOffset is provided", timezoneUTCOffset: "+1234", expectedLabelOptions: &cloudwatchtypes.LabelOptions{Timezone: aws.String("+1234")}},
{name: "when timezoneUTCOffset is not provided", timezoneUTCOffset: "", expectedLabelOptions: nil},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
ds := newTestDatasource()
query := getBaseQuery()
query.TimezoneUTCOffset = tc.timezoneUTCOffset
from := now.Add(time.Hour * -2)
to := now.Add(time.Hour * -1)
mdi, err := ds.buildMetricDataInput(context.Background(), from, to, []*models.CloudWatchQuery{query})
assert.NoError(t, err)
require.NotNil(t, mdi)
assert.Equal(t, tc.expectedLabelOptions, mdi.LabelOptions)
})
}
}