pushremoteref.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. Copyright © The ESO Authors
  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. "maps"
  17. "sync"
  18. v1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"
  19. )
  20. // PushRemoteRef is a fake implementation of the PushRemoteRef interface for testing.
  21. type PushRemoteRef struct {
  22. GetRemoteKeyStub func() string
  23. getRemoteKeyMutex sync.RWMutex
  24. getRemoteKeyArgsForCall []struct {
  25. }
  26. getRemoteKeyReturns struct {
  27. result1 string
  28. }
  29. getRemoteKeyReturnsOnCall map[int]struct {
  30. result1 string
  31. }
  32. invocations map[string][][]any
  33. invocationsMutex sync.RWMutex
  34. }
  35. // GetRemoteKey returns a string representing the remote key.
  36. func (fake *PushRemoteRef) GetRemoteKey() string {
  37. fake.getRemoteKeyMutex.Lock()
  38. ret, specificReturn := fake.getRemoteKeyReturnsOnCall[len(fake.getRemoteKeyArgsForCall)]
  39. fake.getRemoteKeyArgsForCall = append(fake.getRemoteKeyArgsForCall, struct {
  40. }{})
  41. stub := fake.GetRemoteKeyStub
  42. fakeReturns := fake.getRemoteKeyReturns
  43. fake.recordInvocation("GetRemoteKey", []any{})
  44. fake.getRemoteKeyMutex.Unlock()
  45. if stub != nil {
  46. return stub()
  47. }
  48. if specificReturn {
  49. return ret.result1
  50. }
  51. return fakeReturns.result1
  52. }
  53. // GetProperty returns the property value as a string.
  54. func (fake *PushRemoteRef) GetProperty() string {
  55. return ""
  56. }
  57. // GetRemoteKeyCallCount returns the number of times GetRemoteKey has been called.
  58. func (fake *PushRemoteRef) GetRemoteKeyCallCount() int {
  59. fake.getRemoteKeyMutex.RLock()
  60. defer fake.getRemoteKeyMutex.RUnlock()
  61. return len(fake.getRemoteKeyArgsForCall)
  62. }
  63. // GetRemoteKeyCalls sets a custom stub function for the GetRemoteKey method.
  64. func (fake *PushRemoteRef) GetRemoteKeyCalls(stub func() string) {
  65. fake.getRemoteKeyMutex.Lock()
  66. defer fake.getRemoteKeyMutex.Unlock()
  67. fake.GetRemoteKeyStub = stub
  68. }
  69. // GetRemoteKeyReturns sets return values that will be returned by GetRemoteKey.
  70. func (fake *PushRemoteRef) GetRemoteKeyReturns(result1 string) {
  71. fake.getRemoteKeyMutex.Lock()
  72. defer fake.getRemoteKeyMutex.Unlock()
  73. fake.GetRemoteKeyStub = nil
  74. fake.getRemoteKeyReturns = struct {
  75. result1 string
  76. }{result1}
  77. }
  78. // GetRemoteKeyReturnsOnCall sets return values for specific calls to GetRemoteKey.
  79. func (fake *PushRemoteRef) GetRemoteKeyReturnsOnCall(i int, result1 string) {
  80. fake.getRemoteKeyMutex.Lock()
  81. defer fake.getRemoteKeyMutex.Unlock()
  82. fake.GetRemoteKeyStub = nil
  83. if fake.getRemoteKeyReturnsOnCall == nil {
  84. fake.getRemoteKeyReturnsOnCall = make(map[int]struct {
  85. result1 string
  86. })
  87. }
  88. fake.getRemoteKeyReturnsOnCall[i] = struct {
  89. result1 string
  90. }{result1}
  91. }
  92. // Invocations returns a map recording the calls to methods on this fake.
  93. func (fake *PushRemoteRef) Invocations() map[string][][]any {
  94. fake.invocationsMutex.RLock()
  95. defer fake.invocationsMutex.RUnlock()
  96. fake.getRemoteKeyMutex.RLock()
  97. defer fake.getRemoteKeyMutex.RUnlock()
  98. copiedInvocations := map[string][][]any{}
  99. maps.Copy(copiedInvocations, fake.invocations)
  100. return copiedInvocations
  101. }
  102. func (fake *PushRemoteRef) recordInvocation(key string, args []any) {
  103. fake.invocationsMutex.Lock()
  104. defer fake.invocationsMutex.Unlock()
  105. if fake.invocations == nil {
  106. fake.invocations = map[string][][]any{}
  107. }
  108. if fake.invocations[key] == nil {
  109. fake.invocations[key] = [][]any{}
  110. }
  111. fake.invocations[key] = append(fake.invocations[key], args)
  112. }
  113. var _ v1.PushSecretRemoteRef = new(PushRemoteRef)