2021-11-11 15:03:30 +08:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-28 02:20:29 +08:00
|
|
|
// SPDX-License-Identifier: MIT
|
2021-11-11 15:03:30 +08:00
|
|
|
|
2022-06-15 15:02:00 +08:00
|
|
|
package user_test
|
2021-11-11 15:03:30 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-09-25 21:17:37 +08:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2021-11-12 22:36:47 +08:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2022-06-15 15:02:00 +08:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2021-11-12 22:36:47 +08:00
|
|
|
|
2021-11-11 15:03:30 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLookupUserRedirect(t *testing.T) {
|
2021-11-12 22:36:47 +08:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-11-11 15:03:30 +08:00
|
|
|
|
2023-09-25 21:17:37 +08:00
|
|
|
userID, err := user_model.LookupUserRedirect(db.DefaultContext, "olduser1")
|
2021-11-11 15:03:30 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, 1, userID)
|
|
|
|
|
2023-09-25 21:17:37 +08:00
|
|
|
_, err = user_model.LookupUserRedirect(db.DefaultContext, "doesnotexist")
|
2022-06-15 15:02:00 +08:00
|
|
|
assert.True(t, user_model.IsErrUserRedirectNotExist(err))
|
2021-11-11 15:03:30 +08:00
|
|
|
}
|