mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 03:21:51 +08:00
chore: avoid aliasing imports in services (#22499)
This commit is contained in:
@ -6,10 +6,9 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"golang.org/x/oauth2"
|
||||
|
||||
m "github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
//nolint:goconst
|
||||
@ -18,9 +17,9 @@ func TestUserAuth(t *testing.T) {
|
||||
|
||||
Convey("Given 5 users", t, func() {
|
||||
var err error
|
||||
var cmd *m.CreateUserCommand
|
||||
var cmd *models.CreateUserCommand
|
||||
for i := 0; i < 5; i++ {
|
||||
cmd = &m.CreateUserCommand{
|
||||
cmd = &models.CreateUserCommand{
|
||||
Email: fmt.Sprint("user", i, "@test.com"),
|
||||
Name: fmt.Sprint("user", i),
|
||||
Login: fmt.Sprint("loginuser", i),
|
||||
@ -44,7 +43,7 @@ func TestUserAuth(t *testing.T) {
|
||||
// By Login
|
||||
login := "loginuser0"
|
||||
|
||||
query := &m.GetUserByAuthInfoQuery{Login: login}
|
||||
query := &models.GetUserByAuthInfoQuery{Login: login}
|
||||
err = GetUserByAuthInfo(query)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
@ -53,7 +52,7 @@ func TestUserAuth(t *testing.T) {
|
||||
// By ID
|
||||
id := query.Result.Id
|
||||
|
||||
query = &m.GetUserByAuthInfoQuery{UserId: id}
|
||||
query = &models.GetUserByAuthInfoQuery{UserId: id}
|
||||
err = GetUserByAuthInfo(query)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
@ -62,7 +61,7 @@ func TestUserAuth(t *testing.T) {
|
||||
// By Email
|
||||
email := "user1@test.com"
|
||||
|
||||
query = &m.GetUserByAuthInfoQuery{Email: email}
|
||||
query = &models.GetUserByAuthInfoQuery{Email: email}
|
||||
err = GetUserByAuthInfo(query)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
@ -71,19 +70,19 @@ func TestUserAuth(t *testing.T) {
|
||||
// Don't find nonexistent user
|
||||
email = "nonexistent@test.com"
|
||||
|
||||
query = &m.GetUserByAuthInfoQuery{Email: email}
|
||||
query = &models.GetUserByAuthInfoQuery{Email: email}
|
||||
err = GetUserByAuthInfo(query)
|
||||
|
||||
So(err, ShouldEqual, m.ErrUserNotFound)
|
||||
So(err, ShouldEqual, models.ErrUserNotFound)
|
||||
So(query.Result, ShouldBeNil)
|
||||
})
|
||||
|
||||
Convey("Can set & locate by AuthModule and AuthId", func() {
|
||||
// get nonexistent user_auth entry
|
||||
query := &m.GetUserByAuthInfoQuery{AuthModule: "test", AuthId: "test"}
|
||||
query := &models.GetUserByAuthInfoQuery{AuthModule: "test", AuthId: "test"}
|
||||
err = GetUserByAuthInfo(query)
|
||||
|
||||
So(err, ShouldEqual, m.ErrUserNotFound)
|
||||
So(err, ShouldEqual, models.ErrUserNotFound)
|
||||
So(query.Result, ShouldBeNil)
|
||||
|
||||
// create user_auth entry
|
||||
@ -96,7 +95,7 @@ func TestUserAuth(t *testing.T) {
|
||||
So(query.Result.Login, ShouldEqual, login)
|
||||
|
||||
// get via user_auth
|
||||
query = &m.GetUserByAuthInfoQuery{AuthModule: "test", AuthId: "test"}
|
||||
query = &models.GetUserByAuthInfoQuery{AuthModule: "test", AuthId: "test"}
|
||||
err = GetUserByAuthInfo(query)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
@ -112,7 +111,7 @@ func TestUserAuth(t *testing.T) {
|
||||
So(query.Result.Login, ShouldEqual, "loginuser1")
|
||||
|
||||
// get via user_auth
|
||||
query = &m.GetUserByAuthInfoQuery{AuthModule: "test", AuthId: "test"}
|
||||
query = &models.GetUserByAuthInfoQuery{AuthModule: "test", AuthId: "test"}
|
||||
err = GetUserByAuthInfo(query)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
@ -123,10 +122,10 @@ func TestUserAuth(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
// get via user_auth for deleted user
|
||||
query = &m.GetUserByAuthInfoQuery{AuthModule: "test", AuthId: "test"}
|
||||
query = &models.GetUserByAuthInfoQuery{AuthModule: "test", AuthId: "test"}
|
||||
err = GetUserByAuthInfo(query)
|
||||
|
||||
So(err, ShouldEqual, m.ErrUserNotFound)
|
||||
So(err, ShouldEqual, models.ErrUserNotFound)
|
||||
So(query.Result, ShouldBeNil)
|
||||
})
|
||||
|
||||
@ -142,13 +141,13 @@ func TestUserAuth(t *testing.T) {
|
||||
login := "loginuser0"
|
||||
|
||||
// Calling GetUserByAuthInfoQuery on an existing user will populate an entry in the user_auth table
|
||||
query := &m.GetUserByAuthInfoQuery{Login: login, AuthModule: "test", AuthId: "test"}
|
||||
query := &models.GetUserByAuthInfoQuery{Login: login, AuthModule: "test", AuthId: "test"}
|
||||
err = GetUserByAuthInfo(query)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
So(query.Result.Login, ShouldEqual, login)
|
||||
|
||||
cmd := &m.UpdateAuthInfoCommand{
|
||||
cmd := &models.UpdateAuthInfoCommand{
|
||||
UserId: query.Result.Id,
|
||||
AuthId: query.AuthId,
|
||||
AuthModule: query.AuthModule,
|
||||
@ -158,7 +157,7 @@ func TestUserAuth(t *testing.T) {
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
getAuthQuery := &m.GetAuthInfoQuery{
|
||||
getAuthQuery := &models.GetAuthInfoQuery{
|
||||
UserId: query.Result.Id,
|
||||
}
|
||||
|
||||
@ -178,7 +177,7 @@ func TestUserAuth(t *testing.T) {
|
||||
// Calling GetUserByAuthInfoQuery on an existing user will populate an entry in the user_auth table
|
||||
// Make the first log-in during the past
|
||||
getTime = func() time.Time { return time.Now().AddDate(0, 0, -2) }
|
||||
query := &m.GetUserByAuthInfoQuery{Login: login, AuthModule: "test1", AuthId: "test1"}
|
||||
query := &models.GetUserByAuthInfoQuery{Login: login, AuthModule: "test1", AuthId: "test1"}
|
||||
err = GetUserByAuthInfo(query)
|
||||
getTime = time.Now
|
||||
|
||||
@ -188,7 +187,7 @@ func TestUserAuth(t *testing.T) {
|
||||
// Add a second auth module for this user
|
||||
// Have this module's last log-in be more recent
|
||||
getTime = func() time.Time { return time.Now().AddDate(0, 0, -1) }
|
||||
query = &m.GetUserByAuthInfoQuery{Login: login, AuthModule: "test2", AuthId: "test2"}
|
||||
query = &models.GetUserByAuthInfoQuery{Login: login, AuthModule: "test2", AuthId: "test2"}
|
||||
err = GetUserByAuthInfo(query)
|
||||
getTime = time.Now
|
||||
|
||||
@ -196,7 +195,7 @@ func TestUserAuth(t *testing.T) {
|
||||
So(query.Result.Login, ShouldEqual, login)
|
||||
|
||||
// Get the latest entry by not supply an authmodule or authid
|
||||
getAuthQuery := &m.GetAuthInfoQuery{
|
||||
getAuthQuery := &models.GetAuthInfoQuery{
|
||||
UserId: query.Result.Id,
|
||||
}
|
||||
|
||||
@ -206,13 +205,13 @@ func TestUserAuth(t *testing.T) {
|
||||
So(getAuthQuery.Result.AuthModule, ShouldEqual, "test2")
|
||||
|
||||
// "log in" again with the first auth module
|
||||
updateAuthCmd := &m.UpdateAuthInfoCommand{UserId: query.Result.Id, AuthModule: "test1", AuthId: "test1"}
|
||||
updateAuthCmd := &models.UpdateAuthInfoCommand{UserId: query.Result.Id, AuthModule: "test1", AuthId: "test1"}
|
||||
err = UpdateAuthInfo(updateAuthCmd)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
// Get the latest entry by not supply an authmodule or authid
|
||||
getAuthQuery = &m.GetAuthInfoQuery{
|
||||
getAuthQuery = &models.GetAuthInfoQuery{
|
||||
UserId: query.Result.Id,
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user