mocks.go 938 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. "testing"
  7. )
  8. func SetMockApp(t *testing.T, opts AppOpts) {
  9. before := App
  10. App = opts
  11. t.Cleanup(func() {
  12. App = before
  13. })
  14. }
  15. func SetMockAuth(t *testing.T, otps AuthOpts) {
  16. before := Auth
  17. Auth = otps
  18. t.Cleanup(func() {
  19. Auth = before
  20. })
  21. }
  22. func SetMockServer(t *testing.T, opts ServerOpts) {
  23. before := Server
  24. Server = opts
  25. t.Cleanup(func() {
  26. Server = before
  27. })
  28. }
  29. func SetMockSSH(t *testing.T, opts SSHOpts) {
  30. before := SSH
  31. SSH = opts
  32. t.Cleanup(func() {
  33. SSH = before
  34. })
  35. }
  36. func SetMockRepository(t *testing.T, opts RepositoryOpts) {
  37. before := Repository
  38. Repository = opts
  39. t.Cleanup(func() {
  40. Repository = before
  41. })
  42. }
  43. func SetMockUI(t *testing.T, opts UIOpts) {
  44. before := UI
  45. UI = opts
  46. t.Cleanup(func() {
  47. UI = before
  48. })
  49. }