mirror of
https://github.com/go-gitea/gitea
synced 2025-07-03 09:07:19 +00:00
Refactor some tests (#34580)
1. use `test.MockVariableValue` as much as possible 2. avoid `time.Sleep` as much as possible
This commit is contained in:
@ -18,7 +18,7 @@
|
||||
id: 2
|
||||
hook_id: 1
|
||||
uuid: uuid2
|
||||
is_delivered: false
|
||||
is_delivered: true
|
||||
|
||||
-
|
||||
id: 3
|
||||
|
@ -39,8 +39,6 @@ func TestPushMirrorsIterate(t *testing.T) {
|
||||
Interval: 0,
|
||||
})
|
||||
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
|
||||
repo_model.PushMirrorsIterate(db.DefaultContext, 1, func(idx int, bean any) error {
|
||||
m, ok := bean.(*repo_model.PushMirror)
|
||||
assert.True(t, ok)
|
||||
|
@ -513,11 +513,8 @@ func TestIsUserVisibleToViewer(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_ValidateUser(t *testing.T) {
|
||||
oldSetting := setting.Service.AllowedUserVisibilityModesSlice
|
||||
defer func() {
|
||||
setting.Service.AllowedUserVisibilityModesSlice = oldSetting
|
||||
}()
|
||||
setting.Service.AllowedUserVisibilityModesSlice = []bool{true, false, true}
|
||||
defer test.MockVariableValue(&setting.Service.AllowedUserVisibilityModesSlice, []bool{true, false, true})()
|
||||
|
||||
kases := map[*user_model.User]bool{
|
||||
{ID: 1, Visibility: structs.VisibleTypePublic}: true,
|
||||
{ID: 2, Visibility: structs.VisibleTypeLimited}: false,
|
||||
@ -586,12 +583,7 @@ func TestDisabledUserFeatures(t *testing.T) {
|
||||
testValues := container.SetOf(setting.UserFeatureDeletion,
|
||||
setting.UserFeatureManageSSHKeys,
|
||||
setting.UserFeatureManageGPGKeys)
|
||||
|
||||
oldSetting := setting.Admin.ExternalUserDisableFeatures
|
||||
defer func() {
|
||||
setting.Admin.ExternalUserDisableFeatures = oldSetting
|
||||
}()
|
||||
setting.Admin.ExternalUserDisableFeatures = testValues
|
||||
defer test.MockVariableValue(&setting.Admin.ExternalUserDisableFeatures, testValues)()
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
||||
|
||||
|
Reference in New Issue
Block a user