mocks.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright 2020 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package conf
  5. import (
  6. "sync"
  7. "testing"
  8. )
  9. func SetMockApp(t *testing.T, opts AppOpts) {
  10. before := App
  11. App = opts
  12. t.Cleanup(func() {
  13. App = before
  14. })
  15. }
  16. func SetMockAuth(t *testing.T, otps AuthOpts) {
  17. before := Auth
  18. Auth = otps
  19. t.Cleanup(func() {
  20. Auth = before
  21. })
  22. }
  23. var mockServer sync.Mutex
  24. func SetMockServer(t *testing.T, opts ServerOpts) {
  25. mockServer.Lock()
  26. before := Server
  27. Server = opts
  28. t.Cleanup(func() {
  29. Server = before
  30. mockServer.Unlock()
  31. })
  32. }
  33. var mockSSH sync.Mutex
  34. func SetMockSSH(t *testing.T, opts SSHOpts) {
  35. mockSSH.Lock()
  36. before := SSH
  37. SSH = opts
  38. t.Cleanup(func() {
  39. SSH = before
  40. mockSSH.Unlock()
  41. })
  42. }
  43. var mockRepository sync.Mutex
  44. func SetMockRepository(t *testing.T, opts RepositoryOpts) {
  45. mockRepository.Lock()
  46. before := Repository
  47. Repository = opts
  48. t.Cleanup(func() {
  49. Repository = before
  50. mockRepository.Unlock()
  51. })
  52. }
  53. func SetMockUI(t *testing.T, opts UIOpts) {
  54. before := UI
  55. UI = opts
  56. t.Cleanup(func() {
  57. UI = before
  58. })
  59. }
  60. var mockPicture sync.Mutex
  61. func SetMockPicture(t *testing.T, opts PictureOpts) {
  62. mockPicture.Lock()
  63. before := Picture
  64. Picture = opts
  65. t.Cleanup(func() {
  66. Picture = before
  67. mockPicture.Unlock()
  68. })
  69. }