2020-04-06 23:53:55 +08:00
|
|
|
package conf
|
|
|
|
|
|
|
|
|
|
import (
|
2022-11-25 22:40:20 +08:00
|
|
|
"sync"
|
2020-04-06 23:53:55 +08:00
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
2022-06-25 18:07:39 +08:00
|
|
|
func SetMockApp(t *testing.T, opts AppOpts) {
|
|
|
|
|
before := App
|
|
|
|
|
App = opts
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
|
App = before
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-22 14:41:40 +08:00
|
|
|
func SetMockAuth(t *testing.T, otps AuthOpts) {
|
|
|
|
|
before := Auth
|
|
|
|
|
Auth = otps
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
|
Auth = before
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 22:40:20 +08:00
|
|
|
var mockServer sync.Mutex
|
|
|
|
|
|
2020-04-06 23:53:55 +08:00
|
|
|
func SetMockServer(t *testing.T, opts ServerOpts) {
|
2022-11-25 22:40:20 +08:00
|
|
|
mockServer.Lock()
|
2020-04-06 23:53:55 +08:00
|
|
|
before := Server
|
|
|
|
|
Server = opts
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
|
Server = before
|
2022-11-25 22:40:20 +08:00
|
|
|
mockServer.Unlock()
|
2020-04-06 23:53:55 +08:00
|
|
|
})
|
|
|
|
|
}
|
2022-06-25 18:07:39 +08:00
|
|
|
|
2023-02-07 23:39:00 +08:00
|
|
|
var mockSSH sync.Mutex
|
|
|
|
|
|
2022-06-25 18:07:39 +08:00
|
|
|
func SetMockSSH(t *testing.T, opts SSHOpts) {
|
2023-02-07 23:39:00 +08:00
|
|
|
mockSSH.Lock()
|
2022-06-25 18:07:39 +08:00
|
|
|
before := SSH
|
|
|
|
|
SSH = opts
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
|
SSH = before
|
2023-02-07 23:39:00 +08:00
|
|
|
mockSSH.Unlock()
|
2022-06-25 18:07:39 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 22:40:20 +08:00
|
|
|
var mockRepository sync.Mutex
|
|
|
|
|
|
2022-06-25 18:07:39 +08:00
|
|
|
func SetMockRepository(t *testing.T, opts RepositoryOpts) {
|
2022-11-25 22:40:20 +08:00
|
|
|
mockRepository.Lock()
|
2022-06-25 18:07:39 +08:00
|
|
|
before := Repository
|
|
|
|
|
Repository = opts
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
|
Repository = before
|
2022-11-25 22:40:20 +08:00
|
|
|
mockRepository.Unlock()
|
2022-06-25 18:07:39 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func SetMockUI(t *testing.T, opts UIOpts) {
|
|
|
|
|
before := UI
|
|
|
|
|
UI = opts
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
|
UI = before
|
|
|
|
|
})
|
|
|
|
|
}
|
2022-10-22 20:01:38 +08:00
|
|
|
|
2023-02-07 23:39:00 +08:00
|
|
|
var mockPicture sync.Mutex
|
|
|
|
|
|
2022-10-22 20:01:38 +08:00
|
|
|
func SetMockPicture(t *testing.T, opts PictureOpts) {
|
2023-02-07 23:39:00 +08:00
|
|
|
mockPicture.Lock()
|
2022-10-22 20:01:38 +08:00
|
|
|
before := Picture
|
|
|
|
|
Picture = opts
|
|
|
|
|
t.Cleanup(func() {
|
|
|
|
|
Picture = before
|
2023-02-07 23:39:00 +08:00
|
|
|
mockPicture.Unlock()
|
2022-10-22 20:01:38 +08:00
|
|
|
})
|
|
|
|
|
}
|