moq_allocation_model_test.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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) (*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. }
  44. // DateRange holds details about calls to the DateRange method.
  45. DateRange []struct {
  46. // LimitDays is the limitDays argument value.
  47. LimitDays int
  48. }
  49. }
  50. lockComputeAllocation sync.RWMutex
  51. lockDateRange sync.RWMutex
  52. }
  53. // ComputeAllocation calls ComputeAllocationFunc.
  54. func (mock *AllocationModelMock) ComputeAllocation(start time.Time, end time.Time) (*opencost.AllocationSet, error) {
  55. if mock.ComputeAllocationFunc == nil {
  56. panic("AllocationModelMock.ComputeAllocationFunc: method is nil but AllocationModel.ComputeAllocation was just called")
  57. }
  58. callInfo := struct {
  59. Start time.Time
  60. End time.Time
  61. }{
  62. Start: start,
  63. End: end,
  64. }
  65. mock.lockComputeAllocation.Lock()
  66. mock.calls.ComputeAllocation = append(mock.calls.ComputeAllocation, callInfo)
  67. mock.lockComputeAllocation.Unlock()
  68. return mock.ComputeAllocationFunc(start, end)
  69. }
  70. // ComputeAllocationCalls gets all the calls that were made to ComputeAllocation.
  71. // Check the length with:
  72. //
  73. // len(mockedAllocationModel.ComputeAllocationCalls())
  74. func (mock *AllocationModelMock) ComputeAllocationCalls() []struct {
  75. Start time.Time
  76. End time.Time
  77. } {
  78. var calls []struct {
  79. Start time.Time
  80. End time.Time
  81. }
  82. mock.lockComputeAllocation.RLock()
  83. calls = mock.calls.ComputeAllocation
  84. mock.lockComputeAllocation.RUnlock()
  85. return calls
  86. }
  87. // DateRange calls DateRangeFunc.
  88. func (mock *AllocationModelMock) DateRange(limitDays int) (time.Time, time.Time, error) {
  89. if mock.DateRangeFunc == nil {
  90. panic("AllocationModelMock.DateRangeFunc: method is nil but AllocationModel.DateRange was just called")
  91. }
  92. callInfo := struct {
  93. LimitDays int
  94. }{
  95. LimitDays: limitDays,
  96. }
  97. mock.lockDateRange.Lock()
  98. mock.calls.DateRange = append(mock.calls.DateRange, callInfo)
  99. mock.lockDateRange.Unlock()
  100. return mock.DateRangeFunc(limitDays)
  101. }
  102. // DateRangeCalls gets all the calls that were made to DateRange.
  103. // Check the length with:
  104. //
  105. // len(mockedAllocationModel.DateRangeCalls())
  106. func (mock *AllocationModelMock) DateRangeCalls() []struct {
  107. LimitDays int
  108. } {
  109. var calls []struct {
  110. LimitDays int
  111. }
  112. mock.lockDateRange.RLock()
  113. calls = mock.calls.DateRange
  114. mock.lockDateRange.RUnlock()
  115. return calls
  116. }