2019-11-14 03:59:41 -06:00
|
|
|
package cloudwatch
|
|
|
|
|
|
|
|
import (
|
2020-01-17 06:22:43 -06:00
|
|
|
"context"
|
2019-11-14 03:59:41 -06:00
|
|
|
"testing"
|
2021-03-23 10:32:12 -05:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
2019-11-14 03:59:41 -06:00
|
|
|
|
2020-05-18 05:25:58 -05:00
|
|
|
"github.com/stretchr/testify/assert"
|
2019-11-14 03:59:41 -06:00
|
|
|
)
|
|
|
|
|
2020-01-17 06:22:43 -06:00
|
|
|
func TestTimeSeriesQuery(t *testing.T) {
|
2021-03-23 10:32:12 -05:00
|
|
|
executor := newExecutor(nil, nil, newTestConfig(), fakeSessionCache{})
|
|
|
|
now := time.Now()
|
2019-11-14 03:59:41 -06:00
|
|
|
|
2020-05-18 05:25:58 -05:00
|
|
|
t.Run("End time before start time should result in error", func(t *testing.T) {
|
2021-03-23 10:32:12 -05:00
|
|
|
_, err := executor.executeTimeSeriesQuery(context.TODO(), &backend.QueryDataRequest{Queries: []backend.DataQuery{{TimeRange: backend.TimeRange{
|
|
|
|
From: now.Add(time.Hour * -1),
|
|
|
|
To: now.Add(time.Hour * -2),
|
|
|
|
}}}})
|
2020-05-18 05:25:58 -05:00
|
|
|
assert.EqualError(t, err, "invalid time range: start time must be before end time")
|
|
|
|
})
|
2019-11-14 03:59:41 -06:00
|
|
|
|
2020-05-18 05:25:58 -05:00
|
|
|
t.Run("End time equals start time should result in error", func(t *testing.T) {
|
2021-03-23 10:32:12 -05:00
|
|
|
_, err := executor.executeTimeSeriesQuery(context.TODO(), &backend.QueryDataRequest{Queries: []backend.DataQuery{{TimeRange: backend.TimeRange{
|
|
|
|
From: now.Add(time.Hour * -1),
|
|
|
|
To: now.Add(time.Hour * -1),
|
|
|
|
}}}})
|
2020-05-18 05:25:58 -05:00
|
|
|
assert.EqualError(t, err, "invalid time range: start time must be before end time")
|
2019-11-14 03:59:41 -06:00
|
|
|
})
|
|
|
|
}
|