2022-05-16 18:15:54 +08:00
package cloudwatch
import (
2024-04-05 23:57:56 +08:00
"context"
2022-05-16 18:15:54 +08:00
"testing"
"time"
2025-06-26 21:56:50 +08:00
"github.com/aws/aws-sdk-go-v2/aws"
cloudwatchtypes "github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"
2022-05-16 18:15:54 +08:00
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
2022-10-20 17:21:13 +08:00
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models"
2022-05-16 18:15:54 +08:00
)
func TestMetricDataInputBuilder ( t * testing . T ) {
now := time . Now ( )
tests := [ ] struct {
name string
timezoneUTCOffset string
2025-06-26 21:56:50 +08:00
expectedLabelOptions * cloudwatchtypes . LabelOptions
2022-05-16 18:15:54 +08:00
} {
2025-06-26 21:56:50 +08:00
{ name : "when timezoneUTCOffset is provided" , timezoneUTCOffset : "+1234" , expectedLabelOptions : & cloudwatchtypes . LabelOptions { Timezone : aws . String ( "+1234" ) } } ,
2023-04-27 17:19:45 +08:00
{ name : "when timezoneUTCOffset is not provided" , timezoneUTCOffset : "" , expectedLabelOptions : nil } ,
2022-05-16 18:15:54 +08:00
}
for _ , tc := range tests {
t . Run ( tc . name , func ( t * testing . T ) {
2025-06-26 21:56:50 +08:00
ds := newTestDatasource ( )
2022-05-16 18:15:54 +08:00
query := getBaseQuery ( )
query . TimezoneUTCOffset = tc . timezoneUTCOffset
from := now . Add ( time . Hour * - 2 )
to := now . Add ( time . Hour * - 1 )
2025-06-26 21:56:50 +08:00
mdi , err := ds . buildMetricDataInput ( context . Background ( ) , from , to , [ ] * models . CloudWatchQuery { query } )
2022-05-16 18:15:54 +08:00
assert . NoError ( t , err )
require . NotNil ( t , mdi )
assert . Equal ( t , tc . expectedLabelOptions , mdi . LabelOptions )
} )
}
}