mocks.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. func SetMockSSH(t *testing.T, opts SSHOpts) {
  34. before := SSH
  35. SSH = opts
  36. t.Cleanup(func() {
  37. SSH = before
  38. })
  39. }
  40. var mockRepository sync.Mutex
  41. func SetMockRepository(t *testing.T, opts RepositoryOpts) {
  42. mockRepository.Lock()
  43. before := Repository
  44. Repository = opts
  45. t.Cleanup(func() {
  46. Repository = before
  47. mockRepository.Unlock()
  48. })
  49. }
  50. func SetMockUI(t *testing.T, opts UIOpts) {
  51. before := UI
  52. UI = opts
  53. t.Cleanup(func() {
  54. UI = before
  55. })
  56. }
  57. func SetMockPicture(t *testing.T, opts PictureOpts) {
  58. before := Picture
  59. Picture = opts
  60. t.Cleanup(func() {
  61. Picture = before
  62. })
  63. }