moq_allocation_model_test.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // Code generated by moq; DO NOT EDIT.
  2. // github.com/matryer/moq
  3. package costmodel
  4. import (
  5. "github.com/opencost/opencost/core/pkg/opencost"
  6. "sync"
  7. "time"
  8. )
  9. // Ensure, that AllocationModelMock does implement AllocationModel.
  10. // If this is not the case, regenerate this file with moq.
  11. var _ AllocationModel = &AllocationModelMock{}
  12. // AllocationModelMock is a mock implementation of AllocationModel.
  13. //
  14. // func TestSomethingThatUsesAllocationModel(t *testing.T) {
  15. //
  16. // // make and configure a mocked AllocationModel
  17. // mockedAllocationModel := &AllocationModelMock{
  18. // ComputeAllocationFunc: func(start time.Time, end time.Time, resolution time.Duration) (*opencost.AllocationSet, error) {
  19. // panic("mock out the ComputeAllocation method")
  20. // },
  21. // DateRangeFunc: func(limitDays int) (time.Time, time.Time, error) {
  22. // panic("mock out the DateRange method")
  23. // },
  24. // }
  25. //
  26. // // use mockedAllocationModel in code that requires AllocationModel
  27. // // and then make assertions.
  28. //
  29. // }
  30. type AllocationModelMock struct {
  31. // ComputeAllocationFunc mocks the ComputeAllocation method.
  32. ComputeAllocationFunc func(start time.Time, end time.Time, resolution time.Duration) (*opencost.AllocationSet, error)
  33. // DateRangeFunc mocks the DateRange method.
  34. DateRangeFunc func(limitDays int) (time.Time, time.Time, error)
  35. // calls tracks calls to the methods.
  36. calls struct {
  37. // ComputeAllocation holds details about calls to the ComputeAllocation method.
  38. ComputeAllocation []struct {
  39. // Start is the start argument value.
  40. Start time.Time
  41. // End is the end argument value.
  42. End time.Time
  43. // Resolution is the resolution argument value.
  44. Resolution time.Duration
  45. }
  46. // DateRange holds details about calls to the DateRange method.
  47. DateRange []struct {
  48. // LimitDays is the limitDays argument value.
  49. LimitDays int
  50. }
  51. }
  52. lockComputeAllocation sync.RWMutex
  53. lockDateRange sync.RWMutex
  54. }
  55. // ComputeAllocation calls ComputeAllocationFunc.
  56. func (mock *AllocationModelMock) ComputeAllocation(start time.Time, end time.Time, resolution time.Duration) (*opencost.AllocationSet, error) {
  57. if mock.ComputeAllocationFunc == nil {
  58. panic("AllocationModelMock.ComputeAllocationFunc: method is nil but AllocationModel.ComputeAllocation was just called")
  59. }
  60. callInfo := struct {
  61. Start time.Time
  62. End time.Time
  63. Resolution time.Duration
  64. }{
  65. Start: start,
  66. End: end,
  67. Resolution: resolution,
  68. }
  69. mock.lockComputeAllocation.Lock()
  70. mock.calls.ComputeAllocation = append(mock.calls.ComputeAllocation, callInfo)
  71. mock.lockComputeAllocation.Unlock()
  72. return mock.ComputeAllocationFunc(start, end, resolution)
  73. }
  74. // ComputeAllocationCalls gets all the calls that were made to ComputeAllocation.
  75. // Check the length with:
  76. //
  77. // len(mockedAllocationModel.ComputeAllocationCalls())
  78. func (mock *AllocationModelMock) ComputeAllocationCalls() []struct {
  79. Start time.Time
  80. End time.Time
  81. Resolution time.Duration
  82. } {
  83. var calls []struct {
  84. Start time.Time
  85. End time.Time
  86. Resolution time.Duration
  87. }
  88. mock.lockComputeAllocation.RLock()
  89. calls = mock.calls.ComputeAllocation
  90. mock.lockComputeAllocation.RUnlock()
  91. return calls
  92. }
  93. // DateRange calls DateRangeFunc.
  94. func (mock *AllocationModelMock) DateRange(limitDays int) (time.Time, time.Time, error) {
  95. if mock.DateRangeFunc == nil {
  96. panic("AllocationModelMock.DateRangeFunc: method is nil but AllocationModel.DateRange was just called")
  97. }
  98. callInfo := struct {
  99. LimitDays int
  100. }{
  101. LimitDays: limitDays,
  102. }
  103. mock.lockDateRange.Lock()
  104. mock.calls.DateRange = append(mock.calls.DateRange, callInfo)
  105. mock.lockDateRange.Unlock()
  106. return mock.DateRangeFunc(limitDays)
  107. }
  108. // DateRangeCalls gets all the calls that were made to DateRange.
  109. // Check the length with:
  110. //
  111. // len(mockedAllocationModel.DateRangeCalls())
  112. func (mock *AllocationModelMock) DateRangeCalls() []struct {
  113. LimitDays int
  114. } {
  115. var calls []struct {
  116. LimitDays int
  117. }
  118. mock.lockDateRange.RLock()
  119. calls = mock.calls.DateRange
  120. mock.lockDateRange.RUnlock()
  121. return calls
  122. }