pushremoteref.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. Copyright © 2025 ESO Maintainer Team
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. https://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. // Package fakes contains fake implementations for testing purposes.
  14. package fakes
  15. import (
  16. "sync"
  17. v1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"
  18. )
  19. // PushRemoteRef is a fake implementation of the PushRemoteRef interface for testing.
  20. type PushRemoteRef struct {
  21. GetRemoteKeyStub func() string
  22. getRemoteKeyMutex sync.RWMutex
  23. getRemoteKeyArgsForCall []struct {
  24. }
  25. getRemoteKeyReturns struct {
  26. result1 string
  27. }
  28. getRemoteKeyReturnsOnCall map[int]struct {
  29. result1 string
  30. }
  31. invocations map[string][][]any
  32. invocationsMutex sync.RWMutex
  33. }
  34. // GetRemoteKey returns a string representing the remote key.
  35. func (fake *PushRemoteRef) GetRemoteKey() string {
  36. fake.getRemoteKeyMutex.Lock()
  37. ret, specificReturn := fake.getRemoteKeyReturnsOnCall[len(fake.getRemoteKeyArgsForCall)]
  38. fake.getRemoteKeyArgsForCall = append(fake.getRemoteKeyArgsForCall, struct {
  39. }{})
  40. stub := fake.GetRemoteKeyStub
  41. fakeReturns := fake.getRemoteKeyReturns
  42. fake.recordInvocation("GetRemoteKey", []any{})
  43. fake.getRemoteKeyMutex.Unlock()
  44. if stub != nil {
  45. return stub()
  46. }
  47. if specificReturn {
  48. return ret.result1
  49. }
  50. return fakeReturns.result1
  51. }
  52. // GetProperty returns the property value as a string.
  53. func (fake *PushRemoteRef) GetProperty() string {
  54. return ""
  55. }
  56. // GetRemoteKeyCallCount returns the number of times GetRemoteKey has been called.
  57. func (fake *PushRemoteRef) GetRemoteKeyCallCount() int {
  58. fake.getRemoteKeyMutex.RLock()
  59. defer fake.getRemoteKeyMutex.RUnlock()
  60. return len(fake.getRemoteKeyArgsForCall)
  61. }
  62. // GetRemoteKeyCalls sets a custom stub function for the GetRemoteKey method.
  63. func (fake *PushRemoteRef) GetRemoteKeyCalls(stub func() string) {
  64. fake.getRemoteKeyMutex.Lock()
  65. defer fake.getRemoteKeyMutex.Unlock()
  66. fake.GetRemoteKeyStub = stub
  67. }
  68. // GetRemoteKeyReturns sets return values that will be returned by GetRemoteKey.
  69. func (fake *PushRemoteRef) GetRemoteKeyReturns(result1 string) {
  70. fake.getRemoteKeyMutex.Lock()
  71. defer fake.getRemoteKeyMutex.Unlock()
  72. fake.GetRemoteKeyStub = nil
  73. fake.getRemoteKeyReturns = struct {
  74. result1 string
  75. }{result1}
  76. }
  77. // GetRemoteKeyReturnsOnCall sets return values for specific calls to GetRemoteKey.
  78. func (fake *PushRemoteRef) GetRemoteKeyReturnsOnCall(i int, result1 string) {
  79. fake.getRemoteKeyMutex.Lock()
  80. defer fake.getRemoteKeyMutex.Unlock()
  81. fake.GetRemoteKeyStub = nil
  82. if fake.getRemoteKeyReturnsOnCall == nil {
  83. fake.getRemoteKeyReturnsOnCall = make(map[int]struct {
  84. result1 string
  85. })
  86. }
  87. fake.getRemoteKeyReturnsOnCall[i] = struct {
  88. result1 string
  89. }{result1}
  90. }
  91. // Invocations returns a map recording the calls to methods on this fake.
  92. func (fake *PushRemoteRef) Invocations() map[string][][]any {
  93. fake.invocationsMutex.RLock()
  94. defer fake.invocationsMutex.RUnlock()
  95. fake.getRemoteKeyMutex.RLock()
  96. defer fake.getRemoteKeyMutex.RUnlock()
  97. copiedInvocations := map[string][][]any{}
  98. for key, value := range fake.invocations {
  99. copiedInvocations[key] = value
  100. }
  101. return copiedInvocations
  102. }
  103. func (fake *PushRemoteRef) recordInvocation(key string, args []any) {
  104. fake.invocationsMutex.Lock()
  105. defer fake.invocationsMutex.Unlock()
  106. if fake.invocations == nil {
  107. fake.invocations = map[string][][]any{}
  108. }
  109. if fake.invocations[key] == nil {
  110. fake.invocations[key] = [][]any{}
  111. }
  112. fake.invocations[key] = append(fake.invocations[key], args)
  113. }
  114. var _ v1.PushSecretRemoteRef = new(PushRemoteRef)