ops_repo_mock_test.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. )
  6. // opsRepoMock is a test-only OpsRepository implementation with optional function hooks.
  7. type opsRepoMock struct {
  8. InsertErrorLogFn func(ctx context.Context, input *OpsInsertErrorLogInput) (int64, error)
  9. BatchInsertErrorLogsFn func(ctx context.Context, inputs []*OpsInsertErrorLogInput) (int64, error)
  10. GetErrorLogByIDFn func(ctx context.Context, id int64) (*OpsErrorLogDetail, error)
  11. BatchInsertSystemLogsFn func(ctx context.Context, inputs []*OpsInsertSystemLogInput) (int64, error)
  12. ListSystemLogsFn func(ctx context.Context, filter *OpsSystemLogFilter) (*OpsSystemLogList, error)
  13. DeleteSystemLogsFn func(ctx context.Context, filter *OpsSystemLogCleanupFilter) (int64, error)
  14. InsertSystemLogCleanupAuditFn func(ctx context.Context, input *OpsSystemLogCleanupAudit) error
  15. }
  16. func (m *opsRepoMock) InsertErrorLog(ctx context.Context, input *OpsInsertErrorLogInput) (int64, error) {
  17. if m.InsertErrorLogFn != nil {
  18. return m.InsertErrorLogFn(ctx, input)
  19. }
  20. return 0, nil
  21. }
  22. func (m *opsRepoMock) BatchInsertErrorLogs(ctx context.Context, inputs []*OpsInsertErrorLogInput) (int64, error) {
  23. if m.BatchInsertErrorLogsFn != nil {
  24. return m.BatchInsertErrorLogsFn(ctx, inputs)
  25. }
  26. return int64(len(inputs)), nil
  27. }
  28. func (m *opsRepoMock) ListErrorLogs(ctx context.Context, filter *OpsErrorLogFilter) (*OpsErrorLogList, error) {
  29. return &OpsErrorLogList{Errors: []*OpsErrorLog{}, Page: 1, PageSize: 20}, nil
  30. }
  31. func (m *opsRepoMock) GetErrorLogByID(ctx context.Context, id int64) (*OpsErrorLogDetail, error) {
  32. if m.GetErrorLogByIDFn != nil {
  33. return m.GetErrorLogByIDFn(ctx, id)
  34. }
  35. return &OpsErrorLogDetail{}, nil
  36. }
  37. func (m *opsRepoMock) ListRequestDetails(ctx context.Context, filter *OpsRequestDetailFilter) ([]*OpsRequestDetail, int64, error) {
  38. return []*OpsRequestDetail{}, 0, nil
  39. }
  40. func (m *opsRepoMock) BatchInsertSystemLogs(ctx context.Context, inputs []*OpsInsertSystemLogInput) (int64, error) {
  41. if m.BatchInsertSystemLogsFn != nil {
  42. return m.BatchInsertSystemLogsFn(ctx, inputs)
  43. }
  44. return int64(len(inputs)), nil
  45. }
  46. func (m *opsRepoMock) ListSystemLogs(ctx context.Context, filter *OpsSystemLogFilter) (*OpsSystemLogList, error) {
  47. if m.ListSystemLogsFn != nil {
  48. return m.ListSystemLogsFn(ctx, filter)
  49. }
  50. return &OpsSystemLogList{Logs: []*OpsSystemLog{}, Total: 0, Page: 1, PageSize: 50}, nil
  51. }
  52. func (m *opsRepoMock) DeleteSystemLogs(ctx context.Context, filter *OpsSystemLogCleanupFilter) (int64, error) {
  53. if m.DeleteSystemLogsFn != nil {
  54. return m.DeleteSystemLogsFn(ctx, filter)
  55. }
  56. return 0, nil
  57. }
  58. func (m *opsRepoMock) InsertSystemLogCleanupAudit(ctx context.Context, input *OpsSystemLogCleanupAudit) error {
  59. if m.InsertSystemLogCleanupAuditFn != nil {
  60. return m.InsertSystemLogCleanupAuditFn(ctx, input)
  61. }
  62. return nil
  63. }
  64. func (m *opsRepoMock) UpdateErrorResolution(ctx context.Context, errorID int64, resolved bool, resolvedByUserID *int64, resolvedAt *time.Time) error {
  65. return nil
  66. }
  67. func (m *opsRepoMock) GetWindowStats(ctx context.Context, filter *OpsDashboardFilter) (*OpsWindowStats, error) {
  68. return &OpsWindowStats{}, nil
  69. }
  70. func (m *opsRepoMock) GetRealtimeTrafficSummary(ctx context.Context, filter *OpsDashboardFilter) (*OpsRealtimeTrafficSummary, error) {
  71. return &OpsRealtimeTrafficSummary{}, nil
  72. }
  73. func (m *opsRepoMock) GetDashboardOverview(ctx context.Context, filter *OpsDashboardFilter) (*OpsDashboardOverview, error) {
  74. return &OpsDashboardOverview{}, nil
  75. }
  76. func (m *opsRepoMock) GetThroughputTrend(ctx context.Context, filter *OpsDashboardFilter, bucketSeconds int) (*OpsThroughputTrendResponse, error) {
  77. return &OpsThroughputTrendResponse{}, nil
  78. }
  79. func (m *opsRepoMock) GetLatencyHistogram(ctx context.Context, filter *OpsDashboardFilter) (*OpsLatencyHistogramResponse, error) {
  80. return &OpsLatencyHistogramResponse{}, nil
  81. }
  82. func (m *opsRepoMock) GetErrorTrend(ctx context.Context, filter *OpsDashboardFilter, bucketSeconds int) (*OpsErrorTrendResponse, error) {
  83. return &OpsErrorTrendResponse{}, nil
  84. }
  85. func (m *opsRepoMock) GetErrorDistribution(ctx context.Context, filter *OpsDashboardFilter) (*OpsErrorDistributionResponse, error) {
  86. return &OpsErrorDistributionResponse{}, nil
  87. }
  88. func (m *opsRepoMock) GetOpenAITokenStats(ctx context.Context, filter *OpsOpenAITokenStatsFilter) (*OpsOpenAITokenStatsResponse, error) {
  89. return &OpsOpenAITokenStatsResponse{}, nil
  90. }
  91. func (m *opsRepoMock) InsertSystemMetrics(ctx context.Context, input *OpsInsertSystemMetricsInput) error {
  92. return nil
  93. }
  94. func (m *opsRepoMock) GetLatestSystemMetrics(ctx context.Context, windowMinutes int) (*OpsSystemMetricsSnapshot, error) {
  95. return &OpsSystemMetricsSnapshot{}, nil
  96. }
  97. func (m *opsRepoMock) UpsertJobHeartbeat(ctx context.Context, input *OpsUpsertJobHeartbeatInput) error {
  98. return nil
  99. }
  100. func (m *opsRepoMock) ListJobHeartbeats(ctx context.Context) ([]*OpsJobHeartbeat, error) {
  101. return []*OpsJobHeartbeat{}, nil
  102. }
  103. func (m *opsRepoMock) ListAlertRules(ctx context.Context) ([]*OpsAlertRule, error) {
  104. return []*OpsAlertRule{}, nil
  105. }
  106. func (m *opsRepoMock) CreateAlertRule(ctx context.Context, input *OpsAlertRule) (*OpsAlertRule, error) {
  107. return input, nil
  108. }
  109. func (m *opsRepoMock) UpdateAlertRule(ctx context.Context, input *OpsAlertRule) (*OpsAlertRule, error) {
  110. return input, nil
  111. }
  112. func (m *opsRepoMock) DeleteAlertRule(ctx context.Context, id int64) error {
  113. return nil
  114. }
  115. func (m *opsRepoMock) ListAlertEvents(ctx context.Context, filter *OpsAlertEventFilter) ([]*OpsAlertEvent, error) {
  116. return []*OpsAlertEvent{}, nil
  117. }
  118. func (m *opsRepoMock) GetAlertEventByID(ctx context.Context, eventID int64) (*OpsAlertEvent, error) {
  119. return &OpsAlertEvent{}, nil
  120. }
  121. func (m *opsRepoMock) GetActiveAlertEvent(ctx context.Context, ruleID int64) (*OpsAlertEvent, error) {
  122. return nil, nil
  123. }
  124. func (m *opsRepoMock) GetLatestAlertEvent(ctx context.Context, ruleID int64) (*OpsAlertEvent, error) {
  125. return nil, nil
  126. }
  127. func (m *opsRepoMock) CreateAlertEvent(ctx context.Context, event *OpsAlertEvent) (*OpsAlertEvent, error) {
  128. return event, nil
  129. }
  130. func (m *opsRepoMock) UpdateAlertEventStatus(ctx context.Context, eventID int64, status string, resolvedAt *time.Time) error {
  131. return nil
  132. }
  133. func (m *opsRepoMock) UpdateAlertEventEmailSent(ctx context.Context, eventID int64, emailSent bool) error {
  134. return nil
  135. }
  136. func (m *opsRepoMock) CreateAlertSilence(ctx context.Context, input *OpsAlertSilence) (*OpsAlertSilence, error) {
  137. return input, nil
  138. }
  139. func (m *opsRepoMock) IsAlertSilenced(ctx context.Context, ruleID int64, platform string, groupID *int64, region *string, now time.Time) (bool, error) {
  140. return false, nil
  141. }
  142. func (m *opsRepoMock) UpsertHourlyMetrics(ctx context.Context, startTime, endTime time.Time) error {
  143. return nil
  144. }
  145. func (m *opsRepoMock) UpsertDailyMetrics(ctx context.Context, startTime, endTime time.Time) error {
  146. return nil
  147. }
  148. func (m *opsRepoMock) GetLatestHourlyBucketStart(ctx context.Context) (time.Time, bool, error) {
  149. return time.Time{}, false, nil
  150. }
  151. func (m *opsRepoMock) GetLatestDailyBucketDate(ctx context.Context) (time.Time, bool, error) {
  152. return time.Time{}, false, nil
  153. }
  154. var _ OpsRepository = (*opsRepoMock)(nil)