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
c296ae11
Commit
c296ae11
authored
Jun 05, 2017
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring: fixing unit tests broken in last commit
parent
e1800715
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
39 deletions
+32
-39
pkg/services/sqlstore/dashboard_version.go
+6
-6
pkg/services/sqlstore/dashboard_version_test.go
+26
-33
No files found.
pkg/services/sqlstore/dashboard_version.go
View file @
c296ae11
...
@@ -32,12 +32,12 @@ func init() {
...
@@ -32,12 +32,12 @@ func init() {
// CompareDashboardVersionsCommand computes the JSON diff of two versions,
// CompareDashboardVersionsCommand computes the JSON diff of two versions,
// assigning the delta of the diff to the `Delta` field.
// assigning the delta of the diff to the `Delta` field.
func
CompareDashboardVersionsCommand
(
cmd
*
m
.
CompareDashboardVersionsCommand
)
error
{
func
CompareDashboardVersionsCommand
(
cmd
*
m
.
CompareDashboardVersionsCommand
)
error
{
original
,
err
:=
getDashboardVersion
(
cmd
.
DashboardId
,
cmd
.
Original
,
cmd
.
OrgId
)
original
,
err
:=
getDashboardVersion
(
cmd
.
DashboardId
,
cmd
.
Original
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
newDashboard
,
err
:=
getDashboardVersion
(
cmd
.
DashboardId
,
cmd
.
New
,
cmd
.
OrgId
)
newDashboard
,
err
:=
getDashboardVersion
(
cmd
.
DashboardId
,
cmd
.
New
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -80,7 +80,7 @@ func CompareDashboardVersionsCommand(cmd *m.CompareDashboardVersionsCommand) err
...
@@ -80,7 +80,7 @@ func CompareDashboardVersionsCommand(cmd *m.CompareDashboardVersionsCommand) err
// GetDashboardVersion gets the dashboard version for the given dashboard ID
// GetDashboardVersion gets the dashboard version for the given dashboard ID
// and version number.
// and version number.
func
GetDashboardVersion
(
query
*
m
.
GetDashboardVersionQuery
)
error
{
func
GetDashboardVersion
(
query
*
m
.
GetDashboardVersionQuery
)
error
{
result
,
err
:=
getDashboardVersion
(
query
.
DashboardId
,
query
.
Version
,
query
.
OrgId
)
result
,
err
:=
getDashboardVersion
(
query
.
DashboardId
,
query
.
Version
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -128,7 +128,7 @@ func RestoreDashboardVersion(cmd *m.RestoreDashboardVersionCommand) error {
...
@@ -128,7 +128,7 @@ func RestoreDashboardVersion(cmd *m.RestoreDashboardVersionCommand) error {
// session instead of using the global `x`, so we copy those functions
// session instead of using the global `x`, so we copy those functions
// here, replacing `x` with `sess`
// here, replacing `x` with `sess`
dashboardVersion
:=
m
.
DashboardVersion
{}
dashboardVersion
:=
m
.
DashboardVersion
{}
has
,
err
:=
sess
.
Where
(
"dashboard_id=? AND version=?
AND org_id=?"
,
cmd
.
DashboardId
,
cmd
.
Version
,
cmd
.
OrgId
)
.
Get
(
&
dashboardVersion
)
has
,
err
:=
sess
.
Where
(
"dashboard_id=? AND version=?
"
,
cmd
.
DashboardId
,
cmd
.
Version
)
.
Get
(
&
dashboardVersion
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -190,9 +190,9 @@ func RestoreDashboardVersion(cmd *m.RestoreDashboardVersionCommand) error {
...
@@ -190,9 +190,9 @@ func RestoreDashboardVersion(cmd *m.RestoreDashboardVersionCommand) error {
// getDashboardVersion is a helper function that gets the dashboard version for
// getDashboardVersion is a helper function that gets the dashboard version for
// the given dashboard ID and version ID.
// the given dashboard ID and version ID.
func
getDashboardVersion
(
dashboardId
int64
,
version
int
,
orgId
int64
)
(
*
m
.
DashboardVersion
,
error
)
{
func
getDashboardVersion
(
dashboardId
int64
,
version
int
)
(
*
m
.
DashboardVersion
,
error
)
{
dashboardVersion
:=
m
.
DashboardVersion
{}
dashboardVersion
:=
m
.
DashboardVersion
{}
has
,
err
:=
x
.
Where
(
"dashboard_id=? AND version=?
AND org_id=?"
,
dashboardId
,
version
,
orgId
)
.
Get
(
&
dashboardVersion
)
has
,
err
:=
x
.
Where
(
"dashboard_id=? AND version=?
"
,
dashboardId
,
version
)
.
Get
(
&
dashboardVersion
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
pkg/services/sqlstore/dashboard_version_test.go
View file @
c296ae11
...
@@ -30,15 +30,15 @@ func TestGetDashboardVersion(t *testing.T) {
...
@@ -30,15 +30,15 @@ func TestGetDashboardVersion(t *testing.T) {
Convey
(
"Get a Dashboard ID and version ID"
,
func
()
{
Convey
(
"Get a Dashboard ID and version ID"
,
func
()
{
savedDash
:=
insertTestDashboard
(
"test dash 26"
,
1
,
"diff"
)
savedDash
:=
insertTestDashboard
(
"test dash 26"
,
1
,
"diff"
)
cmd
:=
m
.
GetDashboardVersionCommand
{
query
:=
m
.
GetDashboardVersionQuery
{
DashboardId
:
savedDash
.
Id
,
DashboardId
:
savedDash
.
Id
,
Version
:
savedDash
.
Version
,
Version
:
savedDash
.
Version
,
}
}
err
:=
GetDashboardVersion
(
&
cmd
)
err
:=
GetDashboardVersion
(
&
query
)
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
So
(
savedDash
.
Id
,
ShouldEqual
,
cmd
.
DashboardId
)
So
(
savedDash
.
Id
,
ShouldEqual
,
query
.
DashboardId
)
So
(
savedDash
.
Version
,
ShouldEqual
,
cmd
.
Version
)
So
(
savedDash
.
Version
,
ShouldEqual
,
query
.
Version
)
dashCmd
:=
m
.
GetDashboardQuery
{
dashCmd
:=
m
.
GetDashboardQuery
{
OrgId
:
savedDash
.
OrgId
,
OrgId
:
savedDash
.
OrgId
,
...
@@ -46,17 +46,17 @@ func TestGetDashboardVersion(t *testing.T) {
...
@@ -46,17 +46,17 @@ func TestGetDashboardVersion(t *testing.T) {
}
}
err
=
GetDashboard
(
&
dashCmd
)
err
=
GetDashboard
(
&
dashCmd
)
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
eq
:=
reflect
.
DeepEqual
(
dashCmd
.
Result
.
Data
,
cmd
.
Result
.
Data
)
eq
:=
reflect
.
DeepEqual
(
dashCmd
.
Result
.
Data
,
query
.
Result
.
Data
)
So
(
eq
,
ShouldEqual
,
true
)
So
(
eq
,
ShouldEqual
,
true
)
})
})
Convey
(
"Attempt to get a version that doesn't exist"
,
func
()
{
Convey
(
"Attempt to get a version that doesn't exist"
,
func
()
{
cmd
:=
m
.
GetDashboardVersionCommand
{
query
:=
m
.
GetDashboardVersionQuery
{
DashboardId
:
int64
(
999
),
DashboardId
:
int64
(
999
),
Version
:
123
,
Version
:
123
,
}
}
err
:=
GetDashboardVersion
(
&
cmd
)
err
:=
GetDashboardVersion
(
&
query
)
So
(
err
,
ShouldNotBeNil
)
So
(
err
,
ShouldNotBeNil
)
So
(
err
,
ShouldEqual
,
m
.
ErrDashboardVersionNotFound
)
So
(
err
,
ShouldEqual
,
m
.
ErrDashboardVersionNotFound
)
})
})
...
@@ -69,24 +69,20 @@ func TestGetDashboardVersions(t *testing.T) {
...
@@ -69,24 +69,20 @@ func TestGetDashboardVersions(t *testing.T) {
savedDash
:=
insertTestDashboard
(
"test dash 43"
,
1
,
"diff-all"
)
savedDash
:=
insertTestDashboard
(
"test dash 43"
,
1
,
"diff-all"
)
Convey
(
"Get all versions for a given Dashboard ID"
,
func
()
{
Convey
(
"Get all versions for a given Dashboard ID"
,
func
()
{
cmd
:=
m
.
GetDashboardVersionsCommand
{
query
:=
m
.
GetDashboardVersionsQuery
{
DashboardId
:
savedDash
.
Id
,
OrgId
:
1
}
DashboardId
:
savedDash
.
Id
,
}
err
:=
GetDashboardVersions
(
&
cmd
)
err
:=
GetDashboardVersions
(
&
query
)
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
So
(
len
(
cmd
.
Result
),
ShouldEqual
,
1
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
1
)
})
})
Convey
(
"Attempt to get the versions for a non-existent Dashboard ID"
,
func
()
{
Convey
(
"Attempt to get the versions for a non-existent Dashboard ID"
,
func
()
{
cmd
:=
m
.
GetDashboardVersionsCommand
{
query
:=
m
.
GetDashboardVersionsQuery
{
DashboardId
:
int64
(
999
),
OrgId
:
1
}
DashboardId
:
int64
(
999
),
}
err
:=
GetDashboardVersions
(
&
cmd
)
err
:=
GetDashboardVersions
(
&
query
)
So
(
err
,
ShouldNotBeNil
)
So
(
err
,
ShouldNotBeNil
)
So
(
err
,
ShouldEqual
,
m
.
ErrNoVersionsForDashboardId
)
So
(
err
,
ShouldEqual
,
m
.
ErrNoVersionsForDashboardId
)
So
(
len
(
cmd
.
Result
),
ShouldEqual
,
0
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
0
)
})
})
Convey
(
"Get all versions for an updated dashboard"
,
func
()
{
Convey
(
"Get all versions for an updated dashboard"
,
func
()
{
...
@@ -94,12 +90,11 @@ func TestGetDashboardVersions(t *testing.T) {
...
@@ -94,12 +90,11 @@ func TestGetDashboardVersions(t *testing.T) {
"tags"
:
"different-tag"
,
"tags"
:
"different-tag"
,
})
})
cmd
:=
m
.
GetDashboardVersionsCommand
{
query
:=
m
.
GetDashboardVersionsQuery
{
DashboardId
:
savedDash
.
Id
,
OrgId
:
1
}
DashboardId
:
savedDash
.
Id
,
err
:=
GetDashboardVersions
(
&
query
)
}
err
:=
GetDashboardVersions
(
&
cmd
)
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
So
(
len
(
cmd
.
Result
),
ShouldEqual
,
2
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
2
)
})
})
})
})
}
}
...
@@ -114,19 +109,19 @@ func TestCompareDashboardVersions(t *testing.T) {
...
@@ -114,19 +109,19 @@ func TestCompareDashboardVersions(t *testing.T) {
})
})
Convey
(
"Compare two versions that are different"
,
func
()
{
Convey
(
"Compare two versions that are different"
,
func
()
{
getVersionCmd
:=
m
.
GetDashboardVersionsCommand
{
query
:=
m
.
GetDashboardVersionsQuery
{
DashboardId
:
savedDash
.
Id
,
OrgId
:
1
}
DashboardId
:
savedDash
.
Id
,
}
err
:=
GetDashboardVersions
(
&
query
)
err
:=
GetDashboardVersions
(
&
getVersionCmd
)
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
So
(
len
(
getVersionCmd
.
Result
),
ShouldEqual
,
2
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
2
)
cmd
:=
m
.
CompareDashboardVersionsCommand
{
cmd
:=
m
.
CompareDashboardVersionsCommand
{
DashboardId
:
savedDash
.
Id
,
DashboardId
:
savedDash
.
Id
,
Original
:
getVersionCmd
.
Result
[
0
]
.
Version
,
Original
:
query
.
Result
[
0
]
.
Version
,
New
:
getVersionCmd
.
Result
[
1
]
.
Version
,
New
:
query
.
Result
[
1
]
.
Version
,
DiffType
:
m
.
DiffDelta
,
DiffType
:
m
.
DiffDelta
,
}
}
err
=
CompareDashboardVersionsCommand
(
&
cmd
)
err
=
CompareDashboardVersionsCommand
(
&
cmd
)
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
So
(
cmd
.
Delta
,
ShouldNotBeNil
)
So
(
cmd
.
Delta
,
ShouldNotBeNil
)
...
@@ -169,10 +164,8 @@ func TestRestoreDashboardVersion(t *testing.T) {
...
@@ -169,10 +164,8 @@ func TestRestoreDashboardVersion(t *testing.T) {
})
})
Convey
(
"Restore dashboard to a previous version"
,
func
()
{
Convey
(
"Restore dashboard to a previous version"
,
func
()
{
versionsCmd
:=
m
.
GetDashboardVersionsCommand
{
query
:=
m
.
GetDashboardVersionsQuery
{
DashboardId
:
savedDash
.
Id
,
OrgId
:
1
}
DashboardId
:
savedDash
.
Id
,
err
:=
GetDashboardVersions
(
&
query
)
}
err
:=
GetDashboardVersions
(
&
versionsCmd
)
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
cmd
:=
m
.
RestoreDashboardVersionCommand
{
cmd
:=
m
.
RestoreDashboardVersionCommand
{
...
...
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