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
71899a0e
Unverified
Commit
71899a0e
authored
Jan 01, 2021
by
Emil Hessman
Committed by
GitHub
Jan 01, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Chore: Rewrite models dashboards test to standard library (#30023)
parent
4f3a7bb0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
44 deletions
+48
-44
pkg/models/dashboards_test.go
+48
-44
No files found.
pkg/models/dashboards_test.go
View file @
71899a0e
...
...
@@ -5,78 +5,82 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/setting"
.
"github.com/smartystreets/goconvey/convey"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func
TestDashboardModel
(
t
*
testing
.
T
)
{
Convey
(
"Generate full dashboard url"
,
t
,
func
()
{
setting
.
AppUrl
=
"http://grafana.local/"
fullUrl
:=
GetFullDashboardUrl
(
"uid"
,
"my-dashboard"
)
So
(
fullUrl
,
ShouldEqual
,
"http://grafana.local/d/uid/my-dashboard"
)
})
func
TestGetDashboardUrl
(
t
*
testing
.
T
)
{
origAppURL
:=
setting
.
AppUrl
t
.
Cleanup
(
func
()
{
setting
.
AppUrl
=
origAppURL
})
Convey
(
"Generate relative dashboard url"
,
t
,
func
()
{
setting
.
AppUrl
=
""
fullUrl
:=
GetDashboardUrl
(
"uid"
,
"my-dashboard"
)
So
(
fullUrl
,
ShouldEqual
,
"/d/uid/my-dashboard"
)
})
Convey
(
"When generating slug"
,
t
,
func
()
{
dashboard
:=
NewDashboard
(
"Grafana Play Home"
)
dashboard
.
UpdateSlug
()
url
:=
GetDashboardUrl
(
"uid"
,
"my-dashboard"
)
assert
.
Equal
(
t
,
"/d/uid/my-dashboard"
,
url
)
}
So
(
dashboard
.
Slug
,
ShouldEqual
,
"grafana-play-home"
)
})
func
TestGetFullDashboardUrl
(
t
*
testing
.
T
)
{
origAppURL
:=
setting
.
AppUrl
t
.
Cleanup
(
func
()
{
setting
.
AppUrl
=
origAppURL
})
Convey
(
"Can slugify titles"
,
t
,
func
()
{
tests
:=
map
[
string
]
string
{
"Grafana Play Home"
:
"grafana-play-home"
,
"snöräv-över-ån"
:
"snorav-over-an"
,
"漢字"
:
"han-zi"
,
// Hanzi for hanzi
"🇦🇶"
:
"8J-HpvCfh7Y"
,
// flag of Antarctica-emoji, using fallback
"𒆠"
:
"8JKGoA"
,
// cuneiform Ki, using fallback
}
setting
.
AppUrl
=
"http://grafana.local/"
url
:=
GetFullDashboardUrl
(
"uid"
,
"my-dashboard"
)
assert
.
Equal
(
t
,
"http://grafana.local/d/uid/my-dashboard"
,
url
)
}
for
input
,
expected
:=
range
tests
{
slug
:=
SlugifyTitle
(
input
)
func
TestDashboard_UpdateSlug
(
t
*
testing
.
T
)
{
dashboard
:=
NewDashboard
(
"Grafana Play Home"
)
assert
.
Equal
(
t
,
"grafana-play-home"
,
dashboard
.
Slug
)
So
(
slug
,
ShouldEqual
,
expected
)
}
})
dashboard
.
UpdateSlug
(
)
assert
.
Equal
(
t
,
"grafana-play-home"
,
dashboard
.
Slug
)
}
Convey
(
"Given a dashboard json"
,
t
,
func
(
)
{
func
TestNewDashboardFromJson
(
t
*
testing
.
T
)
{
json
:=
simplejson
.
New
()
json
.
Set
(
"title"
,
"test dash"
)
Convey
(
"With tags as string value"
,
func
()
{
json
.
Set
(
"tags"
,
""
)
dash
:=
NewDashboardFromJson
(
json
)
So
(
len
(
dash
.
GetTags
()),
ShouldEqual
,
0
)
})
})
dash
:=
NewDashboardFromJson
(
json
)
assert
.
Equal
(
t
,
"test dash"
,
dash
.
Title
)
require
.
Empty
(
t
,
dash
.
GetTags
())
}
Convey
(
"Given a new dashboard folder"
,
t
,
func
()
{
func
TestSaveDashboardCommand_GetDashboardModel
(
t
*
testing
.
T
)
{
t
.
Run
(
"should set IsFolder"
,
func
(
t
*
testing
.
T
)
{
json
:=
simplejson
.
New
()
json
.
Set
(
"title"
,
"test dash"
)
cmd
:=
&
SaveDashboardCommand
{
Dashboard
:
json
,
IsFolder
:
true
}
dash
:=
cmd
.
GetDashboardModel
()
Convey
(
"Should set IsFolder to true"
,
func
()
{
So
(
dash
.
IsFolder
,
ShouldBeTrue
)
})
assert
.
Equal
(
t
,
"test dash"
,
dash
.
Title
)
assert
.
True
(
t
,
dash
.
IsFolder
)
})
Convey
(
"Given a child dashboard"
,
t
,
func
(
)
{
t
.
Run
(
"should set FolderId"
,
func
(
t
*
testing
.
T
)
{
json
:=
simplejson
.
New
()
json
.
Set
(
"title"
,
"test dash"
)
cmd
:=
&
SaveDashboardCommand
{
Dashboard
:
json
,
FolderId
:
1
}
dash
:=
cmd
.
GetDashboardModel
()
Convey
(
"Should set FolderId"
,
func
()
{
So
(
dash
.
FolderId
,
ShouldEqual
,
1
)
assert
.
Equal
(
t
,
int64
(
1
),
dash
.
FolderId
)
})
}
func
TestSlugifyTitle
(
t
*
testing
.
T
)
{
testCases
:=
map
[
string
]
string
{
"Grafana Play Home"
:
"grafana-play-home"
,
"snöräv-över-ån"
:
"snorav-over-an"
,
"漢字"
:
"han-zi"
,
// Hanzi for hanzi
"🇦🇶"
:
"8J-HpvCfh7Y"
,
// flag of Antarctica-emoji, using fallback
"𒆠"
:
"8JKGoA"
,
// cuneiform Ki, using fallback
}
for
input
,
expected
:=
range
testCases
{
t
.
Run
(
input
,
func
(
t
*
testing
.
T
)
{
slug
:=
SlugifyTitle
(
input
)
assert
.
Equal
(
t
,
expected
,
slug
)
})
}
}
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