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
408c96fe
Unverified
Commit
408c96fe
authored
Dec 20, 2020
by
Emil Hessman
Committed by
GitHub
Dec 20, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Chore: Convert tsdb interval test to standard library (#29935)
parent
c4e141c1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
44 deletions
+49
-44
pkg/tsdb/interval_test.go
+49
-44
No files found.
pkg/tsdb/interval_test.go
View file @
408c96fe
...
...
@@ -4,59 +4,64 @@ import (
"testing"
"time"
"github.com/grafana/grafana/pkg/setting"
.
"github.com/smartystreets/goconvey/convey"
"github.com/stretchr/testify/assert"
)
func
TestInterval
(
t
*
testing
.
T
)
{
Convey
(
"Default interval "
,
t
,
func
()
{
cfg
:=
setting
.
NewCfg
()
err
:=
cfg
.
Load
(
&
setting
.
CommandLineArgs
{
HomePath
:
"../../"
,
})
So
(
err
,
ShouldBeNil
)
calculator
:=
NewIntervalCalculator
(
&
IntervalOptions
{})
Convey
(
"for 5min"
,
func
()
{
tr
:=
NewTimeRange
(
"5m"
,
"now"
)
func
TestIntervalCalculator_Calculate
(
t
*
testing
.
T
)
{
calculator
:=
NewIntervalCalculator
(
&
IntervalOptions
{})
interval
:=
calculator
.
Calculate
(
tr
,
time
.
Millisecond
*
1
)
So
(
interval
.
Text
,
ShouldEqual
,
"200ms"
)
})
Convey
(
"for 15min"
,
func
()
{
tr
:=
NewTimeRange
(
"15m"
,
"now"
)
testCases
:=
[]
struct
{
name
string
timeRange
*
TimeRange
expected
string
}{
{
"from 5m to now"
,
NewTimeRange
(
"5m"
,
"now"
),
"200ms"
},
{
"from 15m to now"
,
NewTimeRange
(
"15m"
,
"now"
),
"500ms"
},
{
"from 30m to now"
,
NewTimeRange
(
"30m"
,
"now"
),
"1s"
},
{
"from 1h to now"
,
NewTimeRange
(
"1h"
,
"now"
),
"2s"
},
}
interval
:=
calculator
.
Calculate
(
tr
,
time
.
Millisecond
*
1
)
So
(
interval
.
Text
,
ShouldEqual
,
"500ms"
)
})
Convey
(
"for 30min"
,
func
()
{
tr
:=
NewTimeRange
(
"30m"
,
"now"
)
interval
:=
calculator
.
Calculate
(
tr
,
time
.
Millisecond
*
1
)
So
(
interval
.
Text
,
ShouldEqual
,
"1s"
)
for
_
,
tc
:=
range
testCases
{
t
.
Run
(
tc
.
name
,
func
(
t
*
testing
.
T
)
{
interval
:=
calculator
.
Calculate
(
tc
.
timeRange
,
time
.
Millisecond
*
1
)
assert
.
Equal
(
t
,
tc
.
expected
,
interval
.
Text
)
})
}
}
Convey
(
"for 1h"
,
func
()
{
tr
:=
NewTimeRange
(
"1h"
,
"now"
)
func
TestRoundInterval
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
name
string
interval
time
.
Duration
expected
time
.
Duration
}{
{
"30ms"
,
time
.
Millisecond
*
30
,
time
.
Millisecond
*
20
},
{
"45ms"
,
time
.
Millisecond
*
45
,
time
.
Millisecond
*
50
},
}
interval
:=
calculator
.
Calculate
(
tr
,
time
.
Millisecond
*
1
)
So
(
interval
.
Text
,
ShouldEqual
,
"2s"
)
for
_
,
tc
:=
range
testCases
{
t
.
Run
(
tc
.
name
,
func
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
tc
.
expected
,
roundInterval
(
tc
.
interval
))
})
}
}
Convey
(
"Round interval"
,
func
()
{
So
(
roundInterval
(
time
.
Millisecond
*
30
),
ShouldEqual
,
time
.
Millisecond
*
20
)
So
(
roundInterval
(
time
.
Millisecond
*
45
),
ShouldEqual
,
time
.
Millisecond
*
50
)
})
func
TestFormatDuration
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
name
string
duration
time
.
Duration
expected
string
}{
{
"61s"
,
time
.
Second
*
61
,
"1m"
},
{
"30ms"
,
time
.
Millisecond
*
30
,
"30ms"
},
{
"23h"
,
time
.
Hour
*
23
,
"23h"
},
{
"24h"
,
time
.
Hour
*
24
,
"1d"
},
{
"367d"
,
time
.
Hour
*
24
*
367
,
"1y"
},
}
Convey
(
"Format value"
,
func
()
{
So
(
FormatDuration
(
time
.
Second
*
61
),
ShouldEqual
,
"1m"
)
So
(
FormatDuration
(
time
.
Millisecond
*
30
),
ShouldEqual
,
"30ms"
)
So
(
FormatDuration
(
time
.
Hour
*
23
),
ShouldEqual
,
"23h"
)
So
(
FormatDuration
(
time
.
Hour
*
24
),
ShouldEqual
,
"1d"
)
So
(
FormatDuration
(
time
.
Hour
*
24
*
367
),
ShouldEqual
,
"1y"
)
for
_
,
tc
:=
range
testCases
{
t
.
Run
(
tc
.
name
,
func
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
tc
.
expected
,
FormatDuration
(
tc
.
duration
))
})
}
)
}
}
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