From 662ecc4e37efa4b854e382c46f6ab9c319134a04 Mon Sep 17 00:00:00 2001 From: cemeng Date: Sun, 5 Jul 2026 22:11:38 +0800 Subject: [PATCH 1/4] fix: use standard httpbase error response in runner handler and propagate upstream error in remote_runner --- builder/deploy/imagerunner/remote_runner.go | 4 +- runner/handler/service.go | 90 ++++++++++++--------- 2 files changed, 52 insertions(+), 42 deletions(-) diff --git a/builder/deploy/imagerunner/remote_runner.go b/builder/deploy/imagerunner/remote_runner.go index 5083a7725..1bba4c1a7 100644 --- a/builder/deploy/imagerunner/remote_runner.go +++ b/builder/deploy/imagerunner/remote_runner.go @@ -267,8 +267,8 @@ func (h *RemoteRunner) doRequest(ctx context.Context, method, url string, data i return nil, errorx.RemoteSvcFail(err, nil) } slog.WarnContext(ctx, "remote runner response with", slog.Any("StatusCode", resp.StatusCode), slog.Any("result", result)) - err = fmt.Errorf("unexpected http status: %d", resp.StatusCode) - return nil, err + err = fmt.Errorf("unexpected http status: %d, upstream error: %s", resp.StatusCode, result.Msg) + return nil, errorx.RemoteSvcFail(err, nil) } return resp, nil diff --git a/runner/handler/service.go b/runner/handler/service.go index e90b58527..182f5301b 100644 --- a/runner/handler/service.go +++ b/runner/handler/service.go @@ -3,7 +3,7 @@ package handler import ( "database/sql" "errors" - "io" + "fmt" "log/slog" "net/http" @@ -19,7 +19,6 @@ import ( rcommon "opencsg.com/csghub-server/runner/common" "opencsg.com/csghub-server/runner/component" rTypes "opencsg.com/csghub-server/runner/types" - "opencsg.com/csghub-server/runner/utils" ) type K8sHandler struct { @@ -46,15 +45,15 @@ func (s *K8sHandler) RunService(c *gin.Context) { err := c.BindJSON(&request) if err != nil { slog.ErrorContext(c.Request.Context(), "runService get bad request", slog.Any("error", err), slog.Any("req", request)) - c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + httpbase.BadRequest(c, err.Error()) return } svcName := s.getServiceNameFromRequest(c) request.SvcName = svcName err = s.serviceComponent.RunService(c.Request.Context(), *request) if err != nil { - slog.Error("fail to run service", slog.Any("error", err), slog.Any("req", request)) - c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + slog.ErrorContext(c.Request.Context(), "fail to run service", slog.Any("error", err), slog.Any("req", request)) + httpbase.ServerError(c, err) return } slog.Info("service created successfully", slog.String("svc_name", svcName), slog.Int64("deploy_id", request.DeployID)) @@ -67,7 +66,7 @@ func (s *K8sHandler) StopService(c *gin.Context) { if err != nil { slog.ErrorContext(c.Request.Context(), "stop service get bad request", slog.Any("error", err), slog.Any("req", request)) - c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + httpbase.BadRequest(c, err.Error()) return } svcName := s.getServiceNameFromRequest(c) @@ -75,7 +74,7 @@ func (s *K8sHandler) StopService(c *gin.Context) { resp, err := s.serviceComponent.StopService(c.Request.Context(), *request) if err != nil { slog.ErrorContext(c.Request.Context(), "failed to stop service", slog.Any("error", err), slog.Any("req", request)) - c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + httpbase.ServerError(c, err) return } @@ -92,7 +91,7 @@ func (s *K8sHandler) UpdateService(c *gin.Context) { if err != nil { slog.ErrorContext(c.Request.Context(), "updateService get bad request", slog.Any("error", err), slog.Any("req", request)) - c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + httpbase.BadRequest(c, err.Error()) return } svcName := s.getServiceNameFromRequest(c) @@ -100,7 +99,7 @@ func (s *K8sHandler) UpdateService(c *gin.Context) { resp, err := s.serviceComponent.UpdateService(c.Request.Context(), *request) if err != nil { slog.ErrorContext(c.Request.Context(), "failed to update service", slog.Any("error", err), slog.Any("req", request)) - c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + httpbase.ServerError(c, err) return } slog.Info("service updated", slog.String("svc_name", svcName)) @@ -114,7 +113,7 @@ func (s *K8sHandler) ServiceStatus(c *gin.Context) { err := c.BindJSON(request) if err != nil { slog.ErrorContext(c.Request.Context(), "serviceStatus get bad request", slog.Any("error", err), slog.Any("req", request)) - c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + httpbase.BadRequest(c, err.Error()) return } svcName := s.getServiceNameFromRequest(c) @@ -128,7 +127,7 @@ func (s *K8sHandler) ServiceStatus(c *gin.Context) { return } slog.ErrorContext(c.Request.Context(), "failed to get service", slog.Any("error", err), slog.String("svc_name", svcName)) - c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to get service"}) + httpbase.ServerError(c, fmt.Errorf("failed to get service")) return } c.JSON(http.StatusOK, resp) @@ -140,20 +139,20 @@ func (s *K8sHandler) ServiceLogs(c *gin.Context) { if err != nil { slog.ErrorContext(c.Request.Context(), "get bad request", slog.Any("error", err), slog.Any("req", request)) - c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + httpbase.BadRequest(c, err.Error()) return } cluster, err := s.clusterPool.GetClusterByID(c, request.ClusterID) if err != nil { slog.ErrorContext(c.Request.Context(), "fail to get cluster ", slog.Any("error", err)) - c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + httpbase.BadRequest(c, err.Error()) return } svcName := s.getServiceNameFromRequest(c) podNames, err := s.serviceComponent.GetServicePods(c.Request.Context(), cluster, svcName, s.k8sNameSpace, 1) if err != nil { slog.ErrorContext(c.Request.Context(), "failed to read image logs, cannot get pods info", slog.Any("error", err), slog.String("svc_name", svcName)) - c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to get pods info"}) + httpbase.ServerError(c, fmt.Errorf("failed to get pods info")) return } podName := "" @@ -169,13 +168,13 @@ func (s *K8sHandler) ServiceLogsByPod(c *gin.Context) { if err != nil { slog.ErrorContext(c.Request.Context(), "serviceLogs get bad request", slog.Any("error", err), slog.Any("req", request)) - c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + httpbase.BadRequest(c, err.Error()) return } cluster, err := s.clusterPool.GetClusterByID(c, request.ClusterID) if err != nil { slog.ErrorContext(c.Request.Context(), "fail to get cluster ", slog.Any("error", err)) - c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + httpbase.BadRequest(c, err.Error()) return } svcName := s.getServiceNameFromRequest(c) @@ -193,7 +192,7 @@ func (s *K8sHandler) getLogsByPod(c *gin.Context, cluster *cluster.Cluster, podN if err != nil { slog.ErrorContext(c.Request.Context(), "check pod existence", slog.Any("namespace", s.k8sNameSpace), slog.Any("pod-name", podName), slog.Any("clusterID", cluster.ID), slog.Any("error", err)) - c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to check pod existence"}) + httpbase.ServerError(c, fmt.Errorf("failed to check pod existence")) return } } @@ -230,36 +229,47 @@ func (s *K8sHandler) readPodLogsFromDB(c *gin.Context, cluster *cluster.Cluster, func (s *K8sHandler) readPodLogsFromCluster(c *gin.Context, cluster *cluster.Cluster, podName, svcName string) { slog.Debug("read pod logs from cluster", slog.Any("namespace", s.k8sNameSpace), slog.Any("pod-name", podName), slog.Any("svcname", svcName), slog.Any("clusterID", cluster.ID)) - - stream, message, err := rcommon.GetPodLogStream(c.Request.Context(), cluster.Client, podName, s.k8sNameSpace, rTypes.UserContainerName) + ch, message, err := rcommon.GetPodLogStream(c, cluster.Client, podName, s.k8sNameSpace, rTypes.UserContainerName) if err != nil { slog.ErrorContext(c.Request.Context(), "Failed to open stream", slog.Any("error", err)) - c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to open stream"}) + httpbase.ServerError(c, fmt.Errorf("failed to open stream")) return } defer func() { - if stream != nil { - _ = stream.Close() + if ch != nil { + select { + case _, ok := <-ch: + if ok { + close(ch) + } + default: + close(ch) + } } }() - if message != "" { - c.JSON(http.StatusBadRequest, gin.H{"error": message}) - return - } - - // TODO miss web socket - setResponseHeaderForLogs(c) - // Flush the header by calling http.Flusher if supported. - if flusher, ok := c.Writer.(http.Flusher); ok { - flusher.Flush() + if message != "" { + _, err = c.Writer.Write([]byte(message)) + if err != nil { + slog.ErrorContext(c.Request.Context(), "write pod message data failed", slog.Any("svcName", svcName), + slog.Any("namespace", s.k8sNameSpace), slog.Any("pod-name", podName), + slog.Any("clusterID", cluster.ID), slog.Any("error", err)) + } + c.Writer.Flush() + httpbase.BadRequest(c, message) + return } - w := utils.Wrap(c.Writer) - if _, err := io.Copy(w, stream); err != nil { - slog.ErrorContext(c.Request.Context(), "failed to copy stream", slog.Any("error", err)) + for log := range ch { + _, err := c.Writer.Write(log) + if err != nil { + slog.ErrorContext(c.Request.Context(), "write pod log data failed", slog.Any("svcName", svcName), + slog.Any("namespace", s.k8sNameSpace), slog.Any("pod-name", podName), + slog.Any("clusterID", cluster.ID), slog.Any("error", err)) + } + c.Writer.Flush() } } @@ -320,20 +330,20 @@ func (s *K8sHandler) GetReplica(c *gin.Context) { err := c.BindJSON(request) if err != nil { slog.ErrorContext(c.Request.Context(), "fail to parse input parameters", slog.Any("error", err)) - c.JSON(http.StatusInternalServerError, gin.H{"error": "fail to parse input parameters"}) + httpbase.ServerError(c, fmt.Errorf("fail to parse input parameters")) return } svcName := s.getServiceNameFromRequest(c) svc, err := s.serviceComponent.GetServiceByName(c.Request.Context(), svcName, request.ClusterID) if err != nil && !errors.Is(err, sql.ErrNoRows) { slog.ErrorContext(c.Request.Context(), "fail to get service", slog.Any("error", err)) - c.JSON(http.StatusInternalServerError, gin.H{"error": "fail to get service"}) + httpbase.ServerError(c, fmt.Errorf("fail to get service")) return } if svc == nil { // service not exist slog.ErrorContext(c.Request.Context(), "service not exist") - c.JSON(http.StatusNotFound, gin.H{"error": "service not exist"}) + httpbase.NotFoundError(c, fmt.Errorf("service not exist")) return } @@ -400,7 +410,7 @@ func (s *K8sHandler) GetServiceInfo(c *gin.Context) { err := c.BindJSON(request) if err != nil { slog.ErrorContext(c.Request.Context(), "fail to parse input parameters", slog.Any("error", err)) - c.JSON(http.StatusInternalServerError, gin.H{"error": "fail to parse input parameters"}) + httpbase.ServerError(c, fmt.Errorf("fail to parse input parameters")) return } @@ -409,7 +419,7 @@ func (s *K8sHandler) GetServiceInfo(c *gin.Context) { resp, err := s.serviceComponent.GetServiceInfo(c.Request.Context(), *request) if err != nil { slog.ErrorContext(c.Request.Context(), "fail to get service info", slog.Any("error", err)) - c.JSON(http.StatusInternalServerError, gin.H{"error": "fail to get service info"}) + httpbase.ServerError(c, fmt.Errorf("fail to get service info")) return } c.JSON(http.StatusOK, resp) From 88711f24300c1b4bb5710a726c0ce954854f838a Mon Sep 17 00:00:00 2001 From: cemeng Date: Sun, 5 Jul 2026 22:11:38 +0800 Subject: [PATCH 2/4] fix: use standard httpbase error response in runner handler and propagate upstream error in remote_runner --- builder/deploy/imagerunner/remote_runner.go | 4 +- runner/handler/service.go | 90 ++++++++++++--------- 2 files changed, 52 insertions(+), 42 deletions(-) diff --git a/builder/deploy/imagerunner/remote_runner.go b/builder/deploy/imagerunner/remote_runner.go index bddd939b6..e3d433b7f 100644 --- a/builder/deploy/imagerunner/remote_runner.go +++ b/builder/deploy/imagerunner/remote_runner.go @@ -267,8 +267,8 @@ func (h *RemoteRunner) doRequest(ctx context.Context, method, url string, data i return nil, errorx.RemoteSvcFail(err, nil) } slog.WarnContext(ctx, "remote runner response with", slog.Any("StatusCode", resp.StatusCode), slog.Any("result", result)) - err = fmt.Errorf("unexpected http status: %d", resp.StatusCode) - return nil, err + err = fmt.Errorf("unexpected http status: %d, upstream error: %s", resp.StatusCode, result.Msg) + return nil, errorx.RemoteSvcFail(err, nil) } return resp, nil diff --git a/runner/handler/service.go b/runner/handler/service.go index e90b58527..182f5301b 100644 --- a/runner/handler/service.go +++ b/runner/handler/service.go @@ -3,7 +3,7 @@ package handler import ( "database/sql" "errors" - "io" + "fmt" "log/slog" "net/http" @@ -19,7 +19,6 @@ import ( rcommon "opencsg.com/csghub-server/runner/common" "opencsg.com/csghub-server/runner/component" rTypes "opencsg.com/csghub-server/runner/types" - "opencsg.com/csghub-server/runner/utils" ) type K8sHandler struct { @@ -46,15 +45,15 @@ func (s *K8sHandler) RunService(c *gin.Context) { err := c.BindJSON(&request) if err != nil { slog.ErrorContext(c.Request.Context(), "runService get bad request", slog.Any("error", err), slog.Any("req", request)) - c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + httpbase.BadRequest(c, err.Error()) return } svcName := s.getServiceNameFromRequest(c) request.SvcName = svcName err = s.serviceComponent.RunService(c.Request.Context(), *request) if err != nil { - slog.Error("fail to run service", slog.Any("error", err), slog.Any("req", request)) - c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + slog.ErrorContext(c.Request.Context(), "fail to run service", slog.Any("error", err), slog.Any("req", request)) + httpbase.ServerError(c, err) return } slog.Info("service created successfully", slog.String("svc_name", svcName), slog.Int64("deploy_id", request.DeployID)) @@ -67,7 +66,7 @@ func (s *K8sHandler) StopService(c *gin.Context) { if err != nil { slog.ErrorContext(c.Request.Context(), "stop service get bad request", slog.Any("error", err), slog.Any("req", request)) - c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + httpbase.BadRequest(c, err.Error()) return } svcName := s.getServiceNameFromRequest(c) @@ -75,7 +74,7 @@ func (s *K8sHandler) StopService(c *gin.Context) { resp, err := s.serviceComponent.StopService(c.Request.Context(), *request) if err != nil { slog.ErrorContext(c.Request.Context(), "failed to stop service", slog.Any("error", err), slog.Any("req", request)) - c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + httpbase.ServerError(c, err) return } @@ -92,7 +91,7 @@ func (s *K8sHandler) UpdateService(c *gin.Context) { if err != nil { slog.ErrorContext(c.Request.Context(), "updateService get bad request", slog.Any("error", err), slog.Any("req", request)) - c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + httpbase.BadRequest(c, err.Error()) return } svcName := s.getServiceNameFromRequest(c) @@ -100,7 +99,7 @@ func (s *K8sHandler) UpdateService(c *gin.Context) { resp, err := s.serviceComponent.UpdateService(c.Request.Context(), *request) if err != nil { slog.ErrorContext(c.Request.Context(), "failed to update service", slog.Any("error", err), slog.Any("req", request)) - c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + httpbase.ServerError(c, err) return } slog.Info("service updated", slog.String("svc_name", svcName)) @@ -114,7 +113,7 @@ func (s *K8sHandler) ServiceStatus(c *gin.Context) { err := c.BindJSON(request) if err != nil { slog.ErrorContext(c.Request.Context(), "serviceStatus get bad request", slog.Any("error", err), slog.Any("req", request)) - c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + httpbase.BadRequest(c, err.Error()) return } svcName := s.getServiceNameFromRequest(c) @@ -128,7 +127,7 @@ func (s *K8sHandler) ServiceStatus(c *gin.Context) { return } slog.ErrorContext(c.Request.Context(), "failed to get service", slog.Any("error", err), slog.String("svc_name", svcName)) - c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to get service"}) + httpbase.ServerError(c, fmt.Errorf("failed to get service")) return } c.JSON(http.StatusOK, resp) @@ -140,20 +139,20 @@ func (s *K8sHandler) ServiceLogs(c *gin.Context) { if err != nil { slog.ErrorContext(c.Request.Context(), "get bad request", slog.Any("error", err), slog.Any("req", request)) - c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + httpbase.BadRequest(c, err.Error()) return } cluster, err := s.clusterPool.GetClusterByID(c, request.ClusterID) if err != nil { slog.ErrorContext(c.Request.Context(), "fail to get cluster ", slog.Any("error", err)) - c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + httpbase.BadRequest(c, err.Error()) return } svcName := s.getServiceNameFromRequest(c) podNames, err := s.serviceComponent.GetServicePods(c.Request.Context(), cluster, svcName, s.k8sNameSpace, 1) if err != nil { slog.ErrorContext(c.Request.Context(), "failed to read image logs, cannot get pods info", slog.Any("error", err), slog.String("svc_name", svcName)) - c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to get pods info"}) + httpbase.ServerError(c, fmt.Errorf("failed to get pods info")) return } podName := "" @@ -169,13 +168,13 @@ func (s *K8sHandler) ServiceLogsByPod(c *gin.Context) { if err != nil { slog.ErrorContext(c.Request.Context(), "serviceLogs get bad request", slog.Any("error", err), slog.Any("req", request)) - c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + httpbase.BadRequest(c, err.Error()) return } cluster, err := s.clusterPool.GetClusterByID(c, request.ClusterID) if err != nil { slog.ErrorContext(c.Request.Context(), "fail to get cluster ", slog.Any("error", err)) - c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + httpbase.BadRequest(c, err.Error()) return } svcName := s.getServiceNameFromRequest(c) @@ -193,7 +192,7 @@ func (s *K8sHandler) getLogsByPod(c *gin.Context, cluster *cluster.Cluster, podN if err != nil { slog.ErrorContext(c.Request.Context(), "check pod existence", slog.Any("namespace", s.k8sNameSpace), slog.Any("pod-name", podName), slog.Any("clusterID", cluster.ID), slog.Any("error", err)) - c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to check pod existence"}) + httpbase.ServerError(c, fmt.Errorf("failed to check pod existence")) return } } @@ -230,36 +229,47 @@ func (s *K8sHandler) readPodLogsFromDB(c *gin.Context, cluster *cluster.Cluster, func (s *K8sHandler) readPodLogsFromCluster(c *gin.Context, cluster *cluster.Cluster, podName, svcName string) { slog.Debug("read pod logs from cluster", slog.Any("namespace", s.k8sNameSpace), slog.Any("pod-name", podName), slog.Any("svcname", svcName), slog.Any("clusterID", cluster.ID)) - - stream, message, err := rcommon.GetPodLogStream(c.Request.Context(), cluster.Client, podName, s.k8sNameSpace, rTypes.UserContainerName) + ch, message, err := rcommon.GetPodLogStream(c, cluster.Client, podName, s.k8sNameSpace, rTypes.UserContainerName) if err != nil { slog.ErrorContext(c.Request.Context(), "Failed to open stream", slog.Any("error", err)) - c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to open stream"}) + httpbase.ServerError(c, fmt.Errorf("failed to open stream")) return } defer func() { - if stream != nil { - _ = stream.Close() + if ch != nil { + select { + case _, ok := <-ch: + if ok { + close(ch) + } + default: + close(ch) + } } }() - if message != "" { - c.JSON(http.StatusBadRequest, gin.H{"error": message}) - return - } - - // TODO miss web socket - setResponseHeaderForLogs(c) - // Flush the header by calling http.Flusher if supported. - if flusher, ok := c.Writer.(http.Flusher); ok { - flusher.Flush() + if message != "" { + _, err = c.Writer.Write([]byte(message)) + if err != nil { + slog.ErrorContext(c.Request.Context(), "write pod message data failed", slog.Any("svcName", svcName), + slog.Any("namespace", s.k8sNameSpace), slog.Any("pod-name", podName), + slog.Any("clusterID", cluster.ID), slog.Any("error", err)) + } + c.Writer.Flush() + httpbase.BadRequest(c, message) + return } - w := utils.Wrap(c.Writer) - if _, err := io.Copy(w, stream); err != nil { - slog.ErrorContext(c.Request.Context(), "failed to copy stream", slog.Any("error", err)) + for log := range ch { + _, err := c.Writer.Write(log) + if err != nil { + slog.ErrorContext(c.Request.Context(), "write pod log data failed", slog.Any("svcName", svcName), + slog.Any("namespace", s.k8sNameSpace), slog.Any("pod-name", podName), + slog.Any("clusterID", cluster.ID), slog.Any("error", err)) + } + c.Writer.Flush() } } @@ -320,20 +330,20 @@ func (s *K8sHandler) GetReplica(c *gin.Context) { err := c.BindJSON(request) if err != nil { slog.ErrorContext(c.Request.Context(), "fail to parse input parameters", slog.Any("error", err)) - c.JSON(http.StatusInternalServerError, gin.H{"error": "fail to parse input parameters"}) + httpbase.ServerError(c, fmt.Errorf("fail to parse input parameters")) return } svcName := s.getServiceNameFromRequest(c) svc, err := s.serviceComponent.GetServiceByName(c.Request.Context(), svcName, request.ClusterID) if err != nil && !errors.Is(err, sql.ErrNoRows) { slog.ErrorContext(c.Request.Context(), "fail to get service", slog.Any("error", err)) - c.JSON(http.StatusInternalServerError, gin.H{"error": "fail to get service"}) + httpbase.ServerError(c, fmt.Errorf("fail to get service")) return } if svc == nil { // service not exist slog.ErrorContext(c.Request.Context(), "service not exist") - c.JSON(http.StatusNotFound, gin.H{"error": "service not exist"}) + httpbase.NotFoundError(c, fmt.Errorf("service not exist")) return } @@ -400,7 +410,7 @@ func (s *K8sHandler) GetServiceInfo(c *gin.Context) { err := c.BindJSON(request) if err != nil { slog.ErrorContext(c.Request.Context(), "fail to parse input parameters", slog.Any("error", err)) - c.JSON(http.StatusInternalServerError, gin.H{"error": "fail to parse input parameters"}) + httpbase.ServerError(c, fmt.Errorf("fail to parse input parameters")) return } @@ -409,7 +419,7 @@ func (s *K8sHandler) GetServiceInfo(c *gin.Context) { resp, err := s.serviceComponent.GetServiceInfo(c.Request.Context(), *request) if err != nil { slog.ErrorContext(c.Request.Context(), "fail to get service info", slog.Any("error", err)) - c.JSON(http.StatusInternalServerError, gin.H{"error": "fail to get service info"}) + httpbase.ServerError(c, fmt.Errorf("fail to get service info")) return } c.JSON(http.StatusOK, resp) From 3afdecc1943141f2e2c1cf09151409034980cfa9 Mon Sep 17 00:00:00 2001 From: cemeng Date: Tue, 7 Jul 2026 19:42:27 +0800 Subject: [PATCH 3/4] fix lint failed --- .../builder/deploy/mock_Deployer.go | 22 +++++----- runner/handler/service.go | 43 +++++++------------ 2 files changed, 27 insertions(+), 38 deletions(-) diff --git a/_mocks/opencsg.com/csghub-server/builder/deploy/mock_Deployer.go b/_mocks/opencsg.com/csghub-server/builder/deploy/mock_Deployer.go index c77d9e9c9..2d2fe64f8 100644 --- a/_mocks/opencsg.com/csghub-server/builder/deploy/mock_Deployer.go +++ b/_mocks/opencsg.com/csghub-server/builder/deploy/mock_Deployer.go @@ -1584,27 +1584,27 @@ func (_c *MockDeployer_StopBuild_Call) RunAndReturn(run func(context.Context, co } // SubmitClawEvaluation provides a mock function with given fields: ctx, req -func (_m *MockDeployer) SubmitClawEvaluation(ctx context.Context, req types.ClawEvaluationReq) (*types.ArgoWorkFlowRes, error) { +func (_m *MockDeployer) SubmitClawEvaluation(ctx context.Context, req commontypes.ClawEvaluationReq) (*commontypes.ArgoWorkFlowRes, error) { ret := _m.Called(ctx, req) if len(ret) == 0 { panic("no return value specified for SubmitClawEvaluation") } - var r0 *types.ArgoWorkFlowRes + var r0 *commontypes.ArgoWorkFlowRes var r1 error - if rf, ok := ret.Get(0).(func(context.Context, types.ClawEvaluationReq) (*types.ArgoWorkFlowRes, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, commontypes.ClawEvaluationReq) (*commontypes.ArgoWorkFlowRes, error)); ok { return rf(ctx, req) } - if rf, ok := ret.Get(0).(func(context.Context, types.ClawEvaluationReq) *types.ArgoWorkFlowRes); ok { + if rf, ok := ret.Get(0).(func(context.Context, commontypes.ClawEvaluationReq) *commontypes.ArgoWorkFlowRes); ok { r0 = rf(ctx, req) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*types.ArgoWorkFlowRes) + r0 = ret.Get(0).(*commontypes.ArgoWorkFlowRes) } } - if rf, ok := ret.Get(1).(func(context.Context, types.ClawEvaluationReq) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, commontypes.ClawEvaluationReq) error); ok { r1 = rf(ctx, req) } else { r1 = ret.Error(1) @@ -1620,24 +1620,24 @@ type MockDeployer_SubmitClawEvaluation_Call struct { // SubmitClawEvaluation is a helper method to define mock.On call // - ctx context.Context -// - req types.ClawEvaluationReq +// - req commontypes.ClawEvaluationReq func (_e *MockDeployer_Expecter) SubmitClawEvaluation(ctx interface{}, req interface{}) *MockDeployer_SubmitClawEvaluation_Call { return &MockDeployer_SubmitClawEvaluation_Call{Call: _e.mock.On("SubmitClawEvaluation", ctx, req)} } -func (_c *MockDeployer_SubmitClawEvaluation_Call) Run(run func(ctx context.Context, req types.ClawEvaluationReq)) *MockDeployer_SubmitClawEvaluation_Call { +func (_c *MockDeployer_SubmitClawEvaluation_Call) Run(run func(ctx context.Context, req commontypes.ClawEvaluationReq)) *MockDeployer_SubmitClawEvaluation_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(types.ClawEvaluationReq)) + run(args[0].(context.Context), args[1].(commontypes.ClawEvaluationReq)) }) return _c } -func (_c *MockDeployer_SubmitClawEvaluation_Call) Return(_a0 *types.ArgoWorkFlowRes, _a1 error) *MockDeployer_SubmitClawEvaluation_Call { +func (_c *MockDeployer_SubmitClawEvaluation_Call) Return(_a0 *commontypes.ArgoWorkFlowRes, _a1 error) *MockDeployer_SubmitClawEvaluation_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *MockDeployer_SubmitClawEvaluation_Call) RunAndReturn(run func(context.Context, types.ClawEvaluationReq) (*types.ArgoWorkFlowRes, error)) *MockDeployer_SubmitClawEvaluation_Call { +func (_c *MockDeployer_SubmitClawEvaluation_Call) RunAndReturn(run func(context.Context, commontypes.ClawEvaluationReq) (*commontypes.ArgoWorkFlowRes, error)) *MockDeployer_SubmitClawEvaluation_Call { _c.Call.Return(run) return _c } diff --git a/runner/handler/service.go b/runner/handler/service.go index 182f5301b..a9307d66e 100644 --- a/runner/handler/service.go +++ b/runner/handler/service.go @@ -4,6 +4,7 @@ import ( "database/sql" "errors" "fmt" + "io" "log/slog" "net/http" @@ -19,6 +20,7 @@ import ( rcommon "opencsg.com/csghub-server/runner/common" "opencsg.com/csghub-server/runner/component" rTypes "opencsg.com/csghub-server/runner/types" + "opencsg.com/csghub-server/runner/utils" ) type K8sHandler struct { @@ -229,47 +231,34 @@ func (s *K8sHandler) readPodLogsFromDB(c *gin.Context, cluster *cluster.Cluster, func (s *K8sHandler) readPodLogsFromCluster(c *gin.Context, cluster *cluster.Cluster, podName, svcName string) { slog.Debug("read pod logs from cluster", slog.Any("namespace", s.k8sNameSpace), slog.Any("pod-name", podName), slog.Any("svcname", svcName), slog.Any("clusterID", cluster.ID)) - ch, message, err := rcommon.GetPodLogStream(c, cluster.Client, podName, s.k8sNameSpace, rTypes.UserContainerName) + + stream, message, err := rcommon.GetPodLogStream(c.Request.Context(), cluster.Client, podName, s.k8sNameSpace, rTypes.UserContainerName) if err != nil { slog.ErrorContext(c.Request.Context(), "Failed to open stream", slog.Any("error", err)) httpbase.ServerError(c, fmt.Errorf("failed to open stream")) return } defer func() { - if ch != nil { - select { - case _, ok := <-ch: - if ok { - close(ch) - } - default: - close(ch) - } + if stream != nil { + _ = stream.Close() } }() - setResponseHeaderForLogs(c) - if message != "" { - _, err = c.Writer.Write([]byte(message)) - if err != nil { - slog.ErrorContext(c.Request.Context(), "write pod message data failed", slog.Any("svcName", svcName), - slog.Any("namespace", s.k8sNameSpace), slog.Any("pod-name", podName), - slog.Any("clusterID", cluster.ID), slog.Any("error", err)) - } - c.Writer.Flush() httpbase.BadRequest(c, message) return } - for log := range ch { - _, err := c.Writer.Write(log) - if err != nil { - slog.ErrorContext(c.Request.Context(), "write pod log data failed", slog.Any("svcName", svcName), - slog.Any("namespace", s.k8sNameSpace), slog.Any("pod-name", podName), - slog.Any("clusterID", cluster.ID), slog.Any("error", err)) - } - c.Writer.Flush() + setResponseHeaderForLogs(c) + + // Flush the header by calling http.Flusher if supported. + if flusher, ok := c.Writer.(http.Flusher); ok { + flusher.Flush() + } + + w := utils.Wrap(c.Writer) + if _, err := io.Copy(w, stream); err != nil { + slog.ErrorContext(c.Request.Context(), "failed to copy stream", slog.Any("error", err)) } } From 13fe51440bef0891f0defb24fd52c16f3f9f5342 Mon Sep 17 00:00:00 2001 From: cemeng Date: Tue, 7 Jul 2026 20:30:08 +0800 Subject: [PATCH 4/4] remove unuse files --- .../database/mock_AccountInvoiceStore.go | 919 ------------------ 1 file changed, 919 deletions(-) delete mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_AccountInvoiceStore.go diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_AccountInvoiceStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_AccountInvoiceStore.go deleted file mode 100644 index 37f6c2f48..000000000 --- a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_AccountInvoiceStore.go +++ /dev/null @@ -1,919 +0,0 @@ -// Code generated by mockery v2.53.5. DO NOT EDIT. - -package database - -import ( - context "context" - - mock "github.com/stretchr/testify/mock" - database "opencsg.com/csghub-server/builder/store/database" -) - -// MockAccountInvoiceStore is an autogenerated mock type for the AccountInvoiceStore type -type MockAccountInvoiceStore struct { - mock.Mock -} - -type MockAccountInvoiceStore_Expecter struct { - mock *mock.Mock -} - -func (_m *MockAccountInvoiceStore) EXPECT() *MockAccountInvoiceStore_Expecter { - return &MockAccountInvoiceStore_Expecter{mock: &_m.Mock} -} - -// CreateInvoice provides a mock function with given fields: ctx, invoice -func (_m *MockAccountInvoiceStore) CreateInvoice(ctx context.Context, invoice *database.AccountInvoice) error { - ret := _m.Called(ctx, invoice) - - if len(ret) == 0 { - panic("no return value specified for CreateInvoice") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *database.AccountInvoice) error); ok { - r0 = rf(ctx, invoice) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// MockAccountInvoiceStore_CreateInvoice_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateInvoice' -type MockAccountInvoiceStore_CreateInvoice_Call struct { - *mock.Call -} - -// CreateInvoice is a helper method to define mock.On call -// - ctx context.Context -// - invoice *database.AccountInvoice -func (_e *MockAccountInvoiceStore_Expecter) CreateInvoice(ctx interface{}, invoice interface{}) *MockAccountInvoiceStore_CreateInvoice_Call { - return &MockAccountInvoiceStore_CreateInvoice_Call{Call: _e.mock.On("CreateInvoice", ctx, invoice)} -} - -func (_c *MockAccountInvoiceStore_CreateInvoice_Call) Run(run func(ctx context.Context, invoice *database.AccountInvoice)) *MockAccountInvoiceStore_CreateInvoice_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*database.AccountInvoice)) - }) - return _c -} - -func (_c *MockAccountInvoiceStore_CreateInvoice_Call) Return(_a0 error) *MockAccountInvoiceStore_CreateInvoice_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *MockAccountInvoiceStore_CreateInvoice_Call) RunAndReturn(run func(context.Context, *database.AccountInvoice) error) *MockAccountInvoiceStore_CreateInvoice_Call { - _c.Call.Return(run) - return _c -} - -// CreateInvoiceTitle provides a mock function with given fields: ctx, title -func (_m *MockAccountInvoiceStore) CreateInvoiceTitle(ctx context.Context, title *database.AccountInvoiceTitle) error { - ret := _m.Called(ctx, title) - - if len(ret) == 0 { - panic("no return value specified for CreateInvoiceTitle") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *database.AccountInvoiceTitle) error); ok { - r0 = rf(ctx, title) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// MockAccountInvoiceStore_CreateInvoiceTitle_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateInvoiceTitle' -type MockAccountInvoiceStore_CreateInvoiceTitle_Call struct { - *mock.Call -} - -// CreateInvoiceTitle is a helper method to define mock.On call -// - ctx context.Context -// - title *database.AccountInvoiceTitle -func (_e *MockAccountInvoiceStore_Expecter) CreateInvoiceTitle(ctx interface{}, title interface{}) *MockAccountInvoiceStore_CreateInvoiceTitle_Call { - return &MockAccountInvoiceStore_CreateInvoiceTitle_Call{Call: _e.mock.On("CreateInvoiceTitle", ctx, title)} -} - -func (_c *MockAccountInvoiceStore_CreateInvoiceTitle_Call) Run(run func(ctx context.Context, title *database.AccountInvoiceTitle)) *MockAccountInvoiceStore_CreateInvoiceTitle_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*database.AccountInvoiceTitle)) - }) - return _c -} - -func (_c *MockAccountInvoiceStore_CreateInvoiceTitle_Call) Return(_a0 error) *MockAccountInvoiceStore_CreateInvoiceTitle_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *MockAccountInvoiceStore_CreateInvoiceTitle_Call) RunAndReturn(run func(context.Context, *database.AccountInvoiceTitle) error) *MockAccountInvoiceStore_CreateInvoiceTitle_Call { - _c.Call.Return(run) - return _c -} - -// DeleteInvoice provides a mock function with given fields: ctx, id -func (_m *MockAccountInvoiceStore) DeleteInvoice(ctx context.Context, id int64) error { - ret := _m.Called(ctx, id) - - if len(ret) == 0 { - panic("no return value specified for DeleteInvoice") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok { - r0 = rf(ctx, id) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// MockAccountInvoiceStore_DeleteInvoice_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteInvoice' -type MockAccountInvoiceStore_DeleteInvoice_Call struct { - *mock.Call -} - -// DeleteInvoice is a helper method to define mock.On call -// - ctx context.Context -// - id int64 -func (_e *MockAccountInvoiceStore_Expecter) DeleteInvoice(ctx interface{}, id interface{}) *MockAccountInvoiceStore_DeleteInvoice_Call { - return &MockAccountInvoiceStore_DeleteInvoice_Call{Call: _e.mock.On("DeleteInvoice", ctx, id)} -} - -func (_c *MockAccountInvoiceStore_DeleteInvoice_Call) Run(run func(ctx context.Context, id int64)) *MockAccountInvoiceStore_DeleteInvoice_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(int64)) - }) - return _c -} - -func (_c *MockAccountInvoiceStore_DeleteInvoice_Call) Return(_a0 error) *MockAccountInvoiceStore_DeleteInvoice_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *MockAccountInvoiceStore_DeleteInvoice_Call) RunAndReturn(run func(context.Context, int64) error) *MockAccountInvoiceStore_DeleteInvoice_Call { - _c.Call.Return(run) - return _c -} - -// DeleteInvoiceTitle provides a mock function with given fields: ctx, titleID -func (_m *MockAccountInvoiceStore) DeleteInvoiceTitle(ctx context.Context, titleID int64) error { - ret := _m.Called(ctx, titleID) - - if len(ret) == 0 { - panic("no return value specified for DeleteInvoiceTitle") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok { - r0 = rf(ctx, titleID) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// MockAccountInvoiceStore_DeleteInvoiceTitle_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteInvoiceTitle' -type MockAccountInvoiceStore_DeleteInvoiceTitle_Call struct { - *mock.Call -} - -// DeleteInvoiceTitle is a helper method to define mock.On call -// - ctx context.Context -// - titleID int64 -func (_e *MockAccountInvoiceStore_Expecter) DeleteInvoiceTitle(ctx interface{}, titleID interface{}) *MockAccountInvoiceStore_DeleteInvoiceTitle_Call { - return &MockAccountInvoiceStore_DeleteInvoiceTitle_Call{Call: _e.mock.On("DeleteInvoiceTitle", ctx, titleID)} -} - -func (_c *MockAccountInvoiceStore_DeleteInvoiceTitle_Call) Run(run func(ctx context.Context, titleID int64)) *MockAccountInvoiceStore_DeleteInvoiceTitle_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(int64)) - }) - return _c -} - -func (_c *MockAccountInvoiceStore_DeleteInvoiceTitle_Call) Return(_a0 error) *MockAccountInvoiceStore_DeleteInvoiceTitle_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *MockAccountInvoiceStore_DeleteInvoiceTitle_Call) RunAndReturn(run func(context.Context, int64) error) *MockAccountInvoiceStore_DeleteInvoiceTitle_Call { - _c.Call.Return(run) - return _c -} - -// GetBillAmount provides a mock function with given fields: ctx, uid, billMonth -func (_m *MockAccountInvoiceStore) GetBillAmount(ctx context.Context, uid string, billMonth string) (float64, error) { - ret := _m.Called(ctx, uid, billMonth) - - if len(ret) == 0 { - panic("no return value specified for GetBillAmount") - } - - var r0 float64 - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string, string) (float64, error)); ok { - return rf(ctx, uid, billMonth) - } - if rf, ok := ret.Get(0).(func(context.Context, string, string) float64); ok { - r0 = rf(ctx, uid, billMonth) - } else { - r0 = ret.Get(0).(float64) - } - - if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { - r1 = rf(ctx, uid, billMonth) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// MockAccountInvoiceStore_GetBillAmount_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetBillAmount' -type MockAccountInvoiceStore_GetBillAmount_Call struct { - *mock.Call -} - -// GetBillAmount is a helper method to define mock.On call -// - ctx context.Context -// - uid string -// - billMonth string -func (_e *MockAccountInvoiceStore_Expecter) GetBillAmount(ctx interface{}, uid interface{}, billMonth interface{}) *MockAccountInvoiceStore_GetBillAmount_Call { - return &MockAccountInvoiceStore_GetBillAmount_Call{Call: _e.mock.On("GetBillAmount", ctx, uid, billMonth)} -} - -func (_c *MockAccountInvoiceStore_GetBillAmount_Call) Run(run func(ctx context.Context, uid string, billMonth string)) *MockAccountInvoiceStore_GetBillAmount_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(string)) - }) - return _c -} - -func (_c *MockAccountInvoiceStore_GetBillAmount_Call) Return(_a0 float64, _a1 error) *MockAccountInvoiceStore_GetBillAmount_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *MockAccountInvoiceStore_GetBillAmount_Call) RunAndReturn(run func(context.Context, string, string) (float64, error)) *MockAccountInvoiceStore_GetBillAmount_Call { - _c.Call.Return(run) - return _c -} - -// GetBillingSummary provides a mock function with given fields: ctx, params -func (_m *MockAccountInvoiceStore) GetBillingSummary(ctx context.Context, params database.BillingSummaryParams) (*database.BillingSummary, error) { - ret := _m.Called(ctx, params) - - if len(ret) == 0 { - panic("no return value specified for GetBillingSummary") - } - - var r0 *database.BillingSummary - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, database.BillingSummaryParams) (*database.BillingSummary, error)); ok { - return rf(ctx, params) - } - if rf, ok := ret.Get(0).(func(context.Context, database.BillingSummaryParams) *database.BillingSummary); ok { - r0 = rf(ctx, params) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*database.BillingSummary) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, database.BillingSummaryParams) error); ok { - r1 = rf(ctx, params) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// MockAccountInvoiceStore_GetBillingSummary_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetBillingSummary' -type MockAccountInvoiceStore_GetBillingSummary_Call struct { - *mock.Call -} - -// GetBillingSummary is a helper method to define mock.On call -// - ctx context.Context -// - params database.BillingSummaryParams -func (_e *MockAccountInvoiceStore_Expecter) GetBillingSummary(ctx interface{}, params interface{}) *MockAccountInvoiceStore_GetBillingSummary_Call { - return &MockAccountInvoiceStore_GetBillingSummary_Call{Call: _e.mock.On("GetBillingSummary", ctx, params)} -} - -func (_c *MockAccountInvoiceStore_GetBillingSummary_Call) Run(run func(ctx context.Context, params database.BillingSummaryParams)) *MockAccountInvoiceStore_GetBillingSummary_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(database.BillingSummaryParams)) - }) - return _c -} - -func (_c *MockAccountInvoiceStore_GetBillingSummary_Call) Return(_a0 *database.BillingSummary, _a1 error) *MockAccountInvoiceStore_GetBillingSummary_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *MockAccountInvoiceStore_GetBillingSummary_Call) RunAndReturn(run func(context.Context, database.BillingSummaryParams) (*database.BillingSummary, error)) *MockAccountInvoiceStore_GetBillingSummary_Call { - _c.Call.Return(run) - return _c -} - -// GetInvoicableList provides a mock function with given fields: ctx, params -func (_m *MockAccountInvoiceStore) GetInvoicableList(ctx context.Context, params database.PagedRequest) ([]database.Invoicable, int, error) { - ret := _m.Called(ctx, params) - - if len(ret) == 0 { - panic("no return value specified for GetInvoicableList") - } - - var r0 []database.Invoicable - var r1 int - var r2 error - if rf, ok := ret.Get(0).(func(context.Context, database.PagedRequest) ([]database.Invoicable, int, error)); ok { - return rf(ctx, params) - } - if rf, ok := ret.Get(0).(func(context.Context, database.PagedRequest) []database.Invoicable); ok { - r0 = rf(ctx, params) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]database.Invoicable) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, database.PagedRequest) int); ok { - r1 = rf(ctx, params) - } else { - r1 = ret.Get(1).(int) - } - - if rf, ok := ret.Get(2).(func(context.Context, database.PagedRequest) error); ok { - r2 = rf(ctx, params) - } else { - r2 = ret.Error(2) - } - - return r0, r1, r2 -} - -// MockAccountInvoiceStore_GetInvoicableList_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetInvoicableList' -type MockAccountInvoiceStore_GetInvoicableList_Call struct { - *mock.Call -} - -// GetInvoicableList is a helper method to define mock.On call -// - ctx context.Context -// - params database.PagedRequest -func (_e *MockAccountInvoiceStore_Expecter) GetInvoicableList(ctx interface{}, params interface{}) *MockAccountInvoiceStore_GetInvoicableList_Call { - return &MockAccountInvoiceStore_GetInvoicableList_Call{Call: _e.mock.On("GetInvoicableList", ctx, params)} -} - -func (_c *MockAccountInvoiceStore_GetInvoicableList_Call) Run(run func(ctx context.Context, params database.PagedRequest)) *MockAccountInvoiceStore_GetInvoicableList_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(database.PagedRequest)) - }) - return _c -} - -func (_c *MockAccountInvoiceStore_GetInvoicableList_Call) Return(_a0 []database.Invoicable, _a1 int, _a2 error) *MockAccountInvoiceStore_GetInvoicableList_Call { - _c.Call.Return(_a0, _a1, _a2) - return _c -} - -func (_c *MockAccountInvoiceStore_GetInvoicableList_Call) RunAndReturn(run func(context.Context, database.PagedRequest) ([]database.Invoicable, int, error)) *MockAccountInvoiceStore_GetInvoicableList_Call { - _c.Call.Return(run) - return _c -} - -// GetInvoice provides a mock function with given fields: ctx, id -func (_m *MockAccountInvoiceStore) GetInvoice(ctx context.Context, id int64) (*database.AccountInvoice, error) { - ret := _m.Called(ctx, id) - - if len(ret) == 0 { - panic("no return value specified for GetInvoice") - } - - var r0 *database.AccountInvoice - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.AccountInvoice, error)); ok { - return rf(ctx, id) - } - if rf, ok := ret.Get(0).(func(context.Context, int64) *database.AccountInvoice); ok { - r0 = rf(ctx, id) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*database.AccountInvoice) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { - r1 = rf(ctx, id) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// MockAccountInvoiceStore_GetInvoice_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetInvoice' -type MockAccountInvoiceStore_GetInvoice_Call struct { - *mock.Call -} - -// GetInvoice is a helper method to define mock.On call -// - ctx context.Context -// - id int64 -func (_e *MockAccountInvoiceStore_Expecter) GetInvoice(ctx interface{}, id interface{}) *MockAccountInvoiceStore_GetInvoice_Call { - return &MockAccountInvoiceStore_GetInvoice_Call{Call: _e.mock.On("GetInvoice", ctx, id)} -} - -func (_c *MockAccountInvoiceStore_GetInvoice_Call) Run(run func(ctx context.Context, id int64)) *MockAccountInvoiceStore_GetInvoice_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(int64)) - }) - return _c -} - -func (_c *MockAccountInvoiceStore_GetInvoice_Call) Return(_a0 *database.AccountInvoice, _a1 error) *MockAccountInvoiceStore_GetInvoice_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *MockAccountInvoiceStore_GetInvoice_Call) RunAndReturn(run func(context.Context, int64) (*database.AccountInvoice, error)) *MockAccountInvoiceStore_GetInvoice_Call { - _c.Call.Return(run) - return _c -} - -// GetInvoiceByBillCycle provides a mock function with given fields: ctx, billCycle, userUUID -func (_m *MockAccountInvoiceStore) GetInvoiceByBillCycle(ctx context.Context, billCycle string, userUUID string) (*database.AccountInvoice, error) { - ret := _m.Called(ctx, billCycle, userUUID) - - if len(ret) == 0 { - panic("no return value specified for GetInvoiceByBillCycle") - } - - var r0 *database.AccountInvoice - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string, string) (*database.AccountInvoice, error)); ok { - return rf(ctx, billCycle, userUUID) - } - if rf, ok := ret.Get(0).(func(context.Context, string, string) *database.AccountInvoice); ok { - r0 = rf(ctx, billCycle, userUUID) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*database.AccountInvoice) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { - r1 = rf(ctx, billCycle, userUUID) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// MockAccountInvoiceStore_GetInvoiceByBillCycle_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetInvoiceByBillCycle' -type MockAccountInvoiceStore_GetInvoiceByBillCycle_Call struct { - *mock.Call -} - -// GetInvoiceByBillCycle is a helper method to define mock.On call -// - ctx context.Context -// - billCycle string -// - userUUID string -func (_e *MockAccountInvoiceStore_Expecter) GetInvoiceByBillCycle(ctx interface{}, billCycle interface{}, userUUID interface{}) *MockAccountInvoiceStore_GetInvoiceByBillCycle_Call { - return &MockAccountInvoiceStore_GetInvoiceByBillCycle_Call{Call: _e.mock.On("GetInvoiceByBillCycle", ctx, billCycle, userUUID)} -} - -func (_c *MockAccountInvoiceStore_GetInvoiceByBillCycle_Call) Run(run func(ctx context.Context, billCycle string, userUUID string)) *MockAccountInvoiceStore_GetInvoiceByBillCycle_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(string)) - }) - return _c -} - -func (_c *MockAccountInvoiceStore_GetInvoiceByBillCycle_Call) Return(_a0 *database.AccountInvoice, _a1 error) *MockAccountInvoiceStore_GetInvoiceByBillCycle_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *MockAccountInvoiceStore_GetInvoiceByBillCycle_Call) RunAndReturn(run func(context.Context, string, string) (*database.AccountInvoice, error)) *MockAccountInvoiceStore_GetInvoiceByBillCycle_Call { - _c.Call.Return(run) - return _c -} - -// GetInvoiceTitle provides a mock function with given fields: ctx, titleID -func (_m *MockAccountInvoiceStore) GetInvoiceTitle(ctx context.Context, titleID int64) (*database.AccountInvoiceTitle, error) { - ret := _m.Called(ctx, titleID) - - if len(ret) == 0 { - panic("no return value specified for GetInvoiceTitle") - } - - var r0 *database.AccountInvoiceTitle - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.AccountInvoiceTitle, error)); ok { - return rf(ctx, titleID) - } - if rf, ok := ret.Get(0).(func(context.Context, int64) *database.AccountInvoiceTitle); ok { - r0 = rf(ctx, titleID) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*database.AccountInvoiceTitle) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { - r1 = rf(ctx, titleID) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// MockAccountInvoiceStore_GetInvoiceTitle_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetInvoiceTitle' -type MockAccountInvoiceStore_GetInvoiceTitle_Call struct { - *mock.Call -} - -// GetInvoiceTitle is a helper method to define mock.On call -// - ctx context.Context -// - titleID int64 -func (_e *MockAccountInvoiceStore_Expecter) GetInvoiceTitle(ctx interface{}, titleID interface{}) *MockAccountInvoiceStore_GetInvoiceTitle_Call { - return &MockAccountInvoiceStore_GetInvoiceTitle_Call{Call: _e.mock.On("GetInvoiceTitle", ctx, titleID)} -} - -func (_c *MockAccountInvoiceStore_GetInvoiceTitle_Call) Run(run func(ctx context.Context, titleID int64)) *MockAccountInvoiceStore_GetInvoiceTitle_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(int64)) - }) - return _c -} - -func (_c *MockAccountInvoiceStore_GetInvoiceTitle_Call) Return(_a0 *database.AccountInvoiceTitle, _a1 error) *MockAccountInvoiceStore_GetInvoiceTitle_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *MockAccountInvoiceStore_GetInvoiceTitle_Call) RunAndReturn(run func(context.Context, int64) (*database.AccountInvoiceTitle, error)) *MockAccountInvoiceStore_GetInvoiceTitle_Call { - _c.Call.Return(run) - return _c -} - -// GetInvoiceTitleByTaxID provides a mock function with given fields: ctx, userUUID, taxID -func (_m *MockAccountInvoiceStore) GetInvoiceTitleByTaxID(ctx context.Context, userUUID string, taxID string) (*database.AccountInvoiceTitle, error) { - ret := _m.Called(ctx, userUUID, taxID) - - if len(ret) == 0 { - panic("no return value specified for GetInvoiceTitleByTaxID") - } - - var r0 *database.AccountInvoiceTitle - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string, string) (*database.AccountInvoiceTitle, error)); ok { - return rf(ctx, userUUID, taxID) - } - if rf, ok := ret.Get(0).(func(context.Context, string, string) *database.AccountInvoiceTitle); ok { - r0 = rf(ctx, userUUID, taxID) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*database.AccountInvoiceTitle) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { - r1 = rf(ctx, userUUID, taxID) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// MockAccountInvoiceStore_GetInvoiceTitleByTaxID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetInvoiceTitleByTaxID' -type MockAccountInvoiceStore_GetInvoiceTitleByTaxID_Call struct { - *mock.Call -} - -// GetInvoiceTitleByTaxID is a helper method to define mock.On call -// - ctx context.Context -// - userUUID string -// - taxID string -func (_e *MockAccountInvoiceStore_Expecter) GetInvoiceTitleByTaxID(ctx interface{}, userUUID interface{}, taxID interface{}) *MockAccountInvoiceStore_GetInvoiceTitleByTaxID_Call { - return &MockAccountInvoiceStore_GetInvoiceTitleByTaxID_Call{Call: _e.mock.On("GetInvoiceTitleByTaxID", ctx, userUUID, taxID)} -} - -func (_c *MockAccountInvoiceStore_GetInvoiceTitleByTaxID_Call) Run(run func(ctx context.Context, userUUID string, taxID string)) *MockAccountInvoiceStore_GetInvoiceTitleByTaxID_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(string)) - }) - return _c -} - -func (_c *MockAccountInvoiceStore_GetInvoiceTitleByTaxID_Call) Return(_a0 *database.AccountInvoiceTitle, _a1 error) *MockAccountInvoiceStore_GetInvoiceTitleByTaxID_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *MockAccountInvoiceStore_GetInvoiceTitleByTaxID_Call) RunAndReturn(run func(context.Context, string, string) (*database.AccountInvoiceTitle, error)) *MockAccountInvoiceStore_GetInvoiceTitleByTaxID_Call { - _c.Call.Return(run) - return _c -} - -// ListInvoiceTitles provides a mock function with given fields: ctx, params -func (_m *MockAccountInvoiceStore) ListInvoiceTitles(ctx context.Context, params database.InvoiceListParams) ([]database.AccountInvoiceTitle, int, error) { - ret := _m.Called(ctx, params) - - if len(ret) == 0 { - panic("no return value specified for ListInvoiceTitles") - } - - var r0 []database.AccountInvoiceTitle - var r1 int - var r2 error - if rf, ok := ret.Get(0).(func(context.Context, database.InvoiceListParams) ([]database.AccountInvoiceTitle, int, error)); ok { - return rf(ctx, params) - } - if rf, ok := ret.Get(0).(func(context.Context, database.InvoiceListParams) []database.AccountInvoiceTitle); ok { - r0 = rf(ctx, params) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]database.AccountInvoiceTitle) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, database.InvoiceListParams) int); ok { - r1 = rf(ctx, params) - } else { - r1 = ret.Get(1).(int) - } - - if rf, ok := ret.Get(2).(func(context.Context, database.InvoiceListParams) error); ok { - r2 = rf(ctx, params) - } else { - r2 = ret.Error(2) - } - - return r0, r1, r2 -} - -// MockAccountInvoiceStore_ListInvoiceTitles_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListInvoiceTitles' -type MockAccountInvoiceStore_ListInvoiceTitles_Call struct { - *mock.Call -} - -// ListInvoiceTitles is a helper method to define mock.On call -// - ctx context.Context -// - params database.InvoiceListParams -func (_e *MockAccountInvoiceStore_Expecter) ListInvoiceTitles(ctx interface{}, params interface{}) *MockAccountInvoiceStore_ListInvoiceTitles_Call { - return &MockAccountInvoiceStore_ListInvoiceTitles_Call{Call: _e.mock.On("ListInvoiceTitles", ctx, params)} -} - -func (_c *MockAccountInvoiceStore_ListInvoiceTitles_Call) Run(run func(ctx context.Context, params database.InvoiceListParams)) *MockAccountInvoiceStore_ListInvoiceTitles_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(database.InvoiceListParams)) - }) - return _c -} - -func (_c *MockAccountInvoiceStore_ListInvoiceTitles_Call) Return(_a0 []database.AccountInvoiceTitle, _a1 int, _a2 error) *MockAccountInvoiceStore_ListInvoiceTitles_Call { - _c.Call.Return(_a0, _a1, _a2) - return _c -} - -func (_c *MockAccountInvoiceStore_ListInvoiceTitles_Call) RunAndReturn(run func(context.Context, database.InvoiceListParams) ([]database.AccountInvoiceTitle, int, error)) *MockAccountInvoiceStore_ListInvoiceTitles_Call { - _c.Call.Return(run) - return _c -} - -// ListInvoices provides a mock function with given fields: ctx, params -func (_m *MockAccountInvoiceStore) ListInvoices(ctx context.Context, params database.InvoiceListParams) ([]database.AccountInvoice, int, error) { - ret := _m.Called(ctx, params) - - if len(ret) == 0 { - panic("no return value specified for ListInvoices") - } - - var r0 []database.AccountInvoice - var r1 int - var r2 error - if rf, ok := ret.Get(0).(func(context.Context, database.InvoiceListParams) ([]database.AccountInvoice, int, error)); ok { - return rf(ctx, params) - } - if rf, ok := ret.Get(0).(func(context.Context, database.InvoiceListParams) []database.AccountInvoice); ok { - r0 = rf(ctx, params) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]database.AccountInvoice) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, database.InvoiceListParams) int); ok { - r1 = rf(ctx, params) - } else { - r1 = ret.Get(1).(int) - } - - if rf, ok := ret.Get(2).(func(context.Context, database.InvoiceListParams) error); ok { - r2 = rf(ctx, params) - } else { - r2 = ret.Error(2) - } - - return r0, r1, r2 -} - -// MockAccountInvoiceStore_ListInvoices_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListInvoices' -type MockAccountInvoiceStore_ListInvoices_Call struct { - *mock.Call -} - -// ListInvoices is a helper method to define mock.On call -// - ctx context.Context -// - params database.InvoiceListParams -func (_e *MockAccountInvoiceStore_Expecter) ListInvoices(ctx interface{}, params interface{}) *MockAccountInvoiceStore_ListInvoices_Call { - return &MockAccountInvoiceStore_ListInvoices_Call{Call: _e.mock.On("ListInvoices", ctx, params)} -} - -func (_c *MockAccountInvoiceStore_ListInvoices_Call) Run(run func(ctx context.Context, params database.InvoiceListParams)) *MockAccountInvoiceStore_ListInvoices_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(database.InvoiceListParams)) - }) - return _c -} - -func (_c *MockAccountInvoiceStore_ListInvoices_Call) Return(_a0 []database.AccountInvoice, _a1 int, _a2 error) *MockAccountInvoiceStore_ListInvoices_Call { - _c.Call.Return(_a0, _a1, _a2) - return _c -} - -func (_c *MockAccountInvoiceStore_ListInvoices_Call) RunAndReturn(run func(context.Context, database.InvoiceListParams) ([]database.AccountInvoice, int, error)) *MockAccountInvoiceStore_ListInvoices_Call { - _c.Call.Return(run) - return _c -} - -// UpdateInvoice provides a mock function with given fields: ctx, invoice -func (_m *MockAccountInvoiceStore) UpdateInvoice(ctx context.Context, invoice *database.AccountInvoice) error { - ret := _m.Called(ctx, invoice) - - if len(ret) == 0 { - panic("no return value specified for UpdateInvoice") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *database.AccountInvoice) error); ok { - r0 = rf(ctx, invoice) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// MockAccountInvoiceStore_UpdateInvoice_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateInvoice' -type MockAccountInvoiceStore_UpdateInvoice_Call struct { - *mock.Call -} - -// UpdateInvoice is a helper method to define mock.On call -// - ctx context.Context -// - invoice *database.AccountInvoice -func (_e *MockAccountInvoiceStore_Expecter) UpdateInvoice(ctx interface{}, invoice interface{}) *MockAccountInvoiceStore_UpdateInvoice_Call { - return &MockAccountInvoiceStore_UpdateInvoice_Call{Call: _e.mock.On("UpdateInvoice", ctx, invoice)} -} - -func (_c *MockAccountInvoiceStore_UpdateInvoice_Call) Run(run func(ctx context.Context, invoice *database.AccountInvoice)) *MockAccountInvoiceStore_UpdateInvoice_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*database.AccountInvoice)) - }) - return _c -} - -func (_c *MockAccountInvoiceStore_UpdateInvoice_Call) Return(_a0 error) *MockAccountInvoiceStore_UpdateInvoice_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *MockAccountInvoiceStore_UpdateInvoice_Call) RunAndReturn(run func(context.Context, *database.AccountInvoice) error) *MockAccountInvoiceStore_UpdateInvoice_Call { - _c.Call.Return(run) - return _c -} - -// UpdateInvoiceTitle provides a mock function with given fields: ctx, title -func (_m *MockAccountInvoiceStore) UpdateInvoiceTitle(ctx context.Context, title *database.AccountInvoiceTitle) error { - ret := _m.Called(ctx, title) - - if len(ret) == 0 { - panic("no return value specified for UpdateInvoiceTitle") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *database.AccountInvoiceTitle) error); ok { - r0 = rf(ctx, title) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// MockAccountInvoiceStore_UpdateInvoiceTitle_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateInvoiceTitle' -type MockAccountInvoiceStore_UpdateInvoiceTitle_Call struct { - *mock.Call -} - -// UpdateInvoiceTitle is a helper method to define mock.On call -// - ctx context.Context -// - title *database.AccountInvoiceTitle -func (_e *MockAccountInvoiceStore_Expecter) UpdateInvoiceTitle(ctx interface{}, title interface{}) *MockAccountInvoiceStore_UpdateInvoiceTitle_Call { - return &MockAccountInvoiceStore_UpdateInvoiceTitle_Call{Call: _e.mock.On("UpdateInvoiceTitle", ctx, title)} -} - -func (_c *MockAccountInvoiceStore_UpdateInvoiceTitle_Call) Run(run func(ctx context.Context, title *database.AccountInvoiceTitle)) *MockAccountInvoiceStore_UpdateInvoiceTitle_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*database.AccountInvoiceTitle)) - }) - return _c -} - -func (_c *MockAccountInvoiceStore_UpdateInvoiceTitle_Call) Return(_a0 error) *MockAccountInvoiceStore_UpdateInvoiceTitle_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *MockAccountInvoiceStore_UpdateInvoiceTitle_Call) RunAndReturn(run func(context.Context, *database.AccountInvoiceTitle) error) *MockAccountInvoiceStore_UpdateInvoiceTitle_Call { - _c.Call.Return(run) - return _c -} - -// UpdateInvoiceTitleNotDefault provides a mock function with given fields: ctx, uid -func (_m *MockAccountInvoiceStore) UpdateInvoiceTitleNotDefault(ctx context.Context, uid string) error { - ret := _m.Called(ctx, uid) - - if len(ret) == 0 { - panic("no return value specified for UpdateInvoiceTitleNotDefault") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { - r0 = rf(ctx, uid) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// MockAccountInvoiceStore_UpdateInvoiceTitleNotDefault_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateInvoiceTitleNotDefault' -type MockAccountInvoiceStore_UpdateInvoiceTitleNotDefault_Call struct { - *mock.Call -} - -// UpdateInvoiceTitleNotDefault is a helper method to define mock.On call -// - ctx context.Context -// - uid string -func (_e *MockAccountInvoiceStore_Expecter) UpdateInvoiceTitleNotDefault(ctx interface{}, uid interface{}) *MockAccountInvoiceStore_UpdateInvoiceTitleNotDefault_Call { - return &MockAccountInvoiceStore_UpdateInvoiceTitleNotDefault_Call{Call: _e.mock.On("UpdateInvoiceTitleNotDefault", ctx, uid)} -} - -func (_c *MockAccountInvoiceStore_UpdateInvoiceTitleNotDefault_Call) Run(run func(ctx context.Context, uid string)) *MockAccountInvoiceStore_UpdateInvoiceTitleNotDefault_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string)) - }) - return _c -} - -func (_c *MockAccountInvoiceStore_UpdateInvoiceTitleNotDefault_Call) Return(_a0 error) *MockAccountInvoiceStore_UpdateInvoiceTitleNotDefault_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *MockAccountInvoiceStore_UpdateInvoiceTitleNotDefault_Call) RunAndReturn(run func(context.Context, string) error) *MockAccountInvoiceStore_UpdateInvoiceTitleNotDefault_Call { - _c.Call.Return(run) - return _c -} - -// NewMockAccountInvoiceStore creates a new instance of MockAccountInvoiceStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewMockAccountInvoiceStore(t interface { - mock.TestingT - Cleanup(func()) -}) *MockAccountInvoiceStore { - mock := &MockAccountInvoiceStore{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -}