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
59d89e42
Commit
59d89e42
authored
Nov 15, 2017
by
Alexander Zobnin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard history clean up: add tests
parent
d4e2f850
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
0 deletions
+42
-0
pkg/services/sqlstore/dashboard_version_test.go
+42
-0
No files found.
pkg/services/sqlstore/dashboard_version_test.go
View file @
59d89e42
...
@@ -8,6 +8,7 @@ import (
...
@@ -8,6 +8,7 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/components/simplejson"
m
"github.com/grafana/grafana/pkg/models"
m
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
)
)
func
updateTestDashboard
(
dashboard
*
m
.
Dashboard
,
data
map
[
string
]
interface
{})
{
func
updateTestDashboard
(
dashboard
*
m
.
Dashboard
,
data
map
[
string
]
interface
{})
{
...
@@ -101,3 +102,44 @@ func TestGetDashboardVersions(t *testing.T) {
...
@@ -101,3 +102,44 @@ func TestGetDashboardVersions(t *testing.T) {
})
})
})
})
}
}
func
TestDeleteExpiredVersions
(
t
*
testing
.
T
)
{
Convey
(
"Testing dashboard versions clean up"
,
t
,
func
()
{
InitTestDB
(
t
)
versionsToKeep
:=
5
versionsToWrite
:=
10
setting
.
DashboardVersionsToKeep
=
versionsToKeep
savedDash
:=
insertTestDashboard
(
"test dash 53"
,
1
,
"diff-all"
)
for
i
:=
0
;
i
<
versionsToWrite
-
1
;
i
++
{
updateTestDashboard
(
savedDash
,
map
[
string
]
interface
{}{
"tags"
:
"different-tag"
,
})
}
Convey
(
"Clean up old dashboard versions"
,
func
()
{
err
:=
DeleteExpiredVersions
(
&
m
.
DeleteExpiredVersionsCommand
{})
So
(
err
,
ShouldBeNil
)
query
:=
m
.
GetDashboardVersionsQuery
{
DashboardId
:
savedDash
.
Id
,
OrgId
:
1
}
GetDashboardVersions
(
&
query
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
versionsToKeep
)
// Ensure latest versions were kept
So
(
query
.
Result
[
versionsToKeep
-
1
]
.
Version
,
ShouldEqual
,
versionsToWrite
-
versionsToKeep
+
1
)
So
(
query
.
Result
[
0
]
.
Version
,
ShouldEqual
,
versionsToWrite
)
})
Convey
(
"Don't delete anything if there're no expired versions"
,
func
()
{
setting
.
DashboardVersionsToKeep
=
versionsToWrite
err
:=
DeleteExpiredVersions
(
&
m
.
DeleteExpiredVersionsCommand
{})
So
(
err
,
ShouldBeNil
)
query
:=
m
.
GetDashboardVersionsQuery
{
DashboardId
:
savedDash
.
Id
,
OrgId
:
1
}
GetDashboardVersions
(
&
query
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
versionsToWrite
)
})
})
}
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