2022-06-12 10:34:12 +08:00
|
|
|
// Copyright 2020 The Gogs Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
2020-04-06 18:35:10 +08:00
|
|
|
|
2024-02-18 19:39:41 -05:00
|
|
|
package database
|
2020-04-06 18:35:10 +08:00
|
|
|
|
|
|
|
|
import (
|
2022-06-12 10:34:12 +08:00
|
|
|
"testing"
|
2020-04-06 18:35:10 +08:00
|
|
|
)
|
|
|
|
|
|
2022-06-12 10:34:12 +08:00
|
|
|
func SetMockAccessTokensStore(t *testing.T, mock AccessTokensStore) {
|
|
|
|
|
before := AccessTokens
|
|
|
|
|
AccessTokens = mock
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
|
AccessTokens = before
|
2022-06-10 11:27:06 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-12 10:34:12 +08:00
|
|
|
func SetMockLFSStore(t *testing.T, mock LFSStore) {
|
|
|
|
|
before := LFS
|
|
|
|
|
LFS = mock
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
|
LFS = before
|
2022-06-10 11:27:06 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-12 10:34:12 +08:00
|
|
|
func setMockLoginSourcesStore(t *testing.T, mock LoginSourcesStore) {
|
|
|
|
|
before := LoginSources
|
|
|
|
|
LoginSources = mock
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
|
LoginSources = before
|
2022-06-10 11:27:06 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-19 20:00:13 -05:00
|
|
|
func setMockLoginSourceFilesStore(t *testing.T, db *loginSourcesStore, mock loginSourceFilesStore) {
|
2022-06-12 10:34:12 +08:00
|
|
|
before := db.files
|
|
|
|
|
db.files = mock
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
|
db.files = before
|
2022-06-10 11:27:06 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-12 10:34:12 +08:00
|
|
|
func SetMockPermsStore(t *testing.T, mock PermsStore) {
|
|
|
|
|
before := Perms
|
|
|
|
|
Perms = mock
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
|
Perms = before
|
2022-06-10 11:27:06 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-12 10:34:12 +08:00
|
|
|
func SetMockReposStore(t *testing.T, mock ReposStore) {
|
|
|
|
|
before := Repos
|
|
|
|
|
Repos = mock
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
|
Repos = before
|
2022-06-10 11:27:06 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-12 10:34:12 +08:00
|
|
|
func SetMockTwoFactorsStore(t *testing.T, mock TwoFactorsStore) {
|
|
|
|
|
before := TwoFactors
|
|
|
|
|
TwoFactors = mock
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
|
TwoFactors = before
|
2022-06-08 19:26:20 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-12 10:34:12 +08:00
|
|
|
func SetMockUsersStore(t *testing.T, mock UsersStore) {
|
|
|
|
|
before := Users
|
|
|
|
|
Users = mock
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
|
Users = before
|
2022-06-08 19:26:20 +08:00
|
|
|
})
|
|
|
|
|
}
|