grafana/pkg/tsdb/azuremonitor/time/time-grain_test.go
Andreas Christou 9d16718acc
AzureMonitor: Fix logs query multi-resource and timespan values (#67914)
* Update TimeGrain interface methods

- Make them util functions because it's simpler

* Update logs ds to appropiately set resources and timespan

* Set timespan using RCF times

* Update tests
2023-05-05 16:47:31 +01:00

53 lines
1.1 KiB
Go

package time
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestTimeGrain_createISO8601Duration(t *testing.T) {
testCases := []struct {
name string
value int
unit string
expected string
}{
{"1m", 1, "m", "PT1M"},
{"1minute", 1, "minute", "PT1M"},
{"2h", 2, "h", "PT2H"},
{"2hour", 2, "hour", "PT2H"},
{"1d", 1, "d", "P1D"},
{"2day", 2, "day", "P2D"},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
d := createISO8601Duration(tc.value, tc.unit)
assert.Equal(t, tc.expected, d)
})
}
}
func TestTimeGrain_createISO8601DurationFromIntervalMS(t *testing.T) {
testCases := []struct {
name string
interval int64
expected string
}{
{"100", 100, "PT1M"},
{"59999", 59999, "PT1M"},
{"600000", 600000, "PT10M"},
{"172800000", 172800000, "P2D"},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
d, err := CreateISO8601DurationFromIntervalMS(tc.interval)
require.NoError(t, err)
assert.Equal(t, tc.expected, d)
})
}
}