1
0

mocks.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package conf
  2. import (
  3. "sync"
  4. "testing"
  5. )
  6. func SetMockApp(t *testing.T, opts AppOpts) {
  7. before := App
  8. App = opts
  9. t.Cleanup(func() {
  10. App = before
  11. })
  12. }
  13. func SetMockAuth(t *testing.T, otps AuthOpts) {
  14. before := Auth
  15. Auth = otps
  16. t.Cleanup(func() {
  17. Auth = before
  18. })
  19. }
  20. var mockServer sync.Mutex
  21. func SetMockServer(t *testing.T, opts ServerOpts) {
  22. mockServer.Lock()
  23. before := Server
  24. Server = opts
  25. t.Cleanup(func() {
  26. Server = before
  27. mockServer.Unlock()
  28. })
  29. }
  30. var mockSSH sync.Mutex
  31. func SetMockSSH(t *testing.T, opts SSHOpts) {
  32. mockSSH.Lock()
  33. before := SSH
  34. SSH = opts
  35. t.Cleanup(func() {
  36. SSH = before
  37. mockSSH.Unlock()
  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. var mockPicture sync.Mutex
  58. func SetMockPicture(t *testing.T, opts PictureOpts) {
  59. mockPicture.Lock()
  60. before := Picture
  61. Picture = opts
  62. t.Cleanup(func() {
  63. Picture = before
  64. mockPicture.Unlock()
  65. })
  66. }