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
8c7e7e6d
Unverified
Commit
8c7e7e6d
authored
Nov 16, 2020
by
Emil Hessman
Committed by
GitHub
Nov 16, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Chore: Rewrite preferences test from GoConvey to stdlib and testify (#29129)
parent
115f38f5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
103 additions
and
106 deletions
+103
-106
pkg/services/sqlstore/preferences_test.go
+103
-106
No files found.
pkg/services/sqlstore/preferences_test.go
View file @
8c7e7e6d
...
@@ -5,116 +5,113 @@ package sqlstore
...
@@ -5,116 +5,113 @@ package sqlstore
import
(
import
(
"testing"
"testing"
.
"github.com/smartystreets/goconvey/convey"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/setting"
"github.com/stretchr/testify/require"
)
)
func
TestPreferencesDataAccess
(
t
*
testing
.
T
)
{
func
TestPreferencesDataAccess
(
t
*
testing
.
T
)
{
Convey
(
"Testing preferences data access"
,
t
,
func
()
{
ss
:=
InitTestDB
(
t
)
ss
:=
InitTestDB
(
t
)
t
.
Run
(
"GetPreferencesWithDefaults with no saved preferences should return defaults"
,
func
(
t
*
testing
.
T
)
{
Convey
(
"GetPreferencesWithDefaults with no saved preferences should return defaults"
,
func
()
{
setting
.
DefaultTheme
=
"light"
setting
.
DefaultTheme
=
"light"
ss
.
Cfg
.
DateFormats
.
DefaultTimezone
=
"UTC"
ss
.
Cfg
.
DateFormats
.
DefaultTimezone
=
"UTC"
query
:=
&
models
.
GetPreferencesWithDefaultsQuery
{
User
:
&
models
.
SignedInUser
{}}
query
:=
&
models
.
GetPreferencesWithDefaultsQuery
{
User
:
&
models
.
SignedInUser
{}}
err
:=
ss
.
GetPreferencesWithDefaults
(
query
)
err
:=
ss
.
GetPreferencesWithDefaults
(
query
)
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
require
.
Equal
(
t
,
"light"
,
query
.
Result
.
Theme
)
So
(
query
.
Result
.
Theme
,
ShouldEqual
,
"light"
)
require
.
Equal
(
t
,
"UTC"
,
query
.
Result
.
Timezone
)
So
(
query
.
Result
.
Timezone
,
ShouldEqual
,
"UTC"
)
require
.
Equal
(
t
,
int64
(
0
),
query
.
Result
.
HomeDashboardId
)
So
(
query
.
Result
.
HomeDashboardId
,
ShouldEqual
,
0
)
})
})
t
.
Run
(
"GetPreferencesWithDefaults with saved org and user home dashboard should return user home dashboard"
,
func
(
t
*
testing
.
T
)
{
Convey
(
"GetPreferencesWithDefaults with saved org and user home dashboard should return user home dashboard"
,
func
()
{
err
:=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
HomeDashboardId
:
1
})
err
:=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
HomeDashboardId
:
1
})
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
err
=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
UserId
:
1
,
HomeDashboardId
:
4
})
err
=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
UserId
:
1
,
HomeDashboardId
:
4
})
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
query
:=
&
models
.
GetPreferencesWithDefaultsQuery
{
User
:
&
models
.
SignedInUser
{
OrgId
:
1
,
UserId
:
1
}}
query
:=
&
models
.
GetPreferencesWithDefaultsQuery
{
User
:
&
models
.
SignedInUser
{
OrgId
:
1
,
UserId
:
1
}}
err
=
ss
.
GetPreferencesWithDefaults
(
query
)
err
=
ss
.
GetPreferencesWithDefaults
(
query
)
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
require
.
Equal
(
t
,
int64
(
4
),
query
.
Result
.
HomeDashboardId
)
So
(
query
.
Result
.
HomeDashboardId
,
ShouldEqual
,
4
)
})
})
t
.
Run
(
"GetPreferencesWithDefaults with saved org and other user home dashboard should return org home dashboard"
,
func
(
t
*
testing
.
T
)
{
Convey
(
"GetPreferencesWithDefaults with saved org and other user home dashboard should return org home dashboard"
,
func
()
{
err
:=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
HomeDashboardId
:
1
})
err
:=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
HomeDashboardId
:
1
})
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
err
=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
UserId
:
1
,
HomeDashboardId
:
4
})
err
=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
UserId
:
1
,
HomeDashboardId
:
4
})
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
query
:=
&
models
.
GetPreferencesWithDefaultsQuery
{
User
:
&
models
.
SignedInUser
{
OrgId
:
1
,
UserId
:
2
}}
query
:=
&
models
.
GetPreferencesWithDefaultsQuery
{
User
:
&
models
.
SignedInUser
{
OrgId
:
1
,
UserId
:
2
}}
err
=
ss
.
GetPreferencesWithDefaults
(
query
)
err
=
ss
.
GetPreferencesWithDefaults
(
query
)
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
require
.
Equal
(
t
,
int64
(
1
),
query
.
Result
.
HomeDashboardId
)
So
(
query
.
Result
.
HomeDashboardId
,
ShouldEqual
,
1
)
})
})
t
.
Run
(
"GetPreferencesWithDefaults with saved org and teams home dashboard should return last team home dashboard"
,
func
(
t
*
testing
.
T
)
{
Convey
(
"GetPreferencesWithDefaults with saved org and teams home dashboard should return last team home dashboard"
,
func
()
{
err
:=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
HomeDashboardId
:
1
})
err
:=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
HomeDashboardId
:
1
})
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
err
=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
TeamId
:
2
,
HomeDashboardId
:
2
})
err
=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
TeamId
:
2
,
HomeDashboardId
:
2
})
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
err
=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
TeamId
:
3
,
HomeDashboardId
:
3
})
err
=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
TeamId
:
3
,
HomeDashboardId
:
3
})
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
query
:=
&
models
.
GetPreferencesWithDefaultsQuery
{
query
:=
&
models
.
GetPreferencesWithDefaultsQuery
{
User
:
&
models
.
SignedInUser
{
OrgId
:
1
,
Teams
:
[]
int64
{
2
,
3
}},
User
:
&
models
.
SignedInUser
{
OrgId
:
1
,
Teams
:
[]
int64
{
2
,
3
}},
}
}
err
=
ss
.
GetPreferencesWithDefaults
(
query
)
err
=
ss
.
GetPreferencesWithDefaults
(
query
)
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
require
.
Equal
(
t
,
int64
(
3
),
query
.
Result
.
HomeDashboardId
)
So
(
query
.
Result
.
HomeDashboardId
,
ShouldEqual
,
3
)
})
})
t
.
Run
(
"GetPreferencesWithDefaults with saved org and other teams home dashboard should return org home dashboard"
,
func
(
t
*
testing
.
T
)
{
Convey
(
"GetPreferencesWithDefaults with saved org and other teams home dashboard should return org home dashboard"
,
func
()
{
err
:=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
HomeDashboardId
:
1
})
err
:=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
HomeDashboardId
:
1
})
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
err
=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
TeamId
:
2
,
HomeDashboardId
:
2
})
err
=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
TeamId
:
2
,
HomeDashboardId
:
2
})
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
err
=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
TeamId
:
3
,
HomeDashboardId
:
3
})
err
=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
TeamId
:
3
,
HomeDashboardId
:
3
})
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
query
:=
&
models
.
GetPreferencesWithDefaultsQuery
{
User
:
&
models
.
SignedInUser
{
OrgId
:
1
}}
query
:=
&
models
.
GetPreferencesWithDefaultsQuery
{
User
:
&
models
.
SignedInUser
{
OrgId
:
1
}}
err
=
ss
.
GetPreferencesWithDefaults
(
query
)
err
=
ss
.
GetPreferencesWithDefaults
(
query
)
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
require
.
Equal
(
t
,
int64
(
1
),
query
.
Result
.
HomeDashboardId
)
So
(
query
.
Result
.
HomeDashboardId
,
ShouldEqual
,
1
)
})
})
t
.
Run
(
"GetPreferencesWithDefaults with saved org, teams and user home dashboard should return user home dashboard"
,
func
(
t
*
testing
.
T
)
{
Convey
(
"GetPreferencesWithDefaults with saved org, teams and user home dashboard should return user home dashboard"
,
func
()
{
err
:=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
HomeDashboardId
:
1
})
err
:=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
HomeDashboardId
:
1
})
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
err
=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
TeamId
:
2
,
HomeDashboardId
:
2
})
err
=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
TeamId
:
2
,
HomeDashboardId
:
2
})
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
err
=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
TeamId
:
3
,
HomeDashboardId
:
3
})
err
=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
TeamId
:
3
,
HomeDashboardId
:
3
})
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
err
=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
UserId
:
1
,
HomeDashboardId
:
4
})
err
=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
UserId
:
1
,
HomeDashboardId
:
4
})
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
query
:=
&
models
.
GetPreferencesWithDefaultsQuery
{
query
:=
&
models
.
GetPreferencesWithDefaultsQuery
{
User
:
&
models
.
SignedInUser
{
OrgId
:
1
,
UserId
:
1
,
Teams
:
[]
int64
{
2
,
3
}},
User
:
&
models
.
SignedInUser
{
OrgId
:
1
,
UserId
:
1
,
Teams
:
[]
int64
{
2
,
3
}},
}
}
err
=
ss
.
GetPreferencesWithDefaults
(
query
)
err
=
ss
.
GetPreferencesWithDefaults
(
query
)
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
require
.
Equal
(
t
,
int64
(
4
),
query
.
Result
.
HomeDashboardId
)
So
(
query
.
Result
.
HomeDashboardId
,
ShouldEqual
,
4
)
})
})
t
.
Run
(
"GetPreferencesWithDefaults with saved org, other teams and user home dashboard should return org home dashboard"
,
func
(
t
*
testing
.
T
)
{
Convey
(
"GetPreferencesWithDefaults with saved org, other teams and user home dashboard should return org home dashboard"
,
func
()
{
err
:=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
HomeDashboardId
:
1
})
err
:=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
HomeDashboardId
:
1
})
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
err
=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
TeamId
:
2
,
HomeDashboardId
:
2
})
err
=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
TeamId
:
2
,
HomeDashboardId
:
2
})
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
err
=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
TeamId
:
3
,
HomeDashboardId
:
3
})
err
=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
TeamId
:
3
,
HomeDashboardId
:
3
})
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
err
=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
UserId
:
1
,
HomeDashboardId
:
4
})
err
=
SavePreferences
(
&
models
.
SavePreferencesCommand
{
OrgId
:
1
,
UserId
:
1
,
HomeDashboardId
:
4
})
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
query
:=
&
models
.
GetPreferencesWithDefaultsQuery
{
query
:=
&
models
.
GetPreferencesWithDefaultsQuery
{
User
:
&
models
.
SignedInUser
{
OrgId
:
1
,
UserId
:
2
},
User
:
&
models
.
SignedInUser
{
OrgId
:
1
,
UserId
:
2
},
}
}
err
=
ss
.
GetPreferencesWithDefaults
(
query
)
err
=
ss
.
GetPreferencesWithDefaults
(
query
)
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
require
.
Equal
(
t
,
int64
(
1
),
query
.
Result
.
HomeDashboardId
)
So
(
query
.
Result
.
HomeDashboardId
,
ShouldEqual
,
1
)
})
})
})
}
}
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