Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
6f72ae38
Unverified
Commit
6f72ae38
authored
Jan 06, 2021
by
Emil Hessman
Committed by
GitHub
Jan 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Chore: Rewrite tsdb azuremonitor time grain test to standard library (#30089)
parent
874dc3d5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
60 deletions
+45
-60
pkg/tsdb/azuremonitor/time-grain_test.go
+45
-60
No files found.
pkg/tsdb/azuremonitor/time-grain_test.go
View file @
6f72ae38
...
...
@@ -3,69 +3,54 @@ package azuremonitor
import
(
"testing"
.
"github.com/smartystreets/goconvey/convey"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func
TestTimeGrain
(
t
*
testing
.
T
)
{
Convey
(
"TimeGrain"
,
t
,
func
()
{
tgc
:=
&
TimeGrain
{}
Convey
(
"create ISO 8601 Duration"
,
func
()
{
Convey
(
"when given a time unit smaller than a day"
,
func
()
{
minuteKbnDuration
:=
tgc
.
createISO8601Duration
(
1
,
"m"
)
hourKbnDuration
:=
tgc
.
createISO8601Duration
(
2
,
"h"
)
minuteDuration
:=
tgc
.
createISO8601Duration
(
1
,
"minute"
)
hourDuration
:=
tgc
.
createISO8601Duration
(
2
,
"hour"
)
Convey
(
"should convert it to a time duration"
,
func
()
{
So
(
minuteKbnDuration
,
ShouldEqual
,
"PT1M"
)
So
(
hourKbnDuration
,
ShouldEqual
,
"PT2H"
)
So
(
minuteDuration
,
ShouldEqual
,
"PT1M"
)
So
(
hourDuration
,
ShouldEqual
,
"PT2H"
)
})
})
Convey
(
"when given the day time unit"
,
func
()
{
kbnDuration
:=
tgc
.
createISO8601Duration
(
1
,
"d"
)
duration
:=
tgc
.
createISO8601Duration
(
2
,
"day"
)
Convey
(
"should convert it to a date duration"
,
func
()
{
So
(
kbnDuration
,
ShouldEqual
,
"P1D"
)
So
(
duration
,
ShouldEqual
,
"P2D"
)
})
})
func
TestTimeGrain_createISO8601Duration
(
t
*
testing
.
T
)
{
tg
:=
&
TimeGrain
{}
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
:=
tg
.
createISO8601Duration
(
tc
.
value
,
tc
.
unit
)
assert
.
Equal
(
t
,
tc
.
expected
,
d
)
})
}
}
Convey
(
"create ISO 8601 Duration from Grafana interval in milliseconds"
,
func
()
{
Convey
(
"and interval is less than a minute"
,
func
()
{
durationMS
,
err
:=
tgc
.
createISO8601DurationFromIntervalMS
(
100
)
So
(
err
,
ShouldBeNil
)
durationS
,
err
:=
tgc
.
createISO8601DurationFromIntervalMS
(
59999
)
So
(
err
,
ShouldBeNil
)
Convey
(
"should be rounded up to a minute as is the minimum interval for Azure Monitor"
,
func
()
{
So
(
durationMS
,
ShouldEqual
,
"PT1M"
)
So
(
durationS
,
ShouldEqual
,
"PT1M"
)
})
})
Convey
(
"and interval is more than a minute"
,
func
()
{
intervals
:=
map
[
string
]
int64
{
"10m"
:
600000
,
"2d"
:
172800000
,
}
durationM
,
err
:=
tgc
.
createISO8601DurationFromIntervalMS
(
intervals
[
"10m"
])
So
(
err
,
ShouldBeNil
)
durationD
,
err
:=
tgc
.
createISO8601DurationFromIntervalMS
(
intervals
[
"2d"
])
So
(
err
,
ShouldBeNil
)
Convey
(
"should be rounded up to a minute as is the minimum interval for Azure Monitor"
,
func
()
{
So
(
durationM
,
ShouldEqual
,
"PT10M"
)
So
(
durationD
,
ShouldEqual
,
"P2D"
)
})
})
func
TestTimeGrain_createISO8601DurationFromIntervalMS
(
t
*
testing
.
T
)
{
tg
:=
&
TimeGrain
{}
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
:=
tg
.
createISO8601DurationFromIntervalMS
(
tc
.
interval
)
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
tc
.
expected
,
d
)
})
}
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment