From 6e380bef20f4979f49e6b038aecc3acbe634e27a Mon Sep 17 00:00:00 2001 From: Ash-exp Date: Sat, 9 Nov 2024 23:30:27 +0530 Subject: [PATCH 1/7] chore: refactoring image tagging reader service --- Wire.go | 3 +- .../configure/BuildPipelineRestHandler.go | 8 +- .../DeploymentPipelineRestHandler.go | 6 +- .../configure/PipelineConfigRestHandler.go | 7 +- cmd/external-app/wire_gen.go | 2 +- .../read/ImageTaggingReadService.go | 55 ++++++++++++ .../imageTagging/wire_image_tagging.go | 11 +++ .../cdPipeline/DeploymentHistoryService.go | 6 +- pkg/pipeline/ImageTaggingService.go | 84 ++++++++----------- wire_gen.go | 10 ++- 10 files changed, 127 insertions(+), 65 deletions(-) create mode 100644 pkg/build/artifacts/imageTagging/read/ImageTaggingReadService.go create mode 100644 pkg/build/artifacts/imageTagging/wire_image_tagging.go diff --git a/Wire.go b/Wire.go index 6e88871c2d4..a830e46d24d 100644 --- a/Wire.go +++ b/Wire.go @@ -122,6 +122,7 @@ import ( "github.com/devtron-labs/devtron/pkg/asyncProvider" "github.com/devtron-labs/devtron/pkg/attributes" "github.com/devtron-labs/devtron/pkg/build" + "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging" "github.com/devtron-labs/devtron/pkg/bulkAction" "github.com/devtron-labs/devtron/pkg/chart" "github.com/devtron-labs/devtron/pkg/chart/gitOpsConfig" @@ -207,7 +208,7 @@ func InitializeApp() (*App, error) { fluxApplication.FluxApplicationWireSet, eventProcessor.EventProcessorWireSet, workflow3.WorkflowWireSet, - + imageTagging.WireSet, devtronResource.DevtronResourceWireSet, // -------wireset end ---------- diff --git a/api/restHandler/app/pipeline/configure/BuildPipelineRestHandler.go b/api/restHandler/app/pipeline/configure/BuildPipelineRestHandler.go index 0a1115a44c0..dd4fa743582 100644 --- a/api/restHandler/app/pipeline/configure/BuildPipelineRestHandler.go +++ b/api/restHandler/app/pipeline/configure/BuildPipelineRestHandler.go @@ -1109,7 +1109,7 @@ func (handler *PipelineConfigRestHandlerImpl) GetBuildHistory(w http.ResponseWri common.WriteJsonResp(w, err, resp, http.StatusInternalServerError) return } - appTags, err := handler.imageTaggingService.GetUniqueTagsByAppId(ciPipeline.AppId) + appTags, err := handler.imageTaggingReadService.GetUniqueTagsByAppId(ciPipeline.AppId) if err != nil { handler.Logger.Errorw("service err, GetTagsByAppId", "err", err, "appId", ciPipeline.AppId) common.WriteJsonResp(w, err, resp, http.StatusInternalServerError) @@ -2071,11 +2071,11 @@ func (handler *PipelineConfigRestHandlerImpl) CreateUpdateImageTagging(w http.Re return } req.ExternalCi = externalCi - //pass it to service layer + // pass it to the service layer resp, err := handler.imageTaggingService.CreateOrUpdateImageTagging(ciPipelineId, appId, artifactId, int(userId), req) if err != nil { if err.Error() == pipeline.DuplicateTagsInAppError { - appReleaseTags, err1 := handler.imageTaggingService.GetUniqueTagsByAppId(appId) + appReleaseTags, err1 := handler.imageTaggingReadService.GetUniqueTagsByAppId(appId) if err1 != nil { handler.Logger.Errorw("error occurred in getting unique tags in app", "err", err1, "appId", appId) err = err1 @@ -2111,7 +2111,7 @@ func (handler *PipelineConfigRestHandlerImpl) GetImageTaggingData(w http.Respons externalCi, ciPipelineId, appId, err := handler.extractCipipelineMetaForImageTags(artifactId) if err != nil { - handler.Logger.Errorw("error occurred in fetching extractCipipelineMetaForImageTags by artifact Id ", "err", err, "artifactId", artifactId) + handler.Logger.Errorw("error occurred in fetching extract ci pipeline metadata for ImageTags by artifact id", "err", err, "artifactId", artifactId) common.WriteJsonResp(w, err, "Unauthorized User", http.StatusInternalServerError) return } diff --git a/api/restHandler/app/pipeline/configure/DeploymentPipelineRestHandler.go b/api/restHandler/app/pipeline/configure/DeploymentPipelineRestHandler.go index c25ede47b05..dccce66db32 100644 --- a/api/restHandler/app/pipeline/configure/DeploymentPipelineRestHandler.go +++ b/api/restHandler/app/pipeline/configure/DeploymentPipelineRestHandler.go @@ -1353,7 +1353,7 @@ func (handler *PipelineConfigRestHandlerImpl) GetArtifactsByCDPipeline(w http.Re return } - appTags, err := handler.imageTaggingService.GetUniqueTagsByAppId(pipeline.AppId) + appTags, err := handler.imageTaggingReadService.GetUniqueTagsByAppId(pipeline.AppId) if err != nil { handler.Logger.Errorw("service err, GetTagsByAppId", "err", err, "appId", pipeline.AppId) common.WriteJsonResp(w, err, ciArtifactResponse, http.StatusInternalServerError) @@ -1597,7 +1597,7 @@ func (handler *PipelineConfigRestHandlerImpl) GetArtifactsForRollback(w http.Res common.WriteJsonResp(w, err, "unable to fetch artifacts", http.StatusInternalServerError) return } - appTags, err := handler.imageTaggingService.GetUniqueTagsByAppId(app.Id) + appTags, err := handler.imageTaggingReadService.GetUniqueTagsByAppId(app.Id) if err != nil { handler.Logger.Errorw("service err, GetTagsByAppId", "err", err, "appId", app.Id) common.WriteJsonResp(w, err, ciArtifactResponse, http.StatusInternalServerError) @@ -1723,7 +1723,7 @@ func (handler *PipelineConfigRestHandlerImpl) ListDeploymentHistory(w http.Respo return } - appTags, err := handler.imageTaggingService.GetUniqueTagsByAppId(appId) + appTags, err := handler.imageTaggingReadService.GetUniqueTagsByAppId(appId) if err != nil { handler.Logger.Errorw("service err, GetTagsByAppId", "err", err, "appId", appId) common.WriteJsonResp(w, err, resp, http.StatusInternalServerError) diff --git a/api/restHandler/app/pipeline/configure/PipelineConfigRestHandler.go b/api/restHandler/app/pipeline/configure/PipelineConfigRestHandler.go index c0a5b804cc4..563f22402e0 100644 --- a/api/restHandler/app/pipeline/configure/PipelineConfigRestHandler.go +++ b/api/restHandler/app/pipeline/configure/PipelineConfigRestHandler.go @@ -21,6 +21,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging/read" "github.com/devtron-labs/devtron/pkg/chart/gitOpsConfig" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deployedAppMetrics" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate" @@ -122,6 +123,7 @@ type PipelineConfigRestHandlerImpl struct { scanResultRepository security.ImageScanResultRepository gitProviderRepo repository.GitProviderRepository argoUserService argo.ArgoUserService + imageTaggingReadService read.ImageTaggingReadService imageTaggingService pipeline.ImageTaggingService deploymentTemplateService generateManifest.DeploymentTemplateService pipelineRestHandlerEnvConfig *PipelineRestHandlerEnvConfig @@ -142,7 +144,8 @@ func NewPipelineRestHandlerImpl(pipelineBuilder pipeline.PipelineBuilder, Logger ciHandler pipeline.CiHandler, validator *validator.Validate, gitSensorClient gitSensor.Client, - ciPipelineRepository pipelineConfig.CiPipelineRepository, pipelineRepository pipelineConfig.PipelineRepository, + ciPipelineRepository pipelineConfig.CiPipelineRepository, + pipelineRepository pipelineConfig.PipelineRepository, enforcerUtil rbac.EnforcerUtil, dockerRegistryConfig pipeline.DockerRegistryConfig, cdHandler pipeline.CdHandler, @@ -152,6 +155,7 @@ func NewPipelineRestHandlerImpl(pipelineBuilder pipeline.PipelineBuilder, Logger materialRepository pipelineConfig.MaterialRepository, policyService security2.PolicyService, scanResultRepository security.ImageScanResultRepository, gitProviderRepo repository.GitProviderRepository, argoUserService argo.ArgoUserService, ciPipelineMaterialRepository pipelineConfig.CiPipelineMaterialRepository, + imageTaggingReadService read.ImageTaggingReadService, imageTaggingService pipeline.ImageTaggingService, ciArtifactRepository repository.CiArtifactRepository, deployedAppMetricsService deployedAppMetrics.DeployedAppMetricsService, @@ -188,6 +192,7 @@ func NewPipelineRestHandlerImpl(pipelineBuilder pipeline.PipelineBuilder, Logger gitProviderRepo: gitProviderRepo, argoUserService: argoUserService, ciPipelineMaterialRepository: ciPipelineMaterialRepository, + imageTaggingReadService: imageTaggingReadService, imageTaggingService: imageTaggingService, deploymentTemplateService: deploymentTemplateService, pipelineRestHandlerEnvConfig: envConfig, diff --git a/cmd/external-app/wire_gen.go b/cmd/external-app/wire_gen.go index 2c4e5a32b02..dbad98bb6ab 100644 --- a/cmd/external-app/wire_gen.go +++ b/cmd/external-app/wire_gen.go @@ -1,6 +1,6 @@ // Code generated by Wire. DO NOT EDIT. -//go:generate go run -mod=mod github.com/google/wire/cmd/wire +//go:generate go run github.com/google/wire/cmd/wire //go:build !wireinject // +build !wireinject diff --git a/pkg/build/artifacts/imageTagging/read/ImageTaggingReadService.go b/pkg/build/artifacts/imageTagging/read/ImageTaggingReadService.go new file mode 100644 index 00000000000..8b18740f25a --- /dev/null +++ b/pkg/build/artifacts/imageTagging/read/ImageTaggingReadService.go @@ -0,0 +1,55 @@ +package read + +import ( + "errors" + repository "github.com/devtron-labs/devtron/internal/sql/repository/imageTagging" + "github.com/go-pg/pg" + "go.uber.org/zap" +) + +type ImageTaggingReadService interface { + // GetTagNamesByArtifactId gets all the tag names for the given artifactId + GetTagNamesByArtifactId(artifactId int) ([]string, error) + // GetUniqueTagsByAppId gets all the unique tag names for the given appId + GetUniqueTagsByAppId(appId int) ([]string, error) +} + +type ImageTaggingReadServiceImpl struct { + logger *zap.SugaredLogger + imageTaggingRepo repository.ImageTaggingRepository +} + +func NewImageTaggingReadServiceImpl( + imageTaggingRepo repository.ImageTaggingRepository, + logger *zap.SugaredLogger) *ImageTaggingReadServiceImpl { + return &ImageTaggingReadServiceImpl{ + logger: logger, + imageTaggingRepo: imageTaggingRepo, + } +} + +func (impl *ImageTaggingReadServiceImpl) GetTagNamesByArtifactId(artifactId int) ([]string, error) { + imageReleaseTags, err := impl.imageTaggingRepo.GetTagsByArtifactId(artifactId) + if err != nil && !errors.Is(err, pg.ErrNoRows) { + impl.logger.Errorw("error in fetching image tags using artifactId", "err", err, "artifactId", artifactId) + return nil, err + } + imageLabels := make([]string, 0, len(imageReleaseTags)) + for _, imageTag := range imageReleaseTags { + imageLabels = append(imageLabels, imageTag.TagName) + } + return imageLabels, nil +} + +func (impl *ImageTaggingReadServiceImpl) GetUniqueTagsByAppId(appId int) ([]string, error) { + imageTags, err := impl.imageTaggingRepo.GetTagsByAppId(appId) + if err != nil { + impl.logger.Errorw("error in fetching image tags using appId", "err", err, "appId", appId) + return nil, err + } + uniqueTags := make([]string, len(imageTags)) + for i, tag := range imageTags { + uniqueTags[i] = tag.TagName + } + return uniqueTags, nil +} diff --git a/pkg/build/artifacts/imageTagging/wire_image_tagging.go b/pkg/build/artifacts/imageTagging/wire_image_tagging.go new file mode 100644 index 00000000000..f99a29594e5 --- /dev/null +++ b/pkg/build/artifacts/imageTagging/wire_image_tagging.go @@ -0,0 +1,11 @@ +package imageTagging + +import ( + "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging/read" + "github.com/google/wire" +) + +var WireSet = wire.NewSet( + read.NewImageTaggingReadServiceImpl, + wire.Bind(new(read.ImageTaggingReadService), new(*read.ImageTaggingReadServiceImpl)), +) diff --git a/pkg/devtronResource/history/deployment/cdPipeline/DeploymentHistoryService.go b/pkg/devtronResource/history/deployment/cdPipeline/DeploymentHistoryService.go index 31090d42b8a..04ba9bc8416 100644 --- a/pkg/devtronResource/history/deployment/cdPipeline/DeploymentHistoryService.go +++ b/pkg/devtronResource/history/deployment/cdPipeline/DeploymentHistoryService.go @@ -2,6 +2,7 @@ package cdPipeline import ( "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" + "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging/read" historyBean "github.com/devtron-labs/devtron/pkg/devtronResource/bean/history" "github.com/devtron-labs/devtron/pkg/pipeline" "github.com/devtron-labs/devtron/pkg/pipeline/bean" @@ -17,6 +18,7 @@ type DeploymentHistoryService interface { type DeploymentHistoryServiceImpl struct { logger *zap.SugaredLogger cdHandler pipeline.CdHandler + imageTaggingReadService read.ImageTaggingReadService imageTaggingService pipeline.ImageTaggingService pipelineRepository pipelineConfig.PipelineRepository deployedConfigurationHistoryService history.DeployedConfigurationHistoryService @@ -24,12 +26,14 @@ type DeploymentHistoryServiceImpl struct { func NewDeploymentHistoryServiceImpl(logger *zap.SugaredLogger, cdHandler pipeline.CdHandler, + imageTaggingReadService read.ImageTaggingReadService, imageTaggingService pipeline.ImageTaggingService, pipelineRepository pipelineConfig.PipelineRepository, deployedConfigurationHistoryService history.DeployedConfigurationHistoryService) *DeploymentHistoryServiceImpl { return &DeploymentHistoryServiceImpl{ logger: logger, cdHandler: cdHandler, + imageTaggingReadService: imageTaggingReadService, imageTaggingService: imageTaggingService, pipelineRepository: pipelineRepository, deployedConfigurationHistoryService: deployedConfigurationHistoryService, @@ -45,7 +49,7 @@ func (impl *DeploymentHistoryServiceImpl) GetCdPipelineDeploymentHistory(req *hi } resp.CdWorkflows = wfs - appTags, err := impl.imageTaggingService.GetUniqueTagsByAppId(req.AppId) + appTags, err := impl.imageTaggingReadService.GetUniqueTagsByAppId(req.AppId) if err != nil { impl.logger.Errorw("service err, GetTagsByAppId", "err", err, "appId", req.AppId) return resp, err diff --git a/pkg/pipeline/ImageTaggingService.go b/pkg/pipeline/ImageTaggingService.go index f44bba85c65..d45413795b0 100644 --- a/pkg/pipeline/ImageTaggingService.go +++ b/pkg/pipeline/ImageTaggingService.go @@ -22,6 +22,7 @@ import ( "github.com/caarlos0/env" repository "github.com/devtron-labs/devtron/internal/sql/repository/imageTagging" "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" + "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging/read" repository2 "github.com/devtron-labs/devtron/pkg/cluster/repository" "github.com/devtron-labs/devtron/pkg/pipeline/types" "github.com/go-pg/pg" @@ -50,27 +51,26 @@ type ImageTaggingService interface { GetProdEnvByCdPipelineId(pipelineId int) (bool, error) // ValidateImageTaggingRequest validates the requested payload ValidateImageTaggingRequest(imageTaggingRequest *types.ImageTaggingRequestDTO, appId, artifactId int) (bool, error) - GetTagNamesByArtifactId(artifactId int) ([]string, error) // GetTagsDataMapByAppId this will fetch a map of artifact vs []tags for given appId GetTagsDataMapByAppId(appId int) (map[int][]*repository.ImageTag, error) // GetImageCommentsDataMapByArtifactIds this will fetch a map of artifact vs imageComment for given artifactIds GetImageCommentsDataMapByArtifactIds(artifactIds []int) (map[int]*repository.ImageComment, error) - // GetUniqueTagsByAppId gets all the unique tag names for the given appId - GetUniqueTagsByAppId(appId int) ([]string, error) GetImageTaggingServiceConfig() ImageTaggingServiceConfig FindProdEnvExists(externalCi bool, pipelineIds []int) (bool, error) } type ImageTaggingServiceImpl struct { imageTaggingRepo repository.ImageTaggingRepository - ciPipelineRepository pipelineConfig.CiPipelineRepository - cdPipelineRepository pipelineConfig.PipelineRepository - environmentRepository repository2.EnvironmentRepository + imageTaggingReadService read.ImageTaggingReadService + ciPipelineRepository pipelineConfig.CiPipelineRepository // TODO: remove this dependency; use read service + cdPipelineRepository pipelineConfig.PipelineRepository // TODO: remove this dependency; use read service + environmentRepository repository2.EnvironmentRepository // TODO: remove this dependency; use read service logger *zap.SugaredLogger imageTaggingServiceConfig *ImageTaggingServiceConfig } func NewImageTaggingServiceImpl(imageTaggingRepo repository.ImageTaggingRepository, + imageTaggingReadService read.ImageTaggingReadService, ciPipelineRepository pipelineConfig.CiPipelineRepository, cdPipelineRepository pipelineConfig.PipelineRepository, environmentRepository repository2.EnvironmentRepository, @@ -82,6 +82,7 @@ func NewImageTaggingServiceImpl(imageTaggingRepo repository.ImageTaggingReposito } return &ImageTaggingServiceImpl{ imageTaggingRepo: imageTaggingRepo, + imageTaggingReadService: imageTaggingReadService, ciPipelineRepository: ciPipelineRepository, cdPipelineRepository: cdPipelineRepository, environmentRepository: environmentRepository, @@ -90,7 +91,7 @@ func NewImageTaggingServiceImpl(imageTaggingRepo repository.ImageTaggingReposito } } -func (impl ImageTaggingServiceImpl) GetImageTaggingServiceConfig() ImageTaggingServiceConfig { +func (impl *ImageTaggingServiceImpl) GetImageTaggingServiceConfig() ImageTaggingServiceConfig { return *impl.imageTaggingServiceConfig } @@ -99,14 +100,14 @@ func (impl ImageTaggingServiceImpl) GetImageTaggingServiceConfig() ImageTaggingS // AppReleaseTags -> all the tags of the given appId, // imageComment -> comment of the given artifactId, // ProdEnvExists -> implies the existence of prod environment in any workflow of given ciPipelineId or its child ciPipelineRequest's -func (impl ImageTaggingServiceImpl) GetTagsData(ciPipelineId, appId, artifactId int, externalCi bool) (*types.ImageTaggingResponseDTO, error) { +func (impl *ImageTaggingServiceImpl) GetTagsData(ciPipelineId, appId, artifactId int, externalCi bool) (*types.ImageTaggingResponseDTO, error) { resp := &types.ImageTaggingResponseDTO{} imageComment, err := impl.imageTaggingRepo.GetImageComment(artifactId) if err != nil && err != pg.ErrNoRows { impl.logger.Errorw("error in fetching image comment using artifactId", "err", err, "artifactId", artifactId) return resp, err } - appReleaseTags, err := impl.GetUniqueTagsByAppId(appId) + appReleaseTags, err := impl.imageTaggingReadService.GetUniqueTagsByAppId(appId) if err != nil { impl.logger.Errorw("error in fetching image tags using appId", "err", err, "appId", appId) return resp, err @@ -118,7 +119,8 @@ func (impl ImageTaggingServiceImpl) GetTagsData(ciPipelineId, appId, artifactId } prodEnvExists := false if externalCi { - prodEnvExists, err = impl.FindProdEnvExists(externalCi, []int{ciPipelineId}) + // check if the given external ci pipeline has, any prod env as a child + prodEnvExists, err = impl.FindProdEnvExists(true, []int{ciPipelineId}) } else { prodEnvExists, err = impl.GetProdEnvFromParentAndLinkedWorkflow(ciPipelineId) } @@ -134,7 +136,7 @@ func (impl ImageTaggingServiceImpl) GetTagsData(ciPipelineId, appId, artifactId return resp, err } -func (impl ImageTaggingServiceImpl) getTagsByArtifactId(artifactId int) ([]*repository.ImageTag, error) { +func (impl *ImageTaggingServiceImpl) getTagsByArtifactId(artifactId int) ([]*repository.ImageTag, error) { imageReleaseTags, err := impl.imageTaggingRepo.GetTagsByArtifactId(artifactId) if err != nil && !errors.Is(err, pg.ErrNoRows) { //log error @@ -144,21 +146,8 @@ func (impl ImageTaggingServiceImpl) getTagsByArtifactId(artifactId int) ([]*repo return imageReleaseTags, nil } -func (impl ImageTaggingServiceImpl) GetTagNamesByArtifactId(artifactId int) ([]string, error) { - imageReleaseTags, err := impl.getTagsByArtifactId(artifactId) - if err != nil { - impl.logger.Errorw("error in fetching image tags using artifactId", "err", err, "artifactId", artifactId) - return nil, err - } - releaseTags := make([]string, 0, len(imageReleaseTags)) - for _, imageTag := range imageReleaseTags { - releaseTags = append(releaseTags, imageTag.TagName) - } - return releaseTags, nil -} - // GetTagsDataMapByAppId this will fetch a map of artifact vs []tags for given appId -func (impl ImageTaggingServiceImpl) GetTagsDataMapByAppId(appId int) (map[int][]*repository.ImageTag, error) { +func (impl *ImageTaggingServiceImpl) GetTagsDataMapByAppId(appId int) (map[int][]*repository.ImageTag, error) { tags, err := impl.imageTaggingRepo.GetTagsByAppId(appId) if err != nil { impl.logger.Errorw("error occurred in getting image tags by appId", "appId", appId, "err", err) @@ -177,7 +166,7 @@ func (impl ImageTaggingServiceImpl) GetTagsDataMapByAppId(appId int) (map[int][] } -func (impl ImageTaggingServiceImpl) GetImageCommentsDataMapByArtifactIds(artifactIds []int) (map[int]*repository.ImageComment, error) { +func (impl *ImageTaggingServiceImpl) GetImageCommentsDataMapByArtifactIds(artifactIds []int) (map[int]*repository.ImageComment, error) { result := make(map[int]*repository.ImageComment) imageComments, err := impl.imageTaggingRepo.GetImageCommentsByArtifactIds(artifactIds) @@ -195,7 +184,7 @@ func (impl ImageTaggingServiceImpl) GetImageCommentsDataMapByArtifactIds(artifac return result, nil } -func (impl ImageTaggingServiceImpl) ValidateImageTaggingRequest(imageTaggingRequest *types.ImageTaggingRequestDTO, appId, artifactId int) (bool, error) { +func (impl *ImageTaggingServiceImpl) ValidateImageTaggingRequest(imageTaggingRequest *types.ImageTaggingRequestDTO, appId, artifactId int) (bool, error) { if imageTaggingRequest == nil { return false, errors.New("inValid payload") } @@ -254,7 +243,8 @@ func tagNameValidation(tag string) error { } return nil } -func (impl ImageTaggingServiceImpl) CreateOrUpdateImageTagging(ciPipelineId, appId, artifactId, userId int, imageTaggingRequest *types.ImageTaggingRequestDTO) (*types.ImageTaggingResponseDTO, error) { + +func (impl *ImageTaggingServiceImpl) CreateOrUpdateImageTagging(ciPipelineId, appId, artifactId, userId int, imageTaggingRequest *types.ImageTaggingRequestDTO) (*types.ImageTaggingResponseDTO, error) { tx, err := impl.imageTaggingRepo.StartTx() defer func() { @@ -326,7 +316,7 @@ func (impl ImageTaggingServiceImpl) CreateOrUpdateImageTagging(ciPipelineId, app return impl.GetTagsData(ciPipelineId, appId, artifactId, imageTaggingRequest.ExternalCi) } -func (impl ImageTaggingServiceImpl) performTagOperationsAndGetAuditList(tx *pg.Tx, appId, artifactId, userId int, imageTaggingRequest *types.ImageTaggingRequestDTO) ([]*repository.ImageTaggingAudit, error) { +func (impl *ImageTaggingServiceImpl) performTagOperationsAndGetAuditList(tx *pg.Tx, appId, artifactId, userId int, imageTaggingRequest *types.ImageTaggingRequestDTO) ([]*repository.ImageTaggingAudit, error) { //first perform delete and then perform create operation. //case : user can delete existing tag and then create a new tag with same name, this is a valid request @@ -390,7 +380,8 @@ func (impl ImageTaggingServiceImpl) performTagOperationsAndGetAuditList(tx *pg.T } return auditLogsList, err } -func (impl ImageTaggingServiceImpl) getImageTagAudits(softDeleteTags, hardDeleteTags, createTags []string, userId, artifactId int) ([]*repository.ImageTaggingAudit, error) { + +func (impl *ImageTaggingServiceImpl) getImageTagAudits(softDeleteTags, hardDeleteTags, createTags []string, userId, artifactId int) ([]*repository.ImageTaggingAudit, error) { auditLogsList := make([]*repository.ImageTaggingAudit, 0) currentTime := time.Now() if len(softDeleteTags) > 0 { @@ -454,7 +445,7 @@ func (impl ImageTaggingServiceImpl) getImageTagAudits(softDeleteTags, hardDelete } -func (impl ImageTaggingServiceImpl) getImageCommentAudit(imageComment string, userId, artifactId int) (*repository.ImageTaggingAudit, error) { +func (impl *ImageTaggingServiceImpl) getImageCommentAudit(imageComment string, userId, artifactId int) (*repository.ImageTaggingAudit, error) { dataMap := make(map[string]string) dataMap[CommentKey] = imageComment @@ -475,7 +466,9 @@ func (impl ImageTaggingServiceImpl) getImageCommentAudit(imageComment string, us return auditLog, nil } -func (impl ImageTaggingServiceImpl) GetProdEnvFromParentAndLinkedWorkflow(ciPipelineId int) (bool, error) { +// GetProdEnvFromParentAndLinkedWorkflow returns true if the given ciPipelineId has at least one prod env as a child +// TODO: should be a part of ciPipelineReadService +func (impl *ImageTaggingServiceImpl) GetProdEnvFromParentAndLinkedWorkflow(ciPipelineId int) (bool, error) { pipelines, err := impl.ciPipelineRepository.FindByParentCiPipelineId(ciPipelineId) if err != nil { @@ -493,17 +486,19 @@ func (impl ImageTaggingServiceImpl) GetProdEnvFromParentAndLinkedWorkflow(ciPipe return impl.FindProdEnvExists(false, pipelineIds) } -func (impl ImageTaggingServiceImpl) FindProdEnvExists(externalCi bool, pipelineIds []int) (bool, error) { +// FindProdEnvExists returns true if the given ciPipelineIds has at least one prod env as a child +// TODO: should be a part of environmentReadService +func (impl *ImageTaggingServiceImpl) FindProdEnvExists(externalCi bool, pipelineIds []int) (bool, error) { prodEnvExists := false envs, err := impl.environmentRepository.FindEnvLinkedWithCiPipelines(externalCi, pipelineIds) if err != nil { - //add log + // add log impl.logger.Errorw("error in getting envs using ciPipelineIds", "err", err, "ciPipelineIds", pipelineIds) return false, err } for _, env := range envs { - //env is prod ,return true + // env is prod ,return true if env.Default { prodEnvExists = true break @@ -513,7 +508,9 @@ func (impl ImageTaggingServiceImpl) FindProdEnvExists(externalCi bool, pipelineI return prodEnvExists, nil } -func (impl ImageTaggingServiceImpl) GetProdEnvByCdPipelineId(pipelineId int) (bool, error) { +// GetProdEnvByCdPipelineId returns true if the given cdPipelineId has at least one prod env as a child +// TODO: should be a part of cdPipelineReadService +func (impl *ImageTaggingServiceImpl) GetProdEnvByCdPipelineId(pipelineId int) (bool, error) { pipeline, err := impl.cdPipelineRepository.FindById(pipelineId) if err != nil { impl.logger.Errorw("error occurred in fetching cdPipeline with pipelineId", "err", err, "pipelineId", pipelineId) @@ -523,7 +520,7 @@ func (impl ImageTaggingServiceImpl) GetProdEnvByCdPipelineId(pipelineId int) (bo return true, nil } - //CiPipelineId will be zero for external webhook ci + // CiPipelineId will be zero for external webhook ci if pipeline.CiPipelineId > 0 { return impl.GetProdEnvFromParentAndLinkedWorkflow(pipeline.CiPipelineId) } @@ -531,16 +528,3 @@ func (impl ImageTaggingServiceImpl) GetProdEnvByCdPipelineId(pipelineId int) (bo return false, nil } - -func (impl ImageTaggingServiceImpl) GetUniqueTagsByAppId(appId int) ([]string, error) { - imageTags, err := impl.imageTaggingRepo.GetTagsByAppId(appId) - if err != nil { - impl.logger.Errorw("error in fetching image tags using appId", "err", err, "appId", appId) - return nil, err - } - uniqueTags := make([]string, len(imageTags)) - for i, tag := range imageTags { - uniqueTags[i] = tag.TagName - } - return uniqueTags, nil -} diff --git a/wire_gen.go b/wire_gen.go index 0602deef879..4a71a161a07 100644 --- a/wire_gen.go +++ b/wire_gen.go @@ -1,6 +1,6 @@ // Code generated by Wire. DO NOT EDIT. -//go:generate go run -mod=mod github.com/google/wire/cmd/wire +//go:generate go run github.com/google/wire/cmd/wire //go:build !wireinject // +build !wireinject @@ -131,6 +131,7 @@ import ( "github.com/devtron-labs/devtron/pkg/auth/user" repository4 "github.com/devtron-labs/devtron/pkg/auth/user/repository" "github.com/devtron-labs/devtron/pkg/build/artifacts" + read3 "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging/read" "github.com/devtron-labs/devtron/pkg/bulkAction" "github.com/devtron-labs/devtron/pkg/chart" "github.com/devtron-labs/devtron/pkg/chart/gitOpsConfig" @@ -588,7 +589,8 @@ func InitializeApp() (*App, error) { resourceGroupMappingRepositoryImpl := resourceGroup.NewResourceGroupMappingRepositoryImpl(db) resourceGroupServiceImpl := resourceGroup2.NewResourceGroupServiceImpl(sugaredLogger, resourceGroupRepositoryImpl, resourceGroupMappingRepositoryImpl, enforcerUtilImpl, devtronResourceSearchableKeyServiceImpl, appStatusRepositoryImpl) imageTaggingRepositoryImpl := repository13.NewImageTaggingRepositoryImpl(db, transactionUtilImpl) - imageTaggingServiceImpl := pipeline.NewImageTaggingServiceImpl(imageTaggingRepositoryImpl, ciPipelineRepositoryImpl, pipelineRepositoryImpl, environmentRepositoryImpl, sugaredLogger) + imageTaggingReadServiceImpl := read3.NewImageTaggingReadServiceImpl(imageTaggingRepositoryImpl, sugaredLogger) + imageTaggingServiceImpl := pipeline.NewImageTaggingServiceImpl(imageTaggingRepositoryImpl, imageTaggingReadServiceImpl, ciPipelineRepositoryImpl, pipelineRepositoryImpl, environmentRepositoryImpl, sugaredLogger) blobStorageConfigServiceImpl := pipeline.NewBlobStorageConfigServiceImpl(sugaredLogger, k8sServiceImpl, ciCdConfig) ciHandlerImpl := pipeline.NewCiHandlerImpl(sugaredLogger, ciServiceImpl, ciPipelineMaterialRepositoryImpl, clientImpl, ciWorkflowRepositoryImpl, workflowServiceImpl, ciLogServiceImpl, ciArtifactRepositoryImpl, userServiceImpl, eventRESTClientImpl, eventSimpleFactoryImpl, ciPipelineRepositoryImpl, appListingRepositoryImpl, k8sServiceImpl, pipelineRepositoryImpl, enforcerUtilImpl, resourceGroupServiceImpl, environmentRepositoryImpl, imageTaggingServiceImpl, k8sCommonServiceImpl, clusterServiceImplExtended, blobStorageConfigServiceImpl, appWorkflowRepositoryImpl, customTagServiceImpl, environmentServiceImpl) gitWebhookRepositoryImpl := repository2.NewGitWebhookRepositoryImpl(db) @@ -653,7 +655,7 @@ func InitializeApp() (*App, error) { imageScanHistoryRepositoryImpl := security.NewImageScanHistoryRepositoryImpl(db, sugaredLogger) cveStoreRepositoryImpl := security.NewCveStoreRepositoryImpl(db, sugaredLogger) policyServiceImpl := security2.NewPolicyServiceImpl(environmentServiceImpl, sugaredLogger, appRepositoryImpl, pipelineOverrideRepositoryImpl, cvePolicyRepositoryImpl, clusterServiceImplExtended, pipelineRepositoryImpl, imageScanResultRepositoryImpl, imageScanDeployInfoRepositoryImpl, imageScanObjectMetaRepositoryImpl, httpClient, ciArtifactRepositoryImpl, ciCdConfig, imageScanHistoryRepositoryImpl, cveStoreRepositoryImpl, ciTemplateRepositoryImpl) - pipelineConfigRestHandlerImpl := configure.NewPipelineRestHandlerImpl(pipelineBuilderImpl, sugaredLogger, deploymentTemplateValidationServiceImpl, chartServiceImpl, devtronAppGitOpConfigServiceImpl, propertiesConfigServiceImpl, userServiceImpl, teamServiceImpl, enforcerImpl, ciHandlerImpl, validate, clientImpl, ciPipelineRepositoryImpl, pipelineRepositoryImpl, enforcerUtilImpl, dockerRegistryConfigImpl, cdHandlerImpl, appCloneServiceImpl, generateManifestDeploymentTemplateServiceImpl, appWorkflowServiceImpl, materialRepositoryImpl, policyServiceImpl, imageScanResultRepositoryImpl, gitProviderRepositoryImpl, argoUserServiceImpl, ciPipelineMaterialRepositoryImpl, imageTaggingServiceImpl, ciArtifactRepositoryImpl, deployedAppMetricsServiceImpl, chartRefServiceImpl, ciCdPipelineOrchestratorImpl) + pipelineConfigRestHandlerImpl := configure.NewPipelineRestHandlerImpl(pipelineBuilderImpl, sugaredLogger, deploymentTemplateValidationServiceImpl, chartServiceImpl, devtronAppGitOpConfigServiceImpl, propertiesConfigServiceImpl, userServiceImpl, teamServiceImpl, enforcerImpl, ciHandlerImpl, validate, clientImpl, ciPipelineRepositoryImpl, pipelineRepositoryImpl, enforcerUtilImpl, dockerRegistryConfigImpl, cdHandlerImpl, appCloneServiceImpl, generateManifestDeploymentTemplateServiceImpl, appWorkflowServiceImpl, materialRepositoryImpl, policyServiceImpl, imageScanResultRepositoryImpl, gitProviderRepositoryImpl, argoUserServiceImpl, ciPipelineMaterialRepositoryImpl, imageTaggingReadServiceImpl, imageTaggingServiceImpl, ciArtifactRepositoryImpl, deployedAppMetricsServiceImpl, chartRefServiceImpl, ciCdPipelineOrchestratorImpl) gitOpsManifestPushServiceImpl := publish.NewGitOpsManifestPushServiceImpl(sugaredLogger, pipelineStatusTimelineServiceImpl, pipelineOverrideRepositoryImpl, acdConfig, chartRefServiceImpl, gitOpsConfigReadServiceImpl, chartServiceImpl, gitOperationServiceImpl, argoClientWrapperServiceImpl, transactionUtilImpl, deploymentConfigServiceImpl, chartTemplateServiceImpl) argoK8sClientImpl := argocdServer.NewArgoK8sClientImpl(sugaredLogger, k8sServiceImpl) manifestCreationServiceImpl := manifest.NewManifestCreationServiceImpl(sugaredLogger, dockerRegistryIpsConfigServiceImpl, chartRefServiceImpl, scopedVariableCMCSManagerImpl, k8sCommonServiceImpl, deployedAppMetricsServiceImpl, imageDigestPolicyServiceImpl, mergeUtil, appCrudOperationServiceImpl, deploymentTemplateServiceImpl, applicationServiceClientImpl, configMapHistoryRepositoryImpl, configMapRepositoryImpl, chartRepositoryImpl, envConfigOverrideRepositoryImpl, environmentRepositoryImpl, pipelineRepositoryImpl, ciArtifactRepositoryImpl, pipelineOverrideRepositoryImpl, pipelineStrategyHistoryRepositoryImpl, pipelineConfigRepositoryImpl, deploymentTemplateHistoryRepositoryImpl, deploymentConfigServiceImpl) @@ -962,7 +964,7 @@ func InitializeApp() (*App, error) { infraConfigRouterImpl := infraConfig2.NewInfraProfileRouterImpl(infraConfigRestHandlerImpl) argoApplicationRestHandlerImpl := argoApplication2.NewArgoApplicationRestHandlerImpl(argoApplicationServiceExtendedImpl, argoApplicationReadServiceImpl, sugaredLogger, enforcerImpl) argoApplicationRouterImpl := argoApplication2.NewArgoApplicationRouterImpl(argoApplicationRestHandlerImpl) - deploymentHistoryServiceImpl := cdPipeline.NewDeploymentHistoryServiceImpl(sugaredLogger, cdHandlerImpl, imageTaggingServiceImpl, pipelineRepositoryImpl, deployedConfigurationHistoryServiceImpl) + deploymentHistoryServiceImpl := cdPipeline.NewDeploymentHistoryServiceImpl(sugaredLogger, cdHandlerImpl, imageTaggingReadServiceImpl, imageTaggingServiceImpl, pipelineRepositoryImpl, deployedConfigurationHistoryServiceImpl) apiReqDecoderServiceImpl := devtronResource.NewAPIReqDecoderServiceImpl(sugaredLogger, pipelineRepositoryImpl) historyRestHandlerImpl := devtronResource2.NewHistoryRestHandlerImpl(sugaredLogger, enforcerImpl, deploymentHistoryServiceImpl, apiReqDecoderServiceImpl, enforcerUtilImpl) historyRouterImpl := devtronResource2.NewHistoryRouterImpl(historyRestHandlerImpl) From 948840bdeb61750e110322d2bc6751f60650612a Mon Sep 17 00:00:00 2001 From: Ash-exp Date: Sat, 9 Nov 2024 23:52:42 +0530 Subject: [PATCH 2/7] added licencing comment --- .../imageTagging/read/ImageTaggingReadService.go | 16 ++++++++++++++++ .../artifacts/imageTagging/wire_image_tagging.go | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/pkg/build/artifacts/imageTagging/read/ImageTaggingReadService.go b/pkg/build/artifacts/imageTagging/read/ImageTaggingReadService.go index 8b18740f25a..4b6c10dc6f1 100644 --- a/pkg/build/artifacts/imageTagging/read/ImageTaggingReadService.go +++ b/pkg/build/artifacts/imageTagging/read/ImageTaggingReadService.go @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2024. Devtron Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package read import ( diff --git a/pkg/build/artifacts/imageTagging/wire_image_tagging.go b/pkg/build/artifacts/imageTagging/wire_image_tagging.go index f99a29594e5..a3e3e170610 100644 --- a/pkg/build/artifacts/imageTagging/wire_image_tagging.go +++ b/pkg/build/artifacts/imageTagging/wire_image_tagging.go @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2024. Devtron Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package imageTagging import ( From 2e2cef10f0f42e221c81299de64b4af7d2fda738 Mon Sep 17 00:00:00 2001 From: Ash-exp Date: Mon, 11 Nov 2024 17:57:46 +0530 Subject: [PATCH 3/7] moved method GetImageTaggingServiceConfig in read service --- .../configure/BuildPipelineRestHandler.go | 2 +- .../DeploymentPipelineRestHandler.go | 6 +-- .../artifacts/imageTagging/read/Config.go | 31 ++++++++++++ .../read/ImageTaggingReadService.go | 27 ++++++++--- .../cdPipeline/DeploymentHistoryService.go | 6 +-- pkg/pipeline/ImageTaggingService.go | 48 +++++++------------ wire_gen.go | 5 +- 7 files changed, 81 insertions(+), 44 deletions(-) create mode 100644 pkg/build/artifacts/imageTagging/read/Config.go diff --git a/api/restHandler/app/pipeline/configure/BuildPipelineRestHandler.go b/api/restHandler/app/pipeline/configure/BuildPipelineRestHandler.go index dd4fa743582..109c186d21c 100644 --- a/api/restHandler/app/pipeline/configure/BuildPipelineRestHandler.go +++ b/api/restHandler/app/pipeline/configure/BuildPipelineRestHandler.go @@ -1119,7 +1119,7 @@ func (handler *PipelineConfigRestHandlerImpl) GetBuildHistory(w http.ResponseWri prodEnvExists, err := handler.imageTaggingService.GetProdEnvFromParentAndLinkedWorkflow(ciPipeline.Id) resp.TagsEditable = prodEnvExists && triggerAccess - resp.HideImageTaggingHardDelete = handler.imageTaggingService.GetImageTaggingServiceConfig().HideImageTaggingHardDelete + resp.HideImageTaggingHardDelete = handler.imageTaggingService.IsHardDeleteHidden() if err != nil { handler.Logger.Errorw("service err, GetProdEnvFromParentAndLinkedWorkflow", "err", err, "ciPipelineId", ciPipeline.Id) common.WriteJsonResp(w, err, resp, http.StatusInternalServerError) diff --git a/api/restHandler/app/pipeline/configure/DeploymentPipelineRestHandler.go b/api/restHandler/app/pipeline/configure/DeploymentPipelineRestHandler.go index dccce66db32..fbc241d0b33 100644 --- a/api/restHandler/app/pipeline/configure/DeploymentPipelineRestHandler.go +++ b/api/restHandler/app/pipeline/configure/DeploymentPipelineRestHandler.go @@ -1364,7 +1364,7 @@ func (handler *PipelineConfigRestHandlerImpl) GetArtifactsByCDPipeline(w http.Re prodEnvExists, err := handler.imageTaggingService.GetProdEnvByCdPipelineId(pipeline.Id) ciArtifactResponse.TagsEditable = prodEnvExists && triggerAccess - ciArtifactResponse.HideImageTaggingHardDelete = handler.imageTaggingService.GetImageTaggingServiceConfig().HideImageTaggingHardDelete + ciArtifactResponse.HideImageTaggingHardDelete = handler.imageTaggingService.IsHardDeleteHidden() if err != nil { handler.Logger.Errorw("service err, GetProdEnvByCdPipelineId", "err", err, "cdPipelineId", pipeline.Id) common.WriteJsonResp(w, err, ciArtifactResponse, http.StatusInternalServerError) @@ -1608,7 +1608,7 @@ func (handler *PipelineConfigRestHandlerImpl) GetArtifactsForRollback(w http.Res prodEnvExists, err := handler.imageTaggingService.GetProdEnvByCdPipelineId(cdPipelineId) ciArtifactResponse.TagsEditable = prodEnvExists && triggerAccess - ciArtifactResponse.HideImageTaggingHardDelete = handler.imageTaggingService.GetImageTaggingServiceConfig().HideImageTaggingHardDelete + ciArtifactResponse.HideImageTaggingHardDelete = handler.imageTaggingService.IsHardDeleteHidden() if err != nil { handler.Logger.Errorw("service err, GetProdEnvByCdPipelineId", "err", err, "cdPipelineId", app.Id) common.WriteJsonResp(w, err, ciArtifactResponse, http.StatusInternalServerError) @@ -1733,7 +1733,7 @@ func (handler *PipelineConfigRestHandlerImpl) ListDeploymentHistory(w http.Respo prodEnvExists, err := handler.imageTaggingService.GetProdEnvByCdPipelineId(pipelineId) resp.TagsEdiatable = prodEnvExists - resp.HideImageTaggingHardDelete = handler.imageTaggingService.GetImageTaggingServiceConfig().HideImageTaggingHardDelete + resp.HideImageTaggingHardDelete = handler.imageTaggingService.IsHardDeleteHidden() if err != nil { handler.Logger.Errorw("service err, GetProdEnvFromParentAndLinkedWorkflow", "err", err, "cdPipelineId", pipelineId) common.WriteJsonResp(w, err, resp, http.StatusInternalServerError) diff --git a/pkg/build/artifacts/imageTagging/read/Config.go b/pkg/build/artifacts/imageTagging/read/Config.go new file mode 100644 index 00000000000..7f74dc3a2c3 --- /dev/null +++ b/pkg/build/artifacts/imageTagging/read/Config.go @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024. Devtron Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package read + +// ImageTaggingServiceConfig holds the configuration for the image tagging service +type ImageTaggingServiceConfig struct { + // HideImageTaggingHardDelete is a flag to hide the hard delete option in the image tagging service + HideImageTaggingHardDelete bool `env:"HIDE_IMAGE_TAGGING_HARD_DELETE" envDefault:"false"` +} + +func (c *ImageTaggingServiceConfig) IsHardDeleteHidden() bool { + if c == nil { + // return default value of ImageTaggingServiceConfig.HideImageTaggingHardDelete + return false + } + return c.HideImageTaggingHardDelete +} diff --git a/pkg/build/artifacts/imageTagging/read/ImageTaggingReadService.go b/pkg/build/artifacts/imageTagging/read/ImageTaggingReadService.go index 4b6c10dc6f1..e863a73ee6e 100644 --- a/pkg/build/artifacts/imageTagging/read/ImageTaggingReadService.go +++ b/pkg/build/artifacts/imageTagging/read/ImageTaggingReadService.go @@ -18,12 +18,15 @@ package read import ( "errors" + "github.com/caarlos0/env" repository "github.com/devtron-labs/devtron/internal/sql/repository/imageTagging" "github.com/go-pg/pg" "go.uber.org/zap" ) type ImageTaggingReadService interface { + // GetImageTaggingServiceConfig returns the ImageTaggingServiceConfig + GetImageTaggingServiceConfig() *ImageTaggingServiceConfig // GetTagNamesByArtifactId gets all the tag names for the given artifactId GetTagNamesByArtifactId(artifactId int) ([]string, error) // GetUniqueTagsByAppId gets all the unique tag names for the given appId @@ -31,17 +34,29 @@ type ImageTaggingReadService interface { } type ImageTaggingReadServiceImpl struct { - logger *zap.SugaredLogger - imageTaggingRepo repository.ImageTaggingRepository + logger *zap.SugaredLogger + imageTaggingServiceConfig *ImageTaggingServiceConfig + imageTaggingRepo repository.ImageTaggingRepository } func NewImageTaggingReadServiceImpl( imageTaggingRepo repository.ImageTaggingRepository, - logger *zap.SugaredLogger) *ImageTaggingReadServiceImpl { - return &ImageTaggingReadServiceImpl{ - logger: logger, - imageTaggingRepo: imageTaggingRepo, + logger *zap.SugaredLogger) (*ImageTaggingReadServiceImpl, error) { + imageTaggingServiceConfig := &ImageTaggingServiceConfig{} + err := env.Parse(imageTaggingServiceConfig) + if err != nil { + logger.Infow("error occurred while parsing ImageTaggingServiceConfig,so setting HIDE_IMAGE_TAGGING_HARD_DELETE to default value", "err", err) + return nil, err } + return &ImageTaggingReadServiceImpl{ + logger: logger, + imageTaggingServiceConfig: imageTaggingServiceConfig, + imageTaggingRepo: imageTaggingRepo, + }, nil +} + +func (impl *ImageTaggingReadServiceImpl) GetImageTaggingServiceConfig() *ImageTaggingServiceConfig { + return impl.imageTaggingServiceConfig } func (impl *ImageTaggingReadServiceImpl) GetTagNamesByArtifactId(artifactId int) ([]string, error) { diff --git a/pkg/devtronResource/history/deployment/cdPipeline/DeploymentHistoryService.go b/pkg/devtronResource/history/deployment/cdPipeline/DeploymentHistoryService.go index 04ba9bc8416..44796c20e18 100644 --- a/pkg/devtronResource/history/deployment/cdPipeline/DeploymentHistoryService.go +++ b/pkg/devtronResource/history/deployment/cdPipeline/DeploymentHistoryService.go @@ -57,12 +57,12 @@ func (impl *DeploymentHistoryServiceImpl) GetCdPipelineDeploymentHistory(req *hi resp.AppReleaseTagNames = appTags prodEnvExists, err := impl.imageTaggingService.GetProdEnvByCdPipelineId(req.PipelineId) - resp.TagsEditable = prodEnvExists - resp.HideImageTaggingHardDelete = impl.imageTaggingService.GetImageTaggingServiceConfig().HideImageTaggingHardDelete if err != nil { - impl.logger.Errorw("service err, GetProdEnvFromParentAndLinkedWorkflow", "err", err, "cdPipelineId", req.PipelineId) + impl.logger.Errorw("service err, GetProdEnvByCdPipelineId", "err", err, "cdPipelineId", req.PipelineId) return resp, err } + resp.TagsEditable = prodEnvExists + resp.HideImageTaggingHardDelete = impl.imageTaggingReadService.GetImageTaggingServiceConfig().IsHardDeleteHidden() return resp, nil } diff --git a/pkg/pipeline/ImageTaggingService.go b/pkg/pipeline/ImageTaggingService.go index d45413795b0..e9a4be1aca6 100644 --- a/pkg/pipeline/ImageTaggingService.go +++ b/pkg/pipeline/ImageTaggingService.go @@ -19,7 +19,6 @@ package pipeline import ( "encoding/json" "errors" - "github.com/caarlos0/env" repository "github.com/devtron-labs/devtron/internal/sql/repository/imageTagging" "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging/read" @@ -35,10 +34,6 @@ const TagsKey = "tags" const CommentKey = "comment" const DuplicateTagsInAppError = "cannot create duplicate tags in the same app" -type ImageTaggingServiceConfig struct { - HideImageTaggingHardDelete bool `env:"HIDE_IMAGE_TAGGING_HARD_DELETE" envDefault:"false"` -} - type ImageTaggingService interface { // GetTagsData returns the following fields in response Object // ImageReleaseTags -> this will get the tags of the artifact, @@ -55,18 +50,17 @@ type ImageTaggingService interface { GetTagsDataMapByAppId(appId int) (map[int][]*repository.ImageTag, error) // GetImageCommentsDataMapByArtifactIds this will fetch a map of artifact vs imageComment for given artifactIds GetImageCommentsDataMapByArtifactIds(artifactIds []int) (map[int]*repository.ImageComment, error) - GetImageTaggingServiceConfig() ImageTaggingServiceConfig + IsHardDeleteHidden() bool FindProdEnvExists(externalCi bool, pipelineIds []int) (bool, error) } type ImageTaggingServiceImpl struct { - imageTaggingRepo repository.ImageTaggingRepository - imageTaggingReadService read.ImageTaggingReadService - ciPipelineRepository pipelineConfig.CiPipelineRepository // TODO: remove this dependency; use read service - cdPipelineRepository pipelineConfig.PipelineRepository // TODO: remove this dependency; use read service - environmentRepository repository2.EnvironmentRepository // TODO: remove this dependency; use read service - logger *zap.SugaredLogger - imageTaggingServiceConfig *ImageTaggingServiceConfig + imageTaggingRepo repository.ImageTaggingRepository + imageTaggingReadService read.ImageTaggingReadService + ciPipelineRepository pipelineConfig.CiPipelineRepository // TODO: remove this dependency; use read service + cdPipelineRepository pipelineConfig.PipelineRepository // TODO: remove this dependency; use read service + environmentRepository repository2.EnvironmentRepository // TODO: remove this dependency; use read service + logger *zap.SugaredLogger } func NewImageTaggingServiceImpl(imageTaggingRepo repository.ImageTaggingRepository, @@ -75,24 +69,18 @@ func NewImageTaggingServiceImpl(imageTaggingRepo repository.ImageTaggingReposito cdPipelineRepository pipelineConfig.PipelineRepository, environmentRepository repository2.EnvironmentRepository, logger *zap.SugaredLogger) *ImageTaggingServiceImpl { - imageTaggingServiceConfig := &ImageTaggingServiceConfig{} - err := env.Parse(imageTaggingServiceConfig) - if err != nil { - logger.Infow("error occurred while parsing ImageTaggingServiceConfig,so setting HIDE_IMAGE_TAGGING_HARD_DELETE to default value", "err", err) - } return &ImageTaggingServiceImpl{ - imageTaggingRepo: imageTaggingRepo, - imageTaggingReadService: imageTaggingReadService, - ciPipelineRepository: ciPipelineRepository, - cdPipelineRepository: cdPipelineRepository, - environmentRepository: environmentRepository, - logger: logger, - imageTaggingServiceConfig: imageTaggingServiceConfig, + imageTaggingRepo: imageTaggingRepo, + imageTaggingReadService: imageTaggingReadService, + ciPipelineRepository: ciPipelineRepository, + cdPipelineRepository: cdPipelineRepository, + environmentRepository: environmentRepository, + logger: logger, } } -func (impl *ImageTaggingServiceImpl) GetImageTaggingServiceConfig() ImageTaggingServiceConfig { - return *impl.imageTaggingServiceConfig +func (impl *ImageTaggingServiceImpl) IsHardDeleteHidden() bool { + return impl.imageTaggingReadService.GetImageTaggingServiceConfig().IsHardDeleteHidden() } // GetTagsData returns the following fields in reponse Object @@ -132,7 +120,7 @@ func (impl *ImageTaggingServiceImpl) GetTagsData(ciPipelineId, appId, artifactId resp.ImageReleaseTags = imageReleaseTags resp.ImageComment = &imageComment resp.ProdEnvExists = prodEnvExists - resp.HideImageTaggingHardDelete = impl.imageTaggingServiceConfig.HideImageTaggingHardDelete + resp.HideImageTaggingHardDelete = impl.IsHardDeleteHidden() return resp, err } @@ -330,7 +318,7 @@ func (impl *ImageTaggingServiceImpl) performTagOperationsAndGetAuditList(tx *pg. } //hard delete tags hardDeleteAuditTags := make([]string, len(imageTaggingRequest.HardDeleteTags)) - if !impl.imageTaggingServiceConfig.HideImageTaggingHardDelete { + if !impl.IsHardDeleteHidden() { for i, tag := range imageTaggingRequest.HardDeleteTags { tag.AppId = appId tag.ArtifactId = artifactId @@ -354,7 +342,7 @@ func (impl *ImageTaggingServiceImpl) performTagOperationsAndGetAuditList(tx *pg. } } - if len(imageTaggingRequest.HardDeleteTags) > 0 && !impl.imageTaggingServiceConfig.HideImageTaggingHardDelete { + if len(imageTaggingRequest.HardDeleteTags) > 0 && !impl.IsHardDeleteHidden() { err = impl.imageTaggingRepo.DeleteReleaseTagInBulk(tx, imageTaggingRequest.HardDeleteTags) if err != nil { impl.logger.Errorw("error in deleting releaseTag in bulk", "err", err, "releaseTags", imageTaggingRequest.HardDeleteTags) diff --git a/wire_gen.go b/wire_gen.go index 4a71a161a07..6c8ce4a1941 100644 --- a/wire_gen.go +++ b/wire_gen.go @@ -589,7 +589,10 @@ func InitializeApp() (*App, error) { resourceGroupMappingRepositoryImpl := resourceGroup.NewResourceGroupMappingRepositoryImpl(db) resourceGroupServiceImpl := resourceGroup2.NewResourceGroupServiceImpl(sugaredLogger, resourceGroupRepositoryImpl, resourceGroupMappingRepositoryImpl, enforcerUtilImpl, devtronResourceSearchableKeyServiceImpl, appStatusRepositoryImpl) imageTaggingRepositoryImpl := repository13.NewImageTaggingRepositoryImpl(db, transactionUtilImpl) - imageTaggingReadServiceImpl := read3.NewImageTaggingReadServiceImpl(imageTaggingRepositoryImpl, sugaredLogger) + imageTaggingReadServiceImpl, err := read3.NewImageTaggingReadServiceImpl(imageTaggingRepositoryImpl, sugaredLogger) + if err != nil { + return nil, err + } imageTaggingServiceImpl := pipeline.NewImageTaggingServiceImpl(imageTaggingRepositoryImpl, imageTaggingReadServiceImpl, ciPipelineRepositoryImpl, pipelineRepositoryImpl, environmentRepositoryImpl, sugaredLogger) blobStorageConfigServiceImpl := pipeline.NewBlobStorageConfigServiceImpl(sugaredLogger, k8sServiceImpl, ciCdConfig) ciHandlerImpl := pipeline.NewCiHandlerImpl(sugaredLogger, ciServiceImpl, ciPipelineMaterialRepositoryImpl, clientImpl, ciWorkflowRepositoryImpl, workflowServiceImpl, ciLogServiceImpl, ciArtifactRepositoryImpl, userServiceImpl, eventRESTClientImpl, eventSimpleFactoryImpl, ciPipelineRepositoryImpl, appListingRepositoryImpl, k8sServiceImpl, pipelineRepositoryImpl, enforcerUtilImpl, resourceGroupServiceImpl, environmentRepositoryImpl, imageTaggingServiceImpl, k8sCommonServiceImpl, clusterServiceImplExtended, blobStorageConfigServiceImpl, appWorkflowRepositoryImpl, customTagServiceImpl, environmentServiceImpl) From 8e8ea0ddcddcd1db7adab54bf7878cc24a2365bd Mon Sep 17 00:00:00 2001 From: Ash-exp Date: Mon, 11 Nov 2024 22:49:10 +0530 Subject: [PATCH 4/7] moved ImageTaggingService.go --- Wire.go | 4 ++-- .../pipeline/configure/BuildPipelineRestHandler.go | 3 ++- .../pipeline/configure/PipelineConfigRestHandler.go | 5 +++-- .../artifacts/imageTagging}/ImageTaggingService.go | 2 +- .../imageTagging}/ImageTaggingService_test.go | 2 +- .../deployment/cdPipeline/DeploymentHistoryService.go | 5 +++-- pkg/pipeline/AppArtifactManager.go | 5 +++-- pkg/pipeline/CdHandler.go | 5 +++-- pkg/pipeline/CiHandler.go | 5 +++-- wire_gen.go | 11 ++++++----- 10 files changed, 27 insertions(+), 20 deletions(-) rename pkg/{pipeline => build/artifacts/imageTagging}/ImageTaggingService.go (99%) rename pkg/{pipeline => build/artifacts/imageTagging}/ImageTaggingService_test.go (99%) diff --git a/Wire.go b/Wire.go index 8eefb2f1e3e..116b077c827 100644 --- a/Wire.go +++ b/Wire.go @@ -452,8 +452,8 @@ func InitializeApp() (*App, error) { // session.NewK8sClient, repository8.NewImageTaggingRepositoryImpl, wire.Bind(new(repository8.ImageTaggingRepository), new(*repository8.ImageTaggingRepositoryImpl)), - pipeline.NewImageTaggingServiceImpl, - wire.Bind(new(pipeline.ImageTaggingService), new(*pipeline.ImageTaggingServiceImpl)), + imageTagging.NewImageTaggingServiceImpl, + wire.Bind(new(imageTagging.ImageTaggingService), new(*imageTagging.ImageTaggingServiceImpl)), argocdServer.NewVersionServiceImpl, wire.Bind(new(argocdServer.VersionService), new(*argocdServer.VersionServiceImpl)), diff --git a/api/restHandler/app/pipeline/configure/BuildPipelineRestHandler.go b/api/restHandler/app/pipeline/configure/BuildPipelineRestHandler.go index 109c186d21c..c3762241982 100644 --- a/api/restHandler/app/pipeline/configure/BuildPipelineRestHandler.go +++ b/api/restHandler/app/pipeline/configure/BuildPipelineRestHandler.go @@ -21,6 +21,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging" "golang.org/x/exp/maps" "io" "net/http" @@ -2074,7 +2075,7 @@ func (handler *PipelineConfigRestHandlerImpl) CreateUpdateImageTagging(w http.Re // pass it to the service layer resp, err := handler.imageTaggingService.CreateOrUpdateImageTagging(ciPipelineId, appId, artifactId, int(userId), req) if err != nil { - if err.Error() == pipeline.DuplicateTagsInAppError { + if err.Error() == imageTagging.DuplicateTagsInAppError { appReleaseTags, err1 := handler.imageTaggingReadService.GetUniqueTagsByAppId(appId) if err1 != nil { handler.Logger.Errorw("error occurred in getting unique tags in app", "err", err1, "appId", appId) diff --git a/api/restHandler/app/pipeline/configure/PipelineConfigRestHandler.go b/api/restHandler/app/pipeline/configure/PipelineConfigRestHandler.go index 563f22402e0..0fe53f1bba7 100644 --- a/api/restHandler/app/pipeline/configure/PipelineConfigRestHandler.go +++ b/api/restHandler/app/pipeline/configure/PipelineConfigRestHandler.go @@ -21,6 +21,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging" "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging/read" "github.com/devtron-labs/devtron/pkg/chart/gitOpsConfig" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deployedAppMetrics" @@ -124,7 +125,7 @@ type PipelineConfigRestHandlerImpl struct { gitProviderRepo repository.GitProviderRepository argoUserService argo.ArgoUserService imageTaggingReadService read.ImageTaggingReadService - imageTaggingService pipeline.ImageTaggingService + imageTaggingService imageTagging.ImageTaggingService deploymentTemplateService generateManifest.DeploymentTemplateService pipelineRestHandlerEnvConfig *PipelineRestHandlerEnvConfig ciArtifactRepository repository.CiArtifactRepository @@ -156,7 +157,7 @@ func NewPipelineRestHandlerImpl(pipelineBuilder pipeline.PipelineBuilder, Logger scanResultRepository security.ImageScanResultRepository, gitProviderRepo repository.GitProviderRepository, argoUserService argo.ArgoUserService, ciPipelineMaterialRepository pipelineConfig.CiPipelineMaterialRepository, imageTaggingReadService read.ImageTaggingReadService, - imageTaggingService pipeline.ImageTaggingService, + imageTaggingService imageTagging.ImageTaggingService, ciArtifactRepository repository.CiArtifactRepository, deployedAppMetricsService deployedAppMetrics.DeployedAppMetricsService, chartRefService chartRef.ChartRefService, diff --git a/pkg/pipeline/ImageTaggingService.go b/pkg/build/artifacts/imageTagging/ImageTaggingService.go similarity index 99% rename from pkg/pipeline/ImageTaggingService.go rename to pkg/build/artifacts/imageTagging/ImageTaggingService.go index e9a4be1aca6..30c811d1793 100644 --- a/pkg/pipeline/ImageTaggingService.go +++ b/pkg/build/artifacts/imageTagging/ImageTaggingService.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package pipeline +package imageTagging import ( "encoding/json" diff --git a/pkg/pipeline/ImageTaggingService_test.go b/pkg/build/artifacts/imageTagging/ImageTaggingService_test.go similarity index 99% rename from pkg/pipeline/ImageTaggingService_test.go rename to pkg/build/artifacts/imageTagging/ImageTaggingService_test.go index c887ba2127e..af77df20359 100644 --- a/pkg/pipeline/ImageTaggingService_test.go +++ b/pkg/build/artifacts/imageTagging/ImageTaggingService_test.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package pipeline +package imageTagging import ( "errors" diff --git a/pkg/devtronResource/history/deployment/cdPipeline/DeploymentHistoryService.go b/pkg/devtronResource/history/deployment/cdPipeline/DeploymentHistoryService.go index 15d34716324..3917efb151d 100644 --- a/pkg/devtronResource/history/deployment/cdPipeline/DeploymentHistoryService.go +++ b/pkg/devtronResource/history/deployment/cdPipeline/DeploymentHistoryService.go @@ -2,6 +2,7 @@ package cdPipeline import ( "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" + "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging" "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging/read" historyBean "github.com/devtron-labs/devtron/pkg/devtronResource/bean/history" "github.com/devtron-labs/devtron/pkg/pipeline" @@ -20,7 +21,7 @@ type DeploymentHistoryServiceImpl struct { logger *zap.SugaredLogger cdHandler pipeline.CdHandler imageTaggingReadService read.ImageTaggingReadService - imageTaggingService pipeline.ImageTaggingService + imageTaggingService imageTagging.ImageTaggingService pipelineRepository pipelineConfig.PipelineRepository deployedConfigurationHistoryService history.DeployedConfigurationHistoryService } @@ -28,7 +29,7 @@ type DeploymentHistoryServiceImpl struct { func NewDeploymentHistoryServiceImpl(logger *zap.SugaredLogger, cdHandler pipeline.CdHandler, imageTaggingReadService read.ImageTaggingReadService, - imageTaggingService pipeline.ImageTaggingService, + imageTaggingService imageTagging.ImageTaggingService, pipelineRepository pipelineConfig.PipelineRepository, deployedConfigurationHistoryService history.DeployedConfigurationHistoryService) *DeploymentHistoryServiceImpl { return &DeploymentHistoryServiceImpl{ diff --git a/pkg/pipeline/AppArtifactManager.go b/pkg/pipeline/AppArtifactManager.go index 088cef8b585..ebce4d12ed0 100644 --- a/pkg/pipeline/AppArtifactManager.go +++ b/pkg/pipeline/AppArtifactManager.go @@ -18,6 +18,7 @@ package pipeline import ( argoApplication "github.com/devtron-labs/devtron/client/argocdServer/bean" + "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging" pipelineBean "github.com/devtron-labs/devtron/pkg/pipeline/bean" "sort" "strings" @@ -51,7 +52,7 @@ type AppArtifactManagerImpl struct { logger *zap.SugaredLogger cdWorkflowRepository pipelineConfig.CdWorkflowRepository userService user.UserService - imageTaggingService ImageTaggingService + imageTaggingService imageTagging.ImageTaggingService ciArtifactRepository repository.CiArtifactRepository ciWorkflowRepository pipelineConfig.CiWorkflowRepository pipelineStageService PipelineStageService @@ -66,7 +67,7 @@ func NewAppArtifactManagerImpl( logger *zap.SugaredLogger, cdWorkflowRepository pipelineConfig.CdWorkflowRepository, userService user.UserService, - imageTaggingService ImageTaggingService, + imageTaggingService imageTagging.ImageTaggingService, ciArtifactRepository repository.CiArtifactRepository, ciWorkflowRepository pipelineConfig.CiWorkflowRepository, pipelineStageService PipelineStageService, diff --git a/pkg/pipeline/CdHandler.go b/pkg/pipeline/CdHandler.go index e62d080bee5..eb8b1fbb494 100644 --- a/pkg/pipeline/CdHandler.go +++ b/pkg/pipeline/CdHandler.go @@ -22,6 +22,7 @@ import ( "fmt" "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/adapter/cdWorkflow" bean2 "github.com/devtron-labs/devtron/pkg/bean" + "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging" common2 "github.com/devtron-labs/devtron/pkg/deployment/common" util2 "github.com/devtron-labs/devtron/pkg/pipeline/util" "os" @@ -84,7 +85,7 @@ type CdHandlerImpl struct { ciWorkflowRepository pipelineConfig.CiWorkflowRepository enforcerUtil rbac.EnforcerUtil resourceGroupService resourceGroup2.ResourceGroupService - imageTaggingService ImageTaggingService + imageTaggingService imageTagging.ImageTaggingService k8sUtil *k8s.K8sServiceImpl workflowService WorkflowService config *types.CdConfig @@ -101,7 +102,7 @@ func NewCdHandlerImpl(Logger *zap.SugaredLogger, userService user.UserService, pipelineRepository pipelineConfig.PipelineRepository, envRepository repository2.EnvironmentRepository, ciWorkflowRepository pipelineConfig.CiWorkflowRepository, enforcerUtil rbac.EnforcerUtil, resourceGroupService resourceGroup2.ResourceGroupService, - imageTaggingService ImageTaggingService, k8sUtil *k8s.K8sServiceImpl, + imageTaggingService imageTagging.ImageTaggingService, k8sUtil *k8s.K8sServiceImpl, workflowService WorkflowService, clusterService cluster.ClusterService, blobConfigStorageService BlobStorageConfigService, customTagService CustomTagService, deploymentConfigService common2.DeploymentConfigService, diff --git a/pkg/pipeline/CiHandler.go b/pkg/pipeline/CiHandler.go index e22c368d5f8..9d003ca96df 100644 --- a/pkg/pipeline/CiHandler.go +++ b/pkg/pipeline/CiHandler.go @@ -23,6 +23,7 @@ import ( "fmt" "github.com/devtron-labs/common-lib/utils/workFlow" "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/workflow/cdWorkflow" + "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging" "github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline" util3 "github.com/devtron-labs/devtron/pkg/pipeline/util" "io/ioutil" @@ -108,7 +109,7 @@ type CiHandlerImpl struct { enforcerUtil rbac.EnforcerUtil resourceGroupService resourceGroup.ResourceGroupService envRepository repository3.EnvironmentRepository - imageTaggingService ImageTaggingService + imageTaggingService imageTagging.ImageTaggingService customTagService CustomTagService appWorkflowRepository appWorkflow.AppWorkflowRepository config *types.CiConfig @@ -121,7 +122,7 @@ type CiHandlerImpl struct { func NewCiHandlerImpl(Logger *zap.SugaredLogger, ciService CiService, ciPipelineMaterialRepository pipelineConfig.CiPipelineMaterialRepository, gitSensorClient gitSensor.Client, ciWorkflowRepository pipelineConfig.CiWorkflowRepository, workflowService WorkflowService, ciLogService CiLogService, ciArtifactRepository repository.CiArtifactRepository, userService user.UserService, eventClient client.EventClient, eventFactory client.EventFactory, ciPipelineRepository pipelineConfig.CiPipelineRepository, appListingRepository repository.AppListingRepository, K8sUtil *k8s.K8sServiceImpl, cdPipelineRepository pipelineConfig.PipelineRepository, enforcerUtil rbac.EnforcerUtil, resourceGroupService resourceGroup.ResourceGroupService, envRepository repository3.EnvironmentRepository, - imageTaggingService ImageTaggingService, k8sCommonService k8s2.K8sCommonService, clusterService cluster.ClusterService, blobConfigStorageService BlobStorageConfigService, appWorkflowRepository appWorkflow.AppWorkflowRepository, customTagService CustomTagService, + imageTaggingService imageTagging.ImageTaggingService, k8sCommonService k8s2.K8sCommonService, clusterService cluster.ClusterService, blobConfigStorageService BlobStorageConfigService, appWorkflowRepository appWorkflow.AppWorkflowRepository, customTagService CustomTagService, envService cluster.EnvironmentService) *CiHandlerImpl { cih := &CiHandlerImpl{ Logger: Logger, diff --git a/wire_gen.go b/wire_gen.go index 4b12bc74173..d51a71e4474 100644 --- a/wire_gen.go +++ b/wire_gen.go @@ -131,6 +131,7 @@ import ( "github.com/devtron-labs/devtron/pkg/auth/user" repository4 "github.com/devtron-labs/devtron/pkg/auth/user/repository" "github.com/devtron-labs/devtron/pkg/build/artifacts" + "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging" read3 "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging/read" "github.com/devtron-labs/devtron/pkg/bulkAction" "github.com/devtron-labs/devtron/pkg/chart" @@ -150,12 +151,12 @@ import ( "github.com/devtron-labs/devtron/pkg/deployment/gitOps/validation" "github.com/devtron-labs/devtron/pkg/deployment/manifest" "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret" - read4 "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret/read" + read5 "github.com/devtron-labs/devtron/pkg/deployment/manifest/configMapAndSecret/read" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deployedAppMetrics" repository9 "github.com/devtron-labs/devtron/pkg/deployment/manifest/deployedAppMetrics/repository" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate" "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef" - read3 "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/read" + read4 "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/read" "github.com/devtron-labs/devtron/pkg/deployment/manifest/publish" "github.com/devtron-labs/devtron/pkg/deployment/providerConfig" "github.com/devtron-labs/devtron/pkg/deployment/trigger/devtronApps" @@ -596,7 +597,7 @@ func InitializeApp() (*App, error) { if err != nil { return nil, err } - imageTaggingServiceImpl := pipeline.NewImageTaggingServiceImpl(imageTaggingRepositoryImpl, imageTaggingReadServiceImpl, ciPipelineRepositoryImpl, pipelineRepositoryImpl, environmentRepositoryImpl, sugaredLogger) + imageTaggingServiceImpl := imageTagging.NewImageTaggingServiceImpl(imageTaggingRepositoryImpl, imageTaggingReadServiceImpl, ciPipelineRepositoryImpl, pipelineRepositoryImpl, environmentRepositoryImpl, sugaredLogger) blobStorageConfigServiceImpl := pipeline.NewBlobStorageConfigServiceImpl(sugaredLogger, k8sServiceImpl, ciCdConfig) ciHandlerImpl := pipeline.NewCiHandlerImpl(sugaredLogger, ciServiceImpl, ciPipelineMaterialRepositoryImpl, clientImpl, ciWorkflowRepositoryImpl, workflowServiceImpl, ciLogServiceImpl, ciArtifactRepositoryImpl, userServiceImpl, eventRESTClientImpl, eventSimpleFactoryImpl, ciPipelineRepositoryImpl, appListingRepositoryImpl, k8sServiceImpl, pipelineRepositoryImpl, enforcerUtilImpl, resourceGroupServiceImpl, environmentRepositoryImpl, imageTaggingServiceImpl, k8sCommonServiceImpl, clusterServiceImplExtended, blobStorageConfigServiceImpl, appWorkflowRepositoryImpl, customTagServiceImpl, environmentServiceImpl) gitWebhookRepositoryImpl := repository2.NewGitWebhookRepositoryImpl(db) @@ -650,7 +651,7 @@ func InitializeApp() (*App, error) { appWorkflowServiceImpl := appWorkflow2.NewAppWorkflowServiceImpl(sugaredLogger, appWorkflowRepositoryImpl, ciCdPipelineOrchestratorImpl, ciPipelineRepositoryImpl, pipelineRepositoryImpl, enforcerUtilImpl, resourceGroupServiceImpl, appRepositoryImpl, userAuthServiceImpl, chartServiceImpl, deploymentConfigServiceImpl) appCloneServiceImpl := appClone.NewAppCloneServiceImpl(sugaredLogger, pipelineBuilderImpl, attributesServiceImpl, chartServiceImpl, configMapServiceImpl, appWorkflowServiceImpl, appListingServiceImpl, propertiesConfigServiceImpl, pipelineStageServiceImpl, ciTemplateServiceImpl, appRepositoryImpl, ciPipelineRepositoryImpl, pipelineRepositoryImpl, ciPipelineConfigServiceImpl, gitOpsConfigReadServiceImpl) deploymentTemplateRepositoryImpl := repository2.NewDeploymentTemplateRepositoryImpl(db, sugaredLogger) - deploymentTemplateHistoryReadServiceImpl := read3.NewDeploymentTemplateHistoryReadServiceImpl(sugaredLogger, deploymentTemplateHistoryRepositoryImpl, scopedVariableManagerImpl) + deploymentTemplateHistoryReadServiceImpl := read4.NewDeploymentTemplateHistoryReadServiceImpl(sugaredLogger, deploymentTemplateHistoryRepositoryImpl, scopedVariableManagerImpl) generateManifestDeploymentTemplateServiceImpl, err := generateManifest.NewDeploymentTemplateServiceImpl(sugaredLogger, chartServiceImpl, appListingServiceImpl, deploymentTemplateRepositoryImpl, helmAppServiceImpl, chartTemplateServiceImpl, helmAppClientImpl, k8sServiceImpl, propertiesConfigServiceImpl, environmentRepositoryImpl, appRepositoryImpl, scopedVariableManagerImpl, chartRefServiceImpl, pipelineOverrideRepositoryImpl, chartRepositoryImpl, pipelineRepositoryImpl, mergeUtil, deploymentTemplateHistoryReadServiceImpl) if err != nil { return nil, err @@ -666,7 +667,7 @@ func InitializeApp() (*App, error) { gitOpsManifestPushServiceImpl := publish.NewGitOpsManifestPushServiceImpl(sugaredLogger, pipelineStatusTimelineServiceImpl, pipelineOverrideRepositoryImpl, acdConfig, chartRefServiceImpl, gitOpsConfigReadServiceImpl, chartServiceImpl, gitOperationServiceImpl, argoClientWrapperServiceImpl, transactionUtilImpl, deploymentConfigServiceImpl, chartTemplateServiceImpl) argoK8sClientImpl := argocdServer.NewArgoK8sClientImpl(sugaredLogger, k8sServiceImpl) manifestCreationServiceImpl := manifest.NewManifestCreationServiceImpl(sugaredLogger, dockerRegistryIpsConfigServiceImpl, chartRefServiceImpl, scopedVariableCMCSManagerImpl, k8sCommonServiceImpl, deployedAppMetricsServiceImpl, imageDigestPolicyServiceImpl, mergeUtil, appCrudOperationServiceImpl, deploymentTemplateServiceImpl, applicationServiceClientImpl, configMapHistoryRepositoryImpl, configMapRepositoryImpl, chartRepositoryImpl, envConfigOverrideRepositoryImpl, environmentRepositoryImpl, pipelineRepositoryImpl, ciArtifactRepositoryImpl, pipelineOverrideRepositoryImpl, pipelineStrategyHistoryRepositoryImpl, pipelineConfigRepositoryImpl, deploymentTemplateHistoryRepositoryImpl, deploymentConfigServiceImpl) - configMapHistoryReadServiceImpl := read4.NewConfigMapHistoryReadService(sugaredLogger, configMapHistoryRepositoryImpl, scopedVariableCMCSManagerImpl) + configMapHistoryReadServiceImpl := read5.NewConfigMapHistoryReadService(sugaredLogger, configMapHistoryRepositoryImpl, scopedVariableCMCSManagerImpl) deployedConfigurationHistoryServiceImpl := history.NewDeployedConfigurationHistoryServiceImpl(sugaredLogger, userServiceImpl, deploymentTemplateHistoryServiceImpl, pipelineStrategyHistoryServiceImpl, configMapHistoryServiceImpl, cdWorkflowRepositoryImpl, scopedVariableCMCSManagerImpl, deploymentTemplateHistoryReadServiceImpl, configMapHistoryReadServiceImpl) userDeploymentRequestRepositoryImpl := repository15.NewUserDeploymentRequestRepositoryImpl(db, transactionUtilImpl) userDeploymentRequestServiceImpl := service2.NewUserDeploymentRequestServiceImpl(sugaredLogger, userDeploymentRequestRepositoryImpl) From 3580a0b9bee2da59c545ba8f943060a0bce9994e Mon Sep 17 00:00:00 2001 From: Ash-exp Date: Tue, 12 Nov 2024 00:01:42 +0530 Subject: [PATCH 5/7] fix: TestImageTaggingService unit test cases --- .../mocks/CiPipelineRepository.go | 249 +++++++++- .../mocks/PipelineRepository.go | 450 ++++++++++++++++-- .../imageTagging/ImageTaggingService_test.go | 84 ++-- .../repository/mocks/EnvironmentRepository.go | 172 ++++++- 4 files changed, 871 insertions(+), 84 deletions(-) diff --git a/internal/sql/repository/pipelineConfig/mocks/CiPipelineRepository.go b/internal/sql/repository/pipelineConfig/mocks/CiPipelineRepository.go index b70635324fb..e40d8fc5b70 100644 --- a/internal/sql/repository/pipelineConfig/mocks/CiPipelineRepository.go +++ b/internal/sql/repository/pipelineConfig/mocks/CiPipelineRepository.go @@ -1,10 +1,11 @@ -// Code generated by mockery v2.32.0. DO NOT EDIT. +// Code generated by mockery v2.42.0. DO NOT EDIT. package mocks import ( context "context" - bean "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/ciPipeline" + + ciPipeline "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/ciPipeline" mock "github.com/stretchr/testify/mock" @@ -24,6 +25,10 @@ type CiPipelineRepository struct { func (_m *CiPipelineRepository) CheckIfPipelineExistsByNameAndAppId(pipelineName string, appId int) (bool, error) { ret := _m.Called(pipelineName, appId) + if len(ret) == 0 { + panic("no return value specified for CheckIfPipelineExistsByNameAndAppId") + } + var r0 bool var r1 error if rf, ok := ret.Get(0).(func(string, int) (bool, error)); ok { @@ -48,6 +53,10 @@ func (_m *CiPipelineRepository) CheckIfPipelineExistsByNameAndAppId(pipelineName func (_m *CiPipelineRepository) CommitTx(tx *pg.Tx) error { ret := _m.Called(tx) + if len(ret) == 0 { + panic("no return value specified for CommitTx") + } + var r0 error if rf, ok := ret.Get(0).(func(*pg.Tx) error); ok { r0 = rf(tx) @@ -62,6 +71,10 @@ func (_m *CiPipelineRepository) CommitTx(tx *pg.Tx) error { func (_m *CiPipelineRepository) FetchCiPipelinesForDG(parentId int, childCiPipelineIds []int) (*pipelineConfig.CiPipeline, int, error) { ret := _m.Called(parentId, childCiPipelineIds) + if len(ret) == 0 { + panic("no return value specified for FetchCiPipelinesForDG") + } + var r0 *pipelineConfig.CiPipeline var r1 int var r2 error @@ -92,19 +105,23 @@ func (_m *CiPipelineRepository) FetchCiPipelinesForDG(parentId int, childCiPipel } // FetchParentCiPipelinesForDG provides a mock function with given fields: -func (_m *CiPipelineRepository) FetchParentCiPipelinesForDG() ([]*bean.CiPipelinesMap, error) { +func (_m *CiPipelineRepository) FetchParentCiPipelinesForDG() ([]*ciPipeline.CiPipelinesMap, error) { ret := _m.Called() - var r0 []*bean.CiPipelinesMap + if len(ret) == 0 { + panic("no return value specified for FetchParentCiPipelinesForDG") + } + + var r0 []*ciPipeline.CiPipelinesMap var r1 error - if rf, ok := ret.Get(0).(func() ([]*bean.CiPipelinesMap, error)); ok { + if rf, ok := ret.Get(0).(func() ([]*ciPipeline.CiPipelinesMap, error)); ok { return rf() } - if rf, ok := ret.Get(0).(func() []*bean.CiPipelinesMap); ok { + if rf, ok := ret.Get(0).(func() []*ciPipeline.CiPipelinesMap); ok { r0 = rf() } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]*bean.CiPipelinesMap) + r0 = ret.Get(0).([]*ciPipeline.CiPipelinesMap) } } @@ -121,6 +138,10 @@ func (_m *CiPipelineRepository) FetchParentCiPipelinesForDG() ([]*bean.CiPipelin func (_m *CiPipelineRepository) FinDByParentCiPipelineAndAppId(parentCiPipeline int, appIds []int) ([]*pipelineConfig.CiPipeline, error) { ret := _m.Called(parentCiPipeline, appIds) + if len(ret) == 0 { + panic("no return value specified for FinDByParentCiPipelineAndAppId") + } + var r0 []*pipelineConfig.CiPipeline var r1 error if rf, ok := ret.Get(0).(func(int, []int) ([]*pipelineConfig.CiPipeline, error)); ok { @@ -147,6 +168,10 @@ func (_m *CiPipelineRepository) FinDByParentCiPipelineAndAppId(parentCiPipeline func (_m *CiPipelineRepository) FindAllDeletedPipelineCountInLast24Hour() (int, error) { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for FindAllDeletedPipelineCountInLast24Hour") + } + var r0 int var r1 error if rf, ok := ret.Get(0).(func() (int, error)); ok { @@ -171,6 +196,10 @@ func (_m *CiPipelineRepository) FindAllDeletedPipelineCountInLast24Hour() (int, func (_m *CiPipelineRepository) FindAllPipelineCreatedCountInLast24Hour() (int, error) { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for FindAllPipelineCreatedCountInLast24Hour") + } + var r0 int var r1 error if rf, ok := ret.Get(0).(func() (int, error)); ok { @@ -195,6 +224,10 @@ func (_m *CiPipelineRepository) FindAllPipelineCreatedCountInLast24Hour() (int, func (_m *CiPipelineRepository) FindAppAndProjectByCiPipelineIds(ciPipelineIds []int) ([]*pipelineConfig.CiPipeline, error) { ret := _m.Called(ciPipelineIds) + if len(ret) == 0 { + panic("no return value specified for FindAppAndProjectByCiPipelineIds") + } + var r0 []*pipelineConfig.CiPipeline var r1 error if rf, ok := ret.Get(0).(func([]int) ([]*pipelineConfig.CiPipeline, error)); ok { @@ -221,6 +254,10 @@ func (_m *CiPipelineRepository) FindAppAndProjectByCiPipelineIds(ciPipelineIds [ func (_m *CiPipelineRepository) FindAppIdsForCiPipelineIds(pipelineIds []int) (map[int]int, error) { ret := _m.Called(pipelineIds) + if len(ret) == 0 { + panic("no return value specified for FindAppIdsForCiPipelineIds") + } + var r0 map[int]int var r1 error if rf, ok := ret.Get(0).(func([]int) (map[int]int, error)); ok { @@ -247,6 +284,10 @@ func (_m *CiPipelineRepository) FindAppIdsForCiPipelineIds(pipelineIds []int) (m func (_m *CiPipelineRepository) FindByAppId(appId int) ([]*pipelineConfig.CiPipeline, error) { ret := _m.Called(appId) + if len(ret) == 0 { + panic("no return value specified for FindByAppId") + } + var r0 []*pipelineConfig.CiPipeline var r1 error if rf, ok := ret.Get(0).(func(int) ([]*pipelineConfig.CiPipeline, error)); ok { @@ -273,6 +314,10 @@ func (_m *CiPipelineRepository) FindByAppId(appId int) ([]*pipelineConfig.CiPipe func (_m *CiPipelineRepository) FindByAppIds(appIds []int) ([]*pipelineConfig.CiPipeline, error) { ret := _m.Called(appIds) + if len(ret) == 0 { + panic("no return value specified for FindByAppIds") + } + var r0 []*pipelineConfig.CiPipeline var r1 error if rf, ok := ret.Get(0).(func([]int) ([]*pipelineConfig.CiPipeline, error)); ok { @@ -299,6 +344,10 @@ func (_m *CiPipelineRepository) FindByAppIds(appIds []int) ([]*pipelineConfig.Ci func (_m *CiPipelineRepository) FindByCiAndAppDetailsById(pipelineId int) (*pipelineConfig.CiPipeline, error) { ret := _m.Called(pipelineId) + if len(ret) == 0 { + panic("no return value specified for FindByCiAndAppDetailsById") + } + var r0 *pipelineConfig.CiPipeline var r1 error if rf, ok := ret.Get(0).(func(int) (*pipelineConfig.CiPipeline, error)); ok { @@ -325,6 +374,10 @@ func (_m *CiPipelineRepository) FindByCiAndAppDetailsById(pipelineId int) (*pipe func (_m *CiPipelineRepository) FindById(id int) (*pipelineConfig.CiPipeline, error) { ret := _m.Called(id) + if len(ret) == 0 { + panic("no return value specified for FindById") + } + var r0 *pipelineConfig.CiPipeline var r1 error if rf, ok := ret.Get(0).(func(int) (*pipelineConfig.CiPipeline, error)); ok { @@ -351,6 +404,10 @@ func (_m *CiPipelineRepository) FindById(id int) (*pipelineConfig.CiPipeline, er func (_m *CiPipelineRepository) FindByIdIncludingInActive(id int) (*pipelineConfig.CiPipeline, error) { ret := _m.Called(id) + if len(ret) == 0 { + panic("no return value specified for FindByIdIncludingInActive") + } + var r0 *pipelineConfig.CiPipeline var r1 error if rf, ok := ret.Get(0).(func(int) (*pipelineConfig.CiPipeline, error)); ok { @@ -377,6 +434,10 @@ func (_m *CiPipelineRepository) FindByIdIncludingInActive(id int) (*pipelineConf func (_m *CiPipelineRepository) FindByIdsIn(ids []int) ([]*pipelineConfig.CiPipeline, error) { ret := _m.Called(ids) + if len(ret) == 0 { + panic("no return value specified for FindByIdsIn") + } + var r0 []*pipelineConfig.CiPipeline var r1 error if rf, ok := ret.Get(0).(func([]int) ([]*pipelineConfig.CiPipeline, error)); ok { @@ -399,10 +460,42 @@ func (_m *CiPipelineRepository) FindByIdsIn(ids []int) ([]*pipelineConfig.CiPipe return r0, r1 } +// FindByLinkedCiCount provides a mock function with given fields: parentCiPipelineId +func (_m *CiPipelineRepository) FindByLinkedCiCount(parentCiPipelineId int) (int, error) { + ret := _m.Called(parentCiPipelineId) + + if len(ret) == 0 { + panic("no return value specified for FindByLinkedCiCount") + } + + var r0 int + var r1 error + if rf, ok := ret.Get(0).(func(int) (int, error)); ok { + return rf(parentCiPipelineId) + } + if rf, ok := ret.Get(0).(func(int) int); ok { + r0 = rf(parentCiPipelineId) + } else { + r0 = ret.Get(0).(int) + } + + if rf, ok := ret.Get(1).(func(int) error); ok { + r1 = rf(parentCiPipelineId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // FindByName provides a mock function with given fields: pipelineName func (_m *CiPipelineRepository) FindByName(pipelineName string) (*pipelineConfig.CiPipeline, error) { ret := _m.Called(pipelineName) + if len(ret) == 0 { + panic("no return value specified for FindByName") + } + var r0 *pipelineConfig.CiPipeline var r1 error if rf, ok := ret.Get(0).(func(string) (*pipelineConfig.CiPipeline, error)); ok { @@ -429,6 +522,10 @@ func (_m *CiPipelineRepository) FindByName(pipelineName string) (*pipelineConfig func (_m *CiPipelineRepository) FindByParentCiPipelineId(parentCiPipelineId int) ([]*pipelineConfig.CiPipeline, error) { ret := _m.Called(parentCiPipelineId) + if len(ret) == 0 { + panic("no return value specified for FindByParentCiPipelineId") + } + var r0 []*pipelineConfig.CiPipeline var r1 error if rf, ok := ret.Get(0).(func(int) ([]*pipelineConfig.CiPipeline, error)); ok { @@ -455,6 +552,10 @@ func (_m *CiPipelineRepository) FindByParentCiPipelineId(parentCiPipelineId int) func (_m *CiPipelineRepository) FindByParentCiPipelineIds(parentCiPipelineIds []int) ([]*pipelineConfig.CiPipeline, error) { ret := _m.Called(parentCiPipelineIds) + if len(ret) == 0 { + panic("no return value specified for FindByParentCiPipelineIds") + } + var r0 []*pipelineConfig.CiPipeline var r1 error if rf, ok := ret.Get(0).(func([]int) ([]*pipelineConfig.CiPipeline, error)); ok { @@ -481,6 +582,10 @@ func (_m *CiPipelineRepository) FindByParentCiPipelineIds(parentCiPipelineIds [] func (_m *CiPipelineRepository) FindByParentIdAndType(parentCiPipelineId int, pipelineType string) ([]*pipelineConfig.CiPipeline, error) { ret := _m.Called(parentCiPipelineId, pipelineType) + if len(ret) == 0 { + panic("no return value specified for FindByParentIdAndType") + } + var r0 []*pipelineConfig.CiPipeline var r1 error if rf, ok := ret.Get(0).(func(int, string) ([]*pipelineConfig.CiPipeline, error)); ok { @@ -507,6 +612,10 @@ func (_m *CiPipelineRepository) FindByParentIdAndType(parentCiPipelineId int, pi func (_m *CiPipelineRepository) FindCiEnvMappingByCiPipelineId(ciPipelineId int) (*pipelineConfig.CiEnvMapping, error) { ret := _m.Called(ciPipelineId) + if len(ret) == 0 { + panic("no return value specified for FindCiEnvMappingByCiPipelineId") + } + var r0 *pipelineConfig.CiEnvMapping var r1 error if rf, ok := ret.Get(0).(func(int) (*pipelineConfig.CiEnvMapping, error)); ok { @@ -533,6 +642,10 @@ func (_m *CiPipelineRepository) FindCiEnvMappingByCiPipelineId(ciPipelineId int) func (_m *CiPipelineRepository) FindCiPipelineByAppIdAndEnvIds(appId int, envIds []int) ([]*pipelineConfig.CiPipeline, error) { ret := _m.Called(appId, envIds) + if len(ret) == 0 { + panic("no return value specified for FindCiPipelineByAppIdAndEnvIds") + } + var r0 []*pipelineConfig.CiPipeline var r1 error if rf, ok := ret.Get(0).(func(int, []int) ([]*pipelineConfig.CiPipeline, error)); ok { @@ -559,6 +672,10 @@ func (_m *CiPipelineRepository) FindCiPipelineByAppIdAndEnvIds(appId int, envIds func (_m *CiPipelineRepository) FindCiPipelineConfigsByIds(ids []int) ([]*pipelineConfig.CiPipeline, error) { ret := _m.Called(ids) + if len(ret) == 0 { + panic("no return value specified for FindCiPipelineConfigsByIds") + } + var r0 []*pipelineConfig.CiPipeline var r1 error if rf, ok := ret.Get(0).(func([]int) ([]*pipelineConfig.CiPipeline, error)); ok { @@ -585,6 +702,10 @@ func (_m *CiPipelineRepository) FindCiPipelineConfigsByIds(ids []int) ([]*pipeli func (_m *CiPipelineRepository) FindCiScriptsByCiPipelineId(ciPipelineId int) ([]*pipelineConfig.CiPipelineScript, error) { ret := _m.Called(ciPipelineId) + if len(ret) == 0 { + panic("no return value specified for FindCiScriptsByCiPipelineId") + } + var r0 []*pipelineConfig.CiPipelineScript var r1 error if rf, ok := ret.Get(0).(func(int) ([]*pipelineConfig.CiPipelineScript, error)); ok { @@ -611,6 +732,10 @@ func (_m *CiPipelineRepository) FindCiScriptsByCiPipelineId(ciPipelineId int) ([ func (_m *CiPipelineRepository) FindCiScriptsByCiPipelineIds(ciPipelineId []int) ([]*pipelineConfig.CiPipelineScript, error) { ret := _m.Called(ciPipelineId) + if len(ret) == 0 { + panic("no return value specified for FindCiScriptsByCiPipelineIds") + } + var r0 []*pipelineConfig.CiPipelineScript var r1 error if rf, ok := ret.Get(0).(func([]int) ([]*pipelineConfig.CiPipelineScript, error)); ok { @@ -637,6 +762,10 @@ func (_m *CiPipelineRepository) FindCiScriptsByCiPipelineIds(ciPipelineId []int) func (_m *CiPipelineRepository) FindExternalCiByAppId(appId int) ([]*pipelineConfig.ExternalCiPipeline, error) { ret := _m.Called(appId) + if len(ret) == 0 { + panic("no return value specified for FindExternalCiByAppId") + } + var r0 []*pipelineConfig.ExternalCiPipeline var r1 error if rf, ok := ret.Get(0).(func(int) ([]*pipelineConfig.ExternalCiPipeline, error)); ok { @@ -663,6 +792,10 @@ func (_m *CiPipelineRepository) FindExternalCiByAppId(appId int) ([]*pipelineCon func (_m *CiPipelineRepository) FindExternalCiByAppIds(appIds []int) ([]*pipelineConfig.ExternalCiPipeline, error) { ret := _m.Called(appIds) + if len(ret) == 0 { + panic("no return value specified for FindExternalCiByAppIds") + } + var r0 []*pipelineConfig.ExternalCiPipeline var r1 error if rf, ok := ret.Get(0).(func([]int) ([]*pipelineConfig.ExternalCiPipeline, error)); ok { @@ -689,6 +822,10 @@ func (_m *CiPipelineRepository) FindExternalCiByAppIds(appIds []int) ([]*pipelin func (_m *CiPipelineRepository) FindExternalCiByCiPipelineId(ciPipelineId int) (*pipelineConfig.ExternalCiPipeline, error) { ret := _m.Called(ciPipelineId) + if len(ret) == 0 { + panic("no return value specified for FindExternalCiByCiPipelineId") + } + var r0 *pipelineConfig.ExternalCiPipeline var r1 error if rf, ok := ret.Get(0).(func(int) (*pipelineConfig.ExternalCiPipeline, error)); ok { @@ -715,6 +852,10 @@ func (_m *CiPipelineRepository) FindExternalCiByCiPipelineId(ciPipelineId int) ( func (_m *CiPipelineRepository) FindExternalCiById(id int) (*pipelineConfig.ExternalCiPipeline, error) { ret := _m.Called(id) + if len(ret) == 0 { + panic("no return value specified for FindExternalCiById") + } + var r0 *pipelineConfig.ExternalCiPipeline var r1 error if rf, ok := ret.Get(0).(func(int) (*pipelineConfig.ExternalCiPipeline, error)); ok { @@ -741,6 +882,10 @@ func (_m *CiPipelineRepository) FindExternalCiById(id int) (*pipelineConfig.Exte func (_m *CiPipelineRepository) FindLinkedCiCount(ciPipelineId int) (int, error) { ret := _m.Called(ciPipelineId) + if len(ret) == 0 { + panic("no return value specified for FindLinkedCiCount") + } + var r0 int var r1 error if rf, ok := ret.Get(0).(func(int) (int, error)); ok { @@ -765,6 +910,10 @@ func (_m *CiPipelineRepository) FindLinkedCiCount(ciPipelineId int) (int, error) func (_m *CiPipelineRepository) FindNumberOfAppsWithCiPipeline(appIds []int) (int, error) { ret := _m.Called(appIds) + if len(ret) == 0 { + panic("no return value specified for FindNumberOfAppsWithCiPipeline") + } + var r0 int var r1 error if rf, ok := ret.Get(0).(func([]int) (int, error)); ok { @@ -789,6 +938,10 @@ func (_m *CiPipelineRepository) FindNumberOfAppsWithCiPipeline(appIds []int) (in func (_m *CiPipelineRepository) FindOneWithAppData(id int) (*pipelineConfig.CiPipeline, error) { ret := _m.Called(id) + if len(ret) == 0 { + panic("no return value specified for FindOneWithAppData") + } + var r0 *pipelineConfig.CiPipeline var r1 error if rf, ok := ret.Get(0).(func(int) (*pipelineConfig.CiPipeline, error)); ok { @@ -815,6 +968,10 @@ func (_m *CiPipelineRepository) FindOneWithAppData(id int) (*pipelineConfig.CiPi func (_m *CiPipelineRepository) FindParentCiPipelineMapByAppId(appId int) ([]*pipelineConfig.CiPipeline, []int, error) { ret := _m.Called(appId) + if len(ret) == 0 { + panic("no return value specified for FindParentCiPipelineMapByAppId") + } + var r0 []*pipelineConfig.CiPipeline var r1 []int var r2 error @@ -850,6 +1007,10 @@ func (_m *CiPipelineRepository) FindParentCiPipelineMapByAppId(appId int) ([]*pi func (_m *CiPipelineRepository) FindWithMinDataByCiPipelineId(id int) (*pipelineConfig.CiPipeline, error) { ret := _m.Called(id) + if len(ret) == 0 { + panic("no return value specified for FindWithMinDataByCiPipelineId") + } + var r0 *pipelineConfig.CiPipeline var r1 error if rf, ok := ret.Get(0).(func(int) (*pipelineConfig.CiPipeline, error)); ok { @@ -876,6 +1037,10 @@ func (_m *CiPipelineRepository) FindWithMinDataByCiPipelineId(id int) (*pipeline func (_m *CiPipelineRepository) GetCiPipelineByArtifactId(artifactId int) (*pipelineConfig.CiPipeline, error) { ret := _m.Called(artifactId) + if len(ret) == 0 { + panic("no return value specified for GetCiPipelineByArtifactId") + } + var r0 *pipelineConfig.CiPipeline var r1 error if rf, ok := ret.Get(0).(func(int) (*pipelineConfig.CiPipeline, error)); ok { @@ -899,20 +1064,24 @@ func (_m *CiPipelineRepository) GetCiPipelineByArtifactId(artifactId int) (*pipe } // GetDownStreamInfo provides a mock function with given fields: ctx, sourceCiPipelineId, appNameMatch, envNameMatch, req -func (_m *CiPipelineRepository) GetDownStreamInfo(ctx context.Context, sourceCiPipelineId int, appNameMatch string, envNameMatch string, req *pagination.RepositoryRequest) ([]bean.LinkedCIDetails, int, error) { +func (_m *CiPipelineRepository) GetDownStreamInfo(ctx context.Context, sourceCiPipelineId int, appNameMatch string, envNameMatch string, req *pagination.RepositoryRequest) ([]ciPipeline.LinkedCIDetails, int, error) { ret := _m.Called(ctx, sourceCiPipelineId, appNameMatch, envNameMatch, req) - var r0 []bean.LinkedCIDetails + if len(ret) == 0 { + panic("no return value specified for GetDownStreamInfo") + } + + var r0 []ciPipeline.LinkedCIDetails var r1 int var r2 error - if rf, ok := ret.Get(0).(func(context.Context, int, string, string, *pagination.RepositoryRequest) ([]bean.LinkedCIDetails, int, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, int, string, string, *pagination.RepositoryRequest) ([]ciPipeline.LinkedCIDetails, int, error)); ok { return rf(ctx, sourceCiPipelineId, appNameMatch, envNameMatch, req) } - if rf, ok := ret.Get(0).(func(context.Context, int, string, string, *pagination.RepositoryRequest) []bean.LinkedCIDetails); ok { + if rf, ok := ret.Get(0).(func(context.Context, int, string, string, *pagination.RepositoryRequest) []ciPipeline.LinkedCIDetails); ok { r0 = rf(ctx, sourceCiPipelineId, appNameMatch, envNameMatch, req) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]bean.LinkedCIDetails) + r0 = ret.Get(0).([]ciPipeline.LinkedCIDetails) } } @@ -935,6 +1104,10 @@ func (_m *CiPipelineRepository) GetDownStreamInfo(ctx context.Context, sourceCiP func (_m *CiPipelineRepository) GetExternalCiPipelineByArtifactId(artifactId int) (*pipelineConfig.ExternalCiPipeline, error) { ret := _m.Called(artifactId) + if len(ret) == 0 { + panic("no return value specified for GetExternalCiPipelineByArtifactId") + } + var r0 *pipelineConfig.ExternalCiPipeline var r1 error if rf, ok := ret.Get(0).(func(int) (*pipelineConfig.ExternalCiPipeline, error)); ok { @@ -961,6 +1134,10 @@ func (_m *CiPipelineRepository) GetExternalCiPipelineByArtifactId(artifactId int func (_m *CiPipelineRepository) GetLinkedCiPipelines(ctx context.Context, ciPipelineId int) ([]*pipelineConfig.CiPipeline, error) { ret := _m.Called(ctx, ciPipelineId) + if len(ret) == 0 { + panic("no return value specified for GetLinkedCiPipelines") + } + var r0 []*pipelineConfig.CiPipeline var r1 error if rf, ok := ret.Get(0).(func(context.Context, int) ([]*pipelineConfig.CiPipeline, error)); ok { @@ -987,6 +1164,10 @@ func (_m *CiPipelineRepository) GetLinkedCiPipelines(ctx context.Context, ciPipe func (_m *CiPipelineRepository) MarkCiPipelineScriptsInactiveByCiPipelineId(ciPipelineId int, tx *pg.Tx) error { ret := _m.Called(ciPipelineId, tx) + if len(ret) == 0 { + panic("no return value specified for MarkCiPipelineScriptsInactiveByCiPipelineId") + } + var r0 error if rf, ok := ret.Get(0).(func(int, *pg.Tx) error); ok { r0 = rf(ciPipelineId, tx) @@ -1001,6 +1182,10 @@ func (_m *CiPipelineRepository) MarkCiPipelineScriptsInactiveByCiPipelineId(ciPi func (_m *CiPipelineRepository) PipelineExistsByName(names []string) ([]string, error) { ret := _m.Called(names) + if len(ret) == 0 { + panic("no return value specified for PipelineExistsByName") + } + var r0 []string var r1 error if rf, ok := ret.Get(0).(func([]string) ([]string, error)); ok { @@ -1027,6 +1212,10 @@ func (_m *CiPipelineRepository) PipelineExistsByName(names []string) ([]string, func (_m *CiPipelineRepository) RollbackTx(tx *pg.Tx) error { ret := _m.Called(tx) + if len(ret) == 0 { + panic("no return value specified for RollbackTx") + } + var r0 error if rf, ok := ret.Get(0).(func(*pg.Tx) error); ok { r0 = rf(tx) @@ -1041,6 +1230,10 @@ func (_m *CiPipelineRepository) RollbackTx(tx *pg.Tx) error { func (_m *CiPipelineRepository) Save(pipeline *pipelineConfig.CiPipeline, tx *pg.Tx) error { ret := _m.Called(pipeline, tx) + if len(ret) == 0 { + panic("no return value specified for Save") + } + var r0 error if rf, ok := ret.Get(0).(func(*pipelineConfig.CiPipeline, *pg.Tx) error); ok { r0 = rf(pipeline, tx) @@ -1055,6 +1248,10 @@ func (_m *CiPipelineRepository) Save(pipeline *pipelineConfig.CiPipeline, tx *pg func (_m *CiPipelineRepository) SaveCiEnvMapping(cienvmapping *pipelineConfig.CiEnvMapping, tx *pg.Tx) error { ret := _m.Called(cienvmapping, tx) + if len(ret) == 0 { + panic("no return value specified for SaveCiEnvMapping") + } + var r0 error if rf, ok := ret.Get(0).(func(*pipelineConfig.CiEnvMapping, *pg.Tx) error); ok { r0 = rf(cienvmapping, tx) @@ -1069,6 +1266,10 @@ func (_m *CiPipelineRepository) SaveCiEnvMapping(cienvmapping *pipelineConfig.Ci func (_m *CiPipelineRepository) SaveCiPipelineScript(ciPipelineScript *pipelineConfig.CiPipelineScript, tx *pg.Tx) error { ret := _m.Called(ciPipelineScript, tx) + if len(ret) == 0 { + panic("no return value specified for SaveCiPipelineScript") + } + var r0 error if rf, ok := ret.Get(0).(func(*pipelineConfig.CiPipelineScript, *pg.Tx) error); ok { r0 = rf(ciPipelineScript, tx) @@ -1083,6 +1284,10 @@ func (_m *CiPipelineRepository) SaveCiPipelineScript(ciPipelineScript *pipelineC func (_m *CiPipelineRepository) SaveExternalCi(pipeline *pipelineConfig.ExternalCiPipeline, tx *pg.Tx) (*pipelineConfig.ExternalCiPipeline, error) { ret := _m.Called(pipeline, tx) + if len(ret) == 0 { + panic("no return value specified for SaveExternalCi") + } + var r0 *pipelineConfig.ExternalCiPipeline var r1 error if rf, ok := ret.Get(0).(func(*pipelineConfig.ExternalCiPipeline, *pg.Tx) (*pipelineConfig.ExternalCiPipeline, error)); ok { @@ -1109,6 +1314,10 @@ func (_m *CiPipelineRepository) SaveExternalCi(pipeline *pipelineConfig.External func (_m *CiPipelineRepository) StartTx() (*pg.Tx, error) { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for StartTx") + } + var r0 *pg.Tx var r1 error if rf, ok := ret.Get(0).(func() (*pg.Tx, error)); ok { @@ -1135,6 +1344,10 @@ func (_m *CiPipelineRepository) StartTx() (*pg.Tx, error) { func (_m *CiPipelineRepository) Update(pipeline *pipelineConfig.CiPipeline, tx *pg.Tx) error { ret := _m.Called(pipeline, tx) + if len(ret) == 0 { + panic("no return value specified for Update") + } + var r0 error if rf, ok := ret.Get(0).(func(*pipelineConfig.CiPipeline, *pg.Tx) error); ok { r0 = rf(pipeline, tx) @@ -1149,6 +1362,10 @@ func (_m *CiPipelineRepository) Update(pipeline *pipelineConfig.CiPipeline, tx * func (_m *CiPipelineRepository) UpdateCiEnvMapping(cienvmapping *pipelineConfig.CiEnvMapping, tx *pg.Tx) error { ret := _m.Called(cienvmapping, tx) + if len(ret) == 0 { + panic("no return value specified for UpdateCiEnvMapping") + } + var r0 error if rf, ok := ret.Get(0).(func(*pipelineConfig.CiEnvMapping, *pg.Tx) error); ok { r0 = rf(cienvmapping, tx) @@ -1163,6 +1380,10 @@ func (_m *CiPipelineRepository) UpdateCiEnvMapping(cienvmapping *pipelineConfig. func (_m *CiPipelineRepository) UpdateCiPipelineScript(script *pipelineConfig.CiPipelineScript, tx *pg.Tx) error { ret := _m.Called(script, tx) + if len(ret) == 0 { + panic("no return value specified for UpdateCiPipelineScript") + } + var r0 error if rf, ok := ret.Get(0).(func(*pipelineConfig.CiPipelineScript, *pg.Tx) error); ok { r0 = rf(script, tx) @@ -1177,6 +1398,10 @@ func (_m *CiPipelineRepository) UpdateCiPipelineScript(script *pipelineConfig.Ci func (_m *CiPipelineRepository) UpdateExternalCi(pipeline *pipelineConfig.ExternalCiPipeline, tx *pg.Tx) (*pipelineConfig.ExternalCiPipeline, error) { ret := _m.Called(pipeline, tx) + if len(ret) == 0 { + panic("no return value specified for UpdateExternalCi") + } + var r0 *pipelineConfig.ExternalCiPipeline var r1 error if rf, ok := ret.Get(0).(func(*pipelineConfig.ExternalCiPipeline, *pg.Tx) (*pipelineConfig.ExternalCiPipeline, error)); ok { diff --git a/internal/sql/repository/pipelineConfig/mocks/PipelineRepository.go b/internal/sql/repository/pipelineConfig/mocks/PipelineRepository.go index 6960bbf3000..4ab07daad28 100644 --- a/internal/sql/repository/pipelineConfig/mocks/PipelineRepository.go +++ b/internal/sql/repository/pipelineConfig/mocks/PipelineRepository.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.32.0. DO NOT EDIT. +// Code generated by mockery v2.42.0. DO NOT EDIT. package mocks @@ -20,6 +20,10 @@ type PipelineRepository struct { func (_m *PipelineRepository) Delete(id int, userId int32, tx *pg.Tx) error { ret := _m.Called(id, userId, tx) + if len(ret) == 0 { + panic("no return value specified for Delete") + } + var r0 error if rf, ok := ret.Get(0).(func(int, int32, *pg.Tx) error); ok { r0 = rf(id, userId, tx) @@ -34,6 +38,10 @@ func (_m *PipelineRepository) Delete(id int, userId int32, tx *pg.Tx) error { func (_m *PipelineRepository) FilterDeploymentDeleteRequestedPipelineIds(cdPipelineIds []int) (map[int]bool, error) { ret := _m.Called(cdPipelineIds) + if len(ret) == 0 { + panic("no return value specified for FilterDeploymentDeleteRequestedPipelineIds") + } + var r0 map[int]bool var r1 error if rf, ok := ret.Get(0).(func([]int) (map[int]bool, error)); ok { @@ -60,6 +68,10 @@ func (_m *PipelineRepository) FilterDeploymentDeleteRequestedPipelineIds(cdPipel func (_m *PipelineRepository) FindActiveByAppId(appId int) ([]*pipelineConfig.Pipeline, error) { ret := _m.Called(appId) + if len(ret) == 0 { + panic("no return value specified for FindActiveByAppId") + } + var r0 []*pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func(int) ([]*pipelineConfig.Pipeline, error)); ok { @@ -82,10 +94,44 @@ func (_m *PipelineRepository) FindActiveByAppId(appId int) ([]*pipelineConfig.Pi return r0, r1 } +// FindActiveByAppIdAndEnvId provides a mock function with given fields: appId, envId +func (_m *PipelineRepository) FindActiveByAppIdAndEnvId(appId int, envId int) (*pipelineConfig.Pipeline, error) { + ret := _m.Called(appId, envId) + + if len(ret) == 0 { + panic("no return value specified for FindActiveByAppIdAndEnvId") + } + + var r0 *pipelineConfig.Pipeline + var r1 error + if rf, ok := ret.Get(0).(func(int, int) (*pipelineConfig.Pipeline, error)); ok { + return rf(appId, envId) + } + if rf, ok := ret.Get(0).(func(int, int) *pipelineConfig.Pipeline); ok { + r0 = rf(appId, envId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*pipelineConfig.Pipeline) + } + } + + if rf, ok := ret.Get(1).(func(int, int) error); ok { + r1 = rf(appId, envId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // FindActiveByAppIdAndEnvironmentId provides a mock function with given fields: appId, environmentId func (_m *PipelineRepository) FindActiveByAppIdAndEnvironmentId(appId int, environmentId int) ([]*pipelineConfig.Pipeline, error) { ret := _m.Called(appId, environmentId) + if len(ret) == 0 { + panic("no return value specified for FindActiveByAppIdAndEnvironmentId") + } + var r0 []*pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func(int, int) ([]*pipelineConfig.Pipeline, error)); ok { @@ -112,6 +158,10 @@ func (_m *PipelineRepository) FindActiveByAppIdAndEnvironmentId(appId int, envir func (_m *PipelineRepository) FindActiveByAppIdAndEnvironmentIdV2() ([]*pipelineConfig.Pipeline, error) { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for FindActiveByAppIdAndEnvironmentIdV2") + } + var r0 []*pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func() ([]*pipelineConfig.Pipeline, error)); ok { @@ -138,6 +188,10 @@ func (_m *PipelineRepository) FindActiveByAppIdAndEnvironmentIdV2() ([]*pipeline func (_m *PipelineRepository) FindActiveByAppIdAndPipelineId(appId int, pipelineId int) ([]*pipelineConfig.Pipeline, error) { ret := _m.Called(appId, pipelineId) + if len(ret) == 0 { + panic("no return value specified for FindActiveByAppIdAndPipelineId") + } + var r0 []*pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func(int, int) ([]*pipelineConfig.Pipeline, error)); ok { @@ -164,6 +218,10 @@ func (_m *PipelineRepository) FindActiveByAppIdAndPipelineId(appId int, pipeline func (_m *PipelineRepository) FindActiveByAppIds(appIds []int) ([]*pipelineConfig.Pipeline, error) { ret := _m.Called(appIds) + if len(ret) == 0 { + panic("no return value specified for FindActiveByAppIds") + } + var r0 []*pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func([]int) ([]*pipelineConfig.Pipeline, error)); ok { @@ -190,6 +248,10 @@ func (_m *PipelineRepository) FindActiveByAppIds(appIds []int) ([]*pipelineConfi func (_m *PipelineRepository) FindActiveByEnvId(envId int) ([]*pipelineConfig.Pipeline, error) { ret := _m.Called(envId) + if len(ret) == 0 { + panic("no return value specified for FindActiveByEnvId") + } + var r0 []*pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func(int) ([]*pipelineConfig.Pipeline, error)); ok { @@ -216,6 +278,10 @@ func (_m *PipelineRepository) FindActiveByEnvId(envId int) ([]*pipelineConfig.Pi func (_m *PipelineRepository) FindActiveByEnvIdAndDeploymentType(environmentId int, deploymentAppType string, exclusionList []int, includeApps []int) ([]*pipelineConfig.Pipeline, error) { ret := _m.Called(environmentId, deploymentAppType, exclusionList, includeApps) + if len(ret) == 0 { + panic("no return value specified for FindActiveByEnvIdAndDeploymentType") + } + var r0 []*pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func(int, string, []int, []int) ([]*pipelineConfig.Pipeline, error)); ok { @@ -242,6 +308,10 @@ func (_m *PipelineRepository) FindActiveByEnvIdAndDeploymentType(environmentId i func (_m *PipelineRepository) FindActiveByEnvIds(envId []int) ([]*pipelineConfig.Pipeline, error) { ret := _m.Called(envId) + if len(ret) == 0 { + panic("no return value specified for FindActiveByEnvIds") + } + var r0 []*pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func([]int) ([]*pipelineConfig.Pipeline, error)); ok { @@ -268,6 +338,10 @@ func (_m *PipelineRepository) FindActiveByEnvIds(envId []int) ([]*pipelineConfig func (_m *PipelineRepository) FindActiveByInFilter(envId int, appIdIncludes []int) ([]*pipelineConfig.Pipeline, error) { ret := _m.Called(envId, appIdIncludes) + if len(ret) == 0 { + panic("no return value specified for FindActiveByInFilter") + } + var r0 []*pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func(int, []int) ([]*pipelineConfig.Pipeline, error)); ok { @@ -294,6 +368,10 @@ func (_m *PipelineRepository) FindActiveByInFilter(envId int, appIdIncludes []in func (_m *PipelineRepository) FindActiveByNotFilter(envId int, appIdExcludes []int) ([]*pipelineConfig.Pipeline, error) { ret := _m.Called(envId, appIdExcludes) + if len(ret) == 0 { + panic("no return value specified for FindActiveByNotFilter") + } + var r0 []*pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func(int, []int) ([]*pipelineConfig.Pipeline, error)); ok { @@ -316,10 +394,74 @@ func (_m *PipelineRepository) FindActiveByNotFilter(envId int, appIdExcludes []i return r0, r1 } +// FindActivePipelineAppIdsByEnvId provides a mock function with given fields: envId +func (_m *PipelineRepository) FindActivePipelineAppIdsByEnvId(envId int) ([]int, error) { + ret := _m.Called(envId) + + if len(ret) == 0 { + panic("no return value specified for FindActivePipelineAppIdsByEnvId") + } + + var r0 []int + var r1 error + if rf, ok := ret.Get(0).(func(int) ([]int, error)); ok { + return rf(envId) + } + if rf, ok := ret.Get(0).(func(int) []int); ok { + r0 = rf(envId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]int) + } + } + + if rf, ok := ret.Get(1).(func(int) error); ok { + r1 = rf(envId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// FindActivePipelineAppIdsByInFilter provides a mock function with given fields: envId, appIdIncludes +func (_m *PipelineRepository) FindActivePipelineAppIdsByInFilter(envId int, appIdIncludes []int) ([]int, error) { + ret := _m.Called(envId, appIdIncludes) + + if len(ret) == 0 { + panic("no return value specified for FindActivePipelineAppIdsByInFilter") + } + + var r0 []int + var r1 error + if rf, ok := ret.Get(0).(func(int, []int) ([]int, error)); ok { + return rf(envId, appIdIncludes) + } + if rf, ok := ret.Get(0).(func(int, []int) []int); ok { + r0 = rf(envId, appIdIncludes) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]int) + } + } + + if rf, ok := ret.Get(1).(func(int, []int) error); ok { + r1 = rf(envId, appIdIncludes) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // FindActivePipelineByEnvId provides a mock function with given fields: envId func (_m *PipelineRepository) FindActivePipelineByEnvId(envId int) ([]*pipelineConfig.Pipeline, error) { ret := _m.Called(envId) + if len(ret) == 0 { + panic("no return value specified for FindActivePipelineByEnvId") + } + var r0 []*pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func(int) ([]*pipelineConfig.Pipeline, error)); ok { @@ -346,6 +488,10 @@ func (_m *PipelineRepository) FindActivePipelineByEnvId(envId int) ([]*pipelineC func (_m *PipelineRepository) FindAllDeletedPipelineCountInLast24Hour() (int, error) { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for FindAllDeletedPipelineCountInLast24Hour") + } + var r0 int var r1 error if rf, ok := ret.Get(0).(func() (int, error)); ok { @@ -370,6 +516,10 @@ func (_m *PipelineRepository) FindAllDeletedPipelineCountInLast24Hour() (int, er func (_m *PipelineRepository) FindAllPipelineCreatedCountInLast24Hour() (int, error) { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for FindAllPipelineCreatedCountInLast24Hour") + } + var r0 int var r1 error if rf, ok := ret.Get(0).(func() (int, error)); ok { @@ -394,6 +544,10 @@ func (_m *PipelineRepository) FindAllPipelineCreatedCountInLast24Hour() (int, er func (_m *PipelineRepository) FindAllPipelinesByChartsOverrideAndAppIdAndChartId(chartOverridden bool, appId int, chartId int) ([]*pipelineConfig.Pipeline, error) { ret := _m.Called(chartOverridden, appId, chartId) + if len(ret) == 0 { + panic("no return value specified for FindAllPipelinesByChartsOverrideAndAppIdAndChartId") + } + var r0 []*pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func(bool, int, int) ([]*pipelineConfig.Pipeline, error)); ok { @@ -420,6 +574,10 @@ func (_m *PipelineRepository) FindAllPipelinesByChartsOverrideAndAppIdAndChartId func (_m *PipelineRepository) FindAppAndEnvDetailsByPipelineId(id int) (*pipelineConfig.Pipeline, error) { ret := _m.Called(id) + if len(ret) == 0 { + panic("no return value specified for FindAppAndEnvDetailsByPipelineId") + } + var r0 *pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func(int) (*pipelineConfig.Pipeline, error)); ok { @@ -446,6 +604,10 @@ func (_m *PipelineRepository) FindAppAndEnvDetailsByPipelineId(id int) (*pipelin func (_m *PipelineRepository) FindAppAndEnvironmentAndProjectByPipelineIds(pipelineIds []int) ([]*pipelineConfig.Pipeline, error) { ret := _m.Called(pipelineIds) + if len(ret) == 0 { + panic("no return value specified for FindAppAndEnvironmentAndProjectByPipelineIds") + } + var r0 []*pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func([]int) ([]*pipelineConfig.Pipeline, error)); ok { @@ -472,6 +634,10 @@ func (_m *PipelineRepository) FindAppAndEnvironmentAndProjectByPipelineIds(pipel func (_m *PipelineRepository) FindAutomaticByCiPipelineId(ciPipelineId int) ([]*pipelineConfig.Pipeline, error) { ret := _m.Called(ciPipelineId) + if len(ret) == 0 { + panic("no return value specified for FindAutomaticByCiPipelineId") + } + var r0 []*pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func(int) ([]*pipelineConfig.Pipeline, error)); ok { @@ -494,10 +660,44 @@ func (_m *PipelineRepository) FindAutomaticByCiPipelineId(ciPipelineId int) ([]* return r0, r1 } +// FindByAppIdToEnvIdsMapping provides a mock function with given fields: appIdToEnvIds +func (_m *PipelineRepository) FindByAppIdToEnvIdsMapping(appIdToEnvIds map[int][]int) ([]*pipelineConfig.Pipeline, error) { + ret := _m.Called(appIdToEnvIds) + + if len(ret) == 0 { + panic("no return value specified for FindByAppIdToEnvIdsMapping") + } + + var r0 []*pipelineConfig.Pipeline + var r1 error + if rf, ok := ret.Get(0).(func(map[int][]int) ([]*pipelineConfig.Pipeline, error)); ok { + return rf(appIdToEnvIds) + } + if rf, ok := ret.Get(0).(func(map[int][]int) []*pipelineConfig.Pipeline); ok { + r0 = rf(appIdToEnvIds) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*pipelineConfig.Pipeline) + } + } + + if rf, ok := ret.Get(1).(func(map[int][]int) error); ok { + r1 = rf(appIdToEnvIds) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // FindByCiPipelineId provides a mock function with given fields: ciPipelineId func (_m *PipelineRepository) FindByCiPipelineId(ciPipelineId int) ([]*pipelineConfig.Pipeline, error) { ret := _m.Called(ciPipelineId) + if len(ret) == 0 { + panic("no return value specified for FindByCiPipelineId") + } + var r0 []*pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func(int) ([]*pipelineConfig.Pipeline, error)); ok { @@ -524,6 +724,10 @@ func (_m *PipelineRepository) FindByCiPipelineId(ciPipelineId int) ([]*pipelineC func (_m *PipelineRepository) FindByCiPipelineIdsIn(ciPipelineIds []int) ([]*pipelineConfig.Pipeline, error) { ret := _m.Called(ciPipelineIds) + if len(ret) == 0 { + panic("no return value specified for FindByCiPipelineIdsIn") + } + var r0 []*pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func([]int) ([]*pipelineConfig.Pipeline, error)); ok { @@ -550,6 +754,10 @@ func (_m *PipelineRepository) FindByCiPipelineIdsIn(ciPipelineIds []int) ([]*pip func (_m *PipelineRepository) FindById(id int) (*pipelineConfig.Pipeline, error) { ret := _m.Called(id) + if len(ret) == 0 { + panic("no return value specified for FindById") + } + var r0 *pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func(int) (*pipelineConfig.Pipeline, error)); ok { @@ -576,6 +784,10 @@ func (_m *PipelineRepository) FindById(id int) (*pipelineConfig.Pipeline, error) func (_m *PipelineRepository) FindByIdEvenIfInactive(id int) (*pipelineConfig.Pipeline, error) { ret := _m.Called(id) + if len(ret) == 0 { + panic("no return value specified for FindByIdEvenIfInactive") + } + var r0 *pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func(int) (*pipelineConfig.Pipeline, error)); ok { @@ -602,6 +814,10 @@ func (_m *PipelineRepository) FindByIdEvenIfInactive(id int) (*pipelineConfig.Pi func (_m *PipelineRepository) FindByIdsIn(ids []int) ([]*pipelineConfig.Pipeline, error) { ret := _m.Called(ids) + if len(ret) == 0 { + panic("no return value specified for FindByIdsIn") + } + var r0 []*pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func([]int) ([]*pipelineConfig.Pipeline, error)); ok { @@ -628,6 +844,10 @@ func (_m *PipelineRepository) FindByIdsIn(ids []int) ([]*pipelineConfig.Pipeline func (_m *PipelineRepository) FindByIdsInAndEnvironment(ids []int, environmentId int) ([]*pipelineConfig.Pipeline, error) { ret := _m.Called(ids, environmentId) + if len(ret) == 0 { + panic("no return value specified for FindByIdsInAndEnvironment") + } + var r0 []*pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func([]int, int) ([]*pipelineConfig.Pipeline, error)); ok { @@ -654,6 +874,10 @@ func (_m *PipelineRepository) FindByIdsInAndEnvironment(ids []int, environmentId func (_m *PipelineRepository) FindByName(pipelineName string) (*pipelineConfig.Pipeline, error) { ret := _m.Called(pipelineName) + if len(ret) == 0 { + panic("no return value specified for FindByName") + } + var r0 *pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func(string) (*pipelineConfig.Pipeline, error)); ok { @@ -680,6 +904,10 @@ func (_m *PipelineRepository) FindByName(pipelineName string) (*pipelineConfig.P func (_m *PipelineRepository) FindByParentCiPipelineId(ciPipelineId int) ([]*pipelineConfig.Pipeline, error) { ret := _m.Called(ciPipelineId) + if len(ret) == 0 { + panic("no return value specified for FindByParentCiPipelineId") + } + var r0 []*pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func(int) ([]*pipelineConfig.Pipeline, error)); ok { @@ -706,6 +934,10 @@ func (_m *PipelineRepository) FindByParentCiPipelineId(ciPipelineId int) ([]*pip func (_m *PipelineRepository) FindByPipelineTriggerGitHash(gitHash string) (*pipelineConfig.Pipeline, error) { ret := _m.Called(gitHash) + if len(ret) == 0 { + panic("no return value specified for FindByPipelineTriggerGitHash") + } + var r0 *pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func(string) (*pipelineConfig.Pipeline, error)); ok { @@ -728,10 +960,72 @@ func (_m *PipelineRepository) FindByPipelineTriggerGitHash(gitHash string) (*pip return r0, r1 } +// FindDeploymentAppTypeByAppIdAndEnvId provides a mock function with given fields: appId, envId +func (_m *PipelineRepository) FindDeploymentAppTypeByAppIdAndEnvId(appId int, envId int) (string, error) { + ret := _m.Called(appId, envId) + + if len(ret) == 0 { + panic("no return value specified for FindDeploymentAppTypeByAppIdAndEnvId") + } + + var r0 string + var r1 error + if rf, ok := ret.Get(0).(func(int, int) (string, error)); ok { + return rf(appId, envId) + } + if rf, ok := ret.Get(0).(func(int, int) string); ok { + r0 = rf(appId, envId) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(int, int) error); ok { + r1 = rf(appId, envId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// FindDeploymentAppTypeByIds provides a mock function with given fields: ids +func (_m *PipelineRepository) FindDeploymentAppTypeByIds(ids []int) ([]*pipelineConfig.Pipeline, error) { + ret := _m.Called(ids) + + if len(ret) == 0 { + panic("no return value specified for FindDeploymentAppTypeByIds") + } + + var r0 []*pipelineConfig.Pipeline + var r1 error + if rf, ok := ret.Get(0).(func([]int) ([]*pipelineConfig.Pipeline, error)); ok { + return rf(ids) + } + if rf, ok := ret.Get(0).(func([]int) []*pipelineConfig.Pipeline); ok { + r0 = rf(ids) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*pipelineConfig.Pipeline) + } + } + + if rf, ok := ret.Get(1).(func([]int) error); ok { + r1 = rf(ids) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // FindDeploymentTypeByPipelineIds provides a mock function with given fields: cdPipelineIds func (_m *PipelineRepository) FindDeploymentTypeByPipelineIds(cdPipelineIds []int) (map[int]pipelineConfig.DeploymentObject, error) { ret := _m.Called(cdPipelineIds) + if len(ret) == 0 { + panic("no return value specified for FindDeploymentTypeByPipelineIds") + } + var r0 map[int]pipelineConfig.DeploymentObject var r1 error if rf, ok := ret.Get(0).(func([]int) (map[int]pipelineConfig.DeploymentObject, error)); ok { @@ -758,6 +1052,10 @@ func (_m *PipelineRepository) FindDeploymentTypeByPipelineIds(cdPipelineIds []in func (_m *PipelineRepository) FindIdsByAppIdsAndEnvironmentIds(appIds []int, environmentIds []int) ([]int, error) { ret := _m.Called(appIds, environmentIds) + if len(ret) == 0 { + panic("no return value specified for FindIdsByAppIdsAndEnvironmentIds") + } + var r0 []int var r1 error if rf, ok := ret.Get(0).(func([]int, []int) ([]int, error)); ok { @@ -784,6 +1082,10 @@ func (_m *PipelineRepository) FindIdsByAppIdsAndEnvironmentIds(appIds []int, env func (_m *PipelineRepository) FindIdsByProjectIdsAndEnvironmentIds(projectIds []int, environmentIds []int) ([]int, error) { ret := _m.Called(projectIds, environmentIds) + if len(ret) == 0 { + panic("no return value specified for FindIdsByProjectIdsAndEnvironmentIds") + } + var r0 []int var r1 error if rf, ok := ret.Get(0).(func([]int, []int) ([]int, error)); ok { @@ -810,6 +1112,10 @@ func (_m *PipelineRepository) FindIdsByProjectIdsAndEnvironmentIds(projectIds [] func (_m *PipelineRepository) FindNumberOfAppsWithCdPipeline(appIds []int) (int, error) { ret := _m.Called(appIds) + if len(ret) == 0 { + panic("no return value specified for FindNumberOfAppsWithCdPipeline") + } + var r0 int var r1 error if rf, ok := ret.Get(0).(func([]int) (int, error)); ok { @@ -834,6 +1140,10 @@ func (_m *PipelineRepository) FindNumberOfAppsWithCdPipeline(appIds []int) (int, func (_m *PipelineRepository) FindWithEnvironmentByCiIds(ctx context.Context, cIPipelineIds []int) ([]*pipelineConfig.Pipeline, error) { ret := _m.Called(ctx, cIPipelineIds) + if len(ret) == 0 { + panic("no return value specified for FindWithEnvironmentByCiIds") + } + var r0 []*pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func(context.Context, []int) ([]*pipelineConfig.Pipeline, error)); ok { @@ -860,6 +1170,10 @@ func (_m *PipelineRepository) FindWithEnvironmentByCiIds(ctx context.Context, cI func (_m *PipelineRepository) GetAppAndEnvDetailsForDeploymentAppTypePipeline(deploymentAppType string, clusterIds []int) ([]*pipelineConfig.Pipeline, error) { ret := _m.Called(deploymentAppType, clusterIds) + if len(ret) == 0 { + panic("no return value specified for GetAppAndEnvDetailsForDeploymentAppTypePipeline") + } + var r0 []*pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func(string, []int) ([]*pipelineConfig.Pipeline, error)); ok { @@ -886,6 +1200,10 @@ func (_m *PipelineRepository) GetAppAndEnvDetailsForDeploymentAppTypePipeline(de func (_m *PipelineRepository) GetArgoPipelineByArgoAppName(argoAppName string) (pipelineConfig.Pipeline, error) { ret := _m.Called(argoAppName) + if len(ret) == 0 { + panic("no return value specified for GetArgoPipelineByArgoAppName") + } + var r0 pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func(string) (pipelineConfig.Pipeline, error)); ok { @@ -910,6 +1228,10 @@ func (_m *PipelineRepository) GetArgoPipelineByArgoAppName(argoAppName string) ( func (_m *PipelineRepository) GetArgoPipelinesHavingLatestTriggerStuckInNonTerminalStatuses(deployedBeforeMinutes int, getPipelineDeployedWithinHours int) ([]*pipelineConfig.Pipeline, error) { ret := _m.Called(deployedBeforeMinutes, getPipelineDeployedWithinHours) + if len(ret) == 0 { + panic("no return value specified for GetArgoPipelinesHavingLatestTriggerStuckInNonTerminalStatuses") + } + var r0 []*pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func(int, int) ([]*pipelineConfig.Pipeline, error)); ok { @@ -936,6 +1258,10 @@ func (_m *PipelineRepository) GetArgoPipelinesHavingLatestTriggerStuckInNonTermi func (_m *PipelineRepository) GetArgoPipelinesHavingTriggersStuckInLastPossibleNonTerminalTimelines(pendingSinceSeconds int, timeForDegradation int) ([]*pipelineConfig.Pipeline, error) { ret := _m.Called(pendingSinceSeconds, timeForDegradation) + if len(ret) == 0 { + panic("no return value specified for GetArgoPipelinesHavingTriggersStuckInLastPossibleNonTerminalTimelines") + } + var r0 []*pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func(int, int) ([]*pipelineConfig.Pipeline, error)); ok { @@ -962,6 +1288,10 @@ func (_m *PipelineRepository) GetArgoPipelinesHavingTriggersStuckInLastPossibleN func (_m *PipelineRepository) GetByEnvOverrideId(envOverrideId int) ([]pipelineConfig.Pipeline, error) { ret := _m.Called(envOverrideId) + if len(ret) == 0 { + panic("no return value specified for GetByEnvOverrideId") + } + var r0 []pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func(int) ([]pipelineConfig.Pipeline, error)); ok { @@ -988,6 +1318,10 @@ func (_m *PipelineRepository) GetByEnvOverrideId(envOverrideId int) ([]pipelineC func (_m *PipelineRepository) GetByEnvOverrideIdAndEnvId(envOverrideId int, envId int) (pipelineConfig.Pipeline, error) { ret := _m.Called(envOverrideId, envId) + if len(ret) == 0 { + panic("no return value specified for GetByEnvOverrideIdAndEnvId") + } + var r0 pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func(int, int) (pipelineConfig.Pipeline, error)); ok { @@ -1012,6 +1346,10 @@ func (_m *PipelineRepository) GetByEnvOverrideIdAndEnvId(envOverrideId int, envI func (_m *PipelineRepository) GetConnection() *pg.DB { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for GetConnection") + } + var r0 *pg.DB if rf, ok := ret.Get(0).(func() *pg.DB); ok { r0 = rf() @@ -1024,34 +1362,14 @@ func (_m *PipelineRepository) GetConnection() *pg.DB { return r0 } -// GetPartiallyDeletedPipelineByStatus provides a mock function with given fields: appId, envId -func (_m *PipelineRepository) GetPartiallyDeletedPipelineByStatus(appId int, envId int) (pipelineConfig.Pipeline, error) { - ret := _m.Called(appId, envId) - - var r0 pipelineConfig.Pipeline - var r1 error - if rf, ok := ret.Get(0).(func(int, int) (pipelineConfig.Pipeline, error)); ok { - return rf(appId, envId) - } - if rf, ok := ret.Get(0).(func(int, int) pipelineConfig.Pipeline); ok { - r0 = rf(appId, envId) - } else { - r0 = ret.Get(0).(pipelineConfig.Pipeline) - } - - if rf, ok := ret.Get(1).(func(int, int) error); ok { - r1 = rf(appId, envId) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - // GetPostStageConfigById provides a mock function with given fields: id func (_m *PipelineRepository) GetPostStageConfigById(id int) (*pipelineConfig.Pipeline, error) { ret := _m.Called(id) + if len(ret) == 0 { + panic("no return value specified for GetPostStageConfigById") + } + var r0 *pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func(int) (*pipelineConfig.Pipeline, error)); ok { @@ -1074,10 +1392,32 @@ func (_m *PipelineRepository) GetPostStageConfigById(id int) (*pipelineConfig.Pi return r0, r1 } +// MarkPartiallyDeleted provides a mock function with given fields: id, userId, tx +func (_m *PipelineRepository) MarkPartiallyDeleted(id int, userId int32, tx *pg.Tx) error { + ret := _m.Called(id, userId, tx) + + if len(ret) == 0 { + panic("no return value specified for MarkPartiallyDeleted") + } + + var r0 error + if rf, ok := ret.Get(0).(func(int, int32, *pg.Tx) error); ok { + r0 = rf(id, userId, tx) + } else { + r0 = ret.Error(0) + } + + return r0 +} + // PipelineExists provides a mock function with given fields: pipelineName func (_m *PipelineRepository) PipelineExists(pipelineName string) (bool, error) { ret := _m.Called(pipelineName) + if len(ret) == 0 { + panic("no return value specified for PipelineExists") + } + var r0 bool var r1 error if rf, ok := ret.Get(0).(func(string) (bool, error)); ok { @@ -1102,6 +1442,10 @@ func (_m *PipelineRepository) PipelineExists(pipelineName string) (bool, error) func (_m *PipelineRepository) Save(pipeline []*pipelineConfig.Pipeline, tx *pg.Tx) error { ret := _m.Called(pipeline, tx) + if len(ret) == 0 { + panic("no return value specified for Save") + } + var r0 error if rf, ok := ret.Get(0).(func([]*pipelineConfig.Pipeline, *pg.Tx) error); ok { r0 = rf(pipeline, tx) @@ -1116,23 +1460,13 @@ func (_m *PipelineRepository) Save(pipeline []*pipelineConfig.Pipeline, tx *pg.T func (_m *PipelineRepository) SetDeploymentAppCreatedInPipeline(deploymentAppCreated bool, pipelineId int, userId int32) error { ret := _m.Called(deploymentAppCreated, pipelineId, userId) - var r0 error - if rf, ok := ret.Get(0).(func(bool, int, int32) error); ok { - r0 = rf(deploymentAppCreated, pipelineId, userId) - } else { - r0 = ret.Error(0) + if len(ret) == 0 { + panic("no return value specified for SetDeploymentAppCreatedInPipeline") } - return r0 -} - -// UndoDelete provides a mock function with given fields: id -func (_m *PipelineRepository) UndoDelete(id int) error { - ret := _m.Called(id) - var r0 error - if rf, ok := ret.Get(0).(func(int) error); ok { - r0 = rf(id) + if rf, ok := ret.Get(0).(func(bool, int, int32) error); ok { + r0 = rf(deploymentAppCreated, pipelineId, userId) } else { r0 = ret.Error(0) } @@ -1144,6 +1478,10 @@ func (_m *PipelineRepository) UndoDelete(id int) error { func (_m *PipelineRepository) UniqueAppEnvironmentPipelines() ([]*pipelineConfig.Pipeline, error) { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for UniqueAppEnvironmentPipelines") + } + var r0 []*pipelineConfig.Pipeline var r1 error if rf, ok := ret.Get(0).(func() ([]*pipelineConfig.Pipeline, error)); ok { @@ -1170,6 +1508,10 @@ func (_m *PipelineRepository) UniqueAppEnvironmentPipelines() ([]*pipelineConfig func (_m *PipelineRepository) Update(pipeline *pipelineConfig.Pipeline, tx *pg.Tx) error { ret := _m.Called(pipeline, tx) + if len(ret) == 0 { + panic("no return value specified for Update") + } + var r0 error if rf, ok := ret.Get(0).(func(*pipelineConfig.Pipeline, *pg.Tx) error); ok { r0 = rf(pipeline, tx) @@ -1184,6 +1526,10 @@ func (_m *PipelineRepository) Update(pipeline *pipelineConfig.Pipeline, tx *pg.T func (_m *PipelineRepository) UpdateCdPipelineAfterDeployment(deploymentAppType string, cdPipelineIdIncludes []int, userId int32, delete bool) error { ret := _m.Called(deploymentAppType, cdPipelineIdIncludes, userId, delete) + if len(ret) == 0 { + panic("no return value specified for UpdateCdPipelineAfterDeployment") + } + var r0 error if rf, ok := ret.Get(0).(func(string, []int, int32, bool) error); ok { r0 = rf(deploymentAppType, cdPipelineIdIncludes, userId, delete) @@ -1198,6 +1544,10 @@ func (_m *PipelineRepository) UpdateCdPipelineAfterDeployment(deploymentAppType func (_m *PipelineRepository) UpdateCdPipelineDeploymentAppInFilter(deploymentAppType string, cdPipelineIdIncludes []int, userId int32, deploymentAppCreated bool, delete bool) error { ret := _m.Called(deploymentAppType, cdPipelineIdIncludes, userId, deploymentAppCreated, delete) + if len(ret) == 0 { + panic("no return value specified for UpdateCdPipelineDeploymentAppInFilter") + } + var r0 error if rf, ok := ret.Get(0).(func(string, []int, int32, bool, bool) error); ok { r0 = rf(deploymentAppType, cdPipelineIdIncludes, userId, deploymentAppCreated, delete) @@ -1208,10 +1558,32 @@ func (_m *PipelineRepository) UpdateCdPipelineDeploymentAppInFilter(deploymentAp return r0 } +// UpdateCiPipelineId provides a mock function with given fields: tx, pipelineIds, ciPipelineId +func (_m *PipelineRepository) UpdateCiPipelineId(tx *pg.Tx, pipelineIds []int, ciPipelineId int) error { + ret := _m.Called(tx, pipelineIds, ciPipelineId) + + if len(ret) == 0 { + panic("no return value specified for UpdateCiPipelineId") + } + + var r0 error + if rf, ok := ret.Get(0).(func(*pg.Tx, []int, int) error); ok { + r0 = rf(tx, pipelineIds, ciPipelineId) + } else { + r0 = ret.Error(0) + } + + return r0 +} + // UpdateOldCiPipelineIdToNewCiPipelineId provides a mock function with given fields: tx, oldCiPipelineId, newCiPipelineId func (_m *PipelineRepository) UpdateOldCiPipelineIdToNewCiPipelineId(tx *pg.Tx, oldCiPipelineId int, newCiPipelineId int) error { ret := _m.Called(tx, oldCiPipelineId, newCiPipelineId) + if len(ret) == 0 { + panic("no return value specified for UpdateOldCiPipelineIdToNewCiPipelineId") + } + var r0 error if rf, ok := ret.Get(0).(func(*pg.Tx, int, int) error); ok { r0 = rf(tx, oldCiPipelineId, newCiPipelineId) diff --git a/pkg/build/artifacts/imageTagging/ImageTaggingService_test.go b/pkg/build/artifacts/imageTagging/ImageTaggingService_test.go index af77df20359..b066ca209f3 100644 --- a/pkg/build/artifacts/imageTagging/ImageTaggingService_test.go +++ b/pkg/build/artifacts/imageTagging/ImageTaggingService_test.go @@ -24,6 +24,8 @@ import ( "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" mocks2 "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/mocks" "github.com/devtron-labs/devtron/internal/util" + "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging/read" + mocks4 "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging/read/mocks" repository1 "github.com/devtron-labs/devtron/pkg/cluster/repository" mocks3 "github.com/devtron-labs/devtron/pkg/cluster/repository/mocks" "github.com/devtron-labs/devtron/pkg/pipeline/types" @@ -35,11 +37,12 @@ import ( func TestImageTaggingService(t *testing.T) { - //test data and mocks intialisation + // test data and mocks initialisation sugaredLogger, err := util.NewSugardLogger() assert.True(t, err == nil, err) appId, artifactId, ciPipelineId, userId := 1, 3, 1, 2 + appReleaseTags := []string{"devtron-v1.1.5", "devtron-v1.1.6"} testPayload := &types.ImageTaggingRequestDTO{ CreateTags: []*repository.ImageTag{{ TagName: "devtron-v1.1.6", @@ -65,35 +68,39 @@ func TestImageTaggingService(t *testing.T) { ExternalCi: false, } - initRepos := func() (ImageTaggingService, *mocks.ImageTaggingRepository, *mocks2.CiPipelineRepository, *mocks2.PipelineRepository, *mocks3.EnvironmentRepository) { + initRepos := func() (ImageTaggingService, *mocks4.ImageTaggingReadService, *mocks.ImageTaggingRepository, *mocks2.CiPipelineRepository, *mocks2.PipelineRepository, *mocks3.EnvironmentRepository) { mockedImageTaggingRepo := mocks.NewImageTaggingRepository(t) + mockedImageTaggingReadService := mocks4.NewImageTaggingReadService(t) mockedCiPipelineRepo := mocks2.NewCiPipelineRepository(t) mockedCdPipelineRepo := mocks2.NewPipelineRepository(t) mockedEnvironmentRepo := mocks3.NewEnvironmentRepository(t) - imageTaggingService := NewImageTaggingServiceImpl(mockedImageTaggingRepo, mockedCiPipelineRepo, mockedCdPipelineRepo, mockedEnvironmentRepo, sugaredLogger) + imageTaggingService := NewImageTaggingServiceImpl(mockedImageTaggingRepo, + mockedImageTaggingReadService, mockedCiPipelineRepo, mockedCdPipelineRepo, + mockedEnvironmentRepo, sugaredLogger) //mockedImageTaggingRepo.On("UpdateImageComment", &pg.Tx{}, mock.Anything).Return(nil) - return imageTaggingService, mockedImageTaggingRepo, mockedCiPipelineRepo, mockedCdPipelineRepo, mockedEnvironmentRepo + return imageTaggingService, mockedImageTaggingReadService, mockedImageTaggingRepo, mockedCiPipelineRepo, mockedCdPipelineRepo, mockedEnvironmentRepo } //test cases starts here t.Run("CreateOrUpdateImageTagging,Valid payload Request,expected: valid response with nil error", func(tt *testing.T) { //tt.SkipNow() - imageTaggingService, mockedImageTaggingRepo, mockedCiPipelineRepo, _, mockedEnvironmentRepo := initRepos() + imageTaggingService, mockedImageTaggingReadService, mockedImageTaggingRepo, mockedCiPipelineRepo, _, mockedEnvironmentRepo := initRepos() mockedImageTaggingRepo.On("SaveImageComment", &pg.Tx{}, mock.Anything).Return(nil) mockedImageTaggingRepo.On("SaveAuditLogsInBulk", &pg.Tx{}, mock.Anything).Return(nil) mockedImageTaggingRepo.On("UpdateReleaseTagInBulk", &pg.Tx{}, mock.Anything).Return(nil) mockedImageTaggingRepo.On("DeleteReleaseTagInBulk", &pg.Tx{}, mock.Anything).Return(nil) mockedImageTaggingRepo.On("SaveReleaseTagsInBulk", &pg.Tx{}, mock.Anything).Return(nil) mockedImageTaggingRepo.On("GetImageComment", artifactId).Return(testPayload.ImageComment, nil) - mockedImageTaggingRepo.On("GetTagsByAppId", appId).Return(append(testPayload.SoftDeleteTags, testPayload.CreateTags...), nil) - mockedImageTaggingRepo.On("getTagsByArtifactId", artifactId).Return(append(testPayload.SoftDeleteTags, testPayload.CreateTags...), nil) + mockedImageTaggingRepo.On("GetTagsByArtifactId", artifactId).Return(append(testPayload.SoftDeleteTags, testPayload.CreateTags...), nil) mockedCiPipelineRepo.On("FindByParentCiPipelineId", ciPipelineId).Return([]*pipelineConfig.CiPipeline{}, nil) mockedEnvironmentRepo.On("FindEnvLinkedWithCiPipelines", testPayload.ExternalCi, []int{ciPipelineId}).Return(nil, nil) mockedImageTaggingRepo.On("StartTx").Return(&pg.Tx{}, nil) mockedImageTaggingRepo.On("RollbackTx", &pg.Tx{}).Return(nil) mockedImageTaggingRepo.On("CommitTx", &pg.Tx{}).Return(nil) + mockedImageTaggingReadService.On("GetImageTaggingServiceConfig").Return(&read.ImageTaggingServiceConfig{HideImageTaggingHardDelete: false}) + mockedImageTaggingReadService.On("GetUniqueTagsByAppId", appId).Return(appReleaseTags, nil) res, err := imageTaggingService.CreateOrUpdateImageTagging(ciPipelineId, appId, artifactId, userId, testPayload) assert.NotNil(tt, res) assert.Nil(tt, err) @@ -105,11 +112,12 @@ func TestImageTaggingService(t *testing.T) { t.Run("CreateOrUpdateImageTagging,Valid Request payload, error in SoftDeleting Tags,expected: nil response with non nil error", func(tt *testing.T) { //tt.SkipNow() - imageTaggingService, mockedImageTaggingRepo, _, _, _ := initRepos() + imageTaggingService, mockedImageTaggingReadService, mockedImageTaggingRepo, _, _, _ := initRepos() softDeleteError := errors.New("error in updating image tags") mockedImageTaggingRepo.On("UpdateReleaseTagInBulk", &pg.Tx{}, mock.Anything).Return(softDeleteError) mockedImageTaggingRepo.On("StartTx").Return(&pg.Tx{}, nil) mockedImageTaggingRepo.On("RollbackTx", &pg.Tx{}).Return(nil) + mockedImageTaggingReadService.On("GetImageTaggingServiceConfig").Return(&read.ImageTaggingServiceConfig{HideImageTaggingHardDelete: false}) res, err := imageTaggingService.CreateOrUpdateImageTagging(ciPipelineId, appId, artifactId, userId, testPayload) assert.Nil(tt, res) @@ -120,12 +128,13 @@ func TestImageTaggingService(t *testing.T) { t.Run("Valid Request, error in HardDeleting Tags", func(tt *testing.T) { //tt.SkipNow() - imageTaggingService, mockedImageTaggingRepo, _, _, _ := initRepos() + imageTaggingService, mockedImageTaggingReadService, mockedImageTaggingRepo, _, _, _ := initRepos() hardDeleteError := errors.New("error in HardDeleting image tags") mockedImageTaggingRepo.On("DeleteReleaseTagInBulk", &pg.Tx{}, mock.Anything).Return(hardDeleteError) mockedImageTaggingRepo.On("StartTx").Return(&pg.Tx{}, nil) mockedImageTaggingRepo.On("RollbackTx", &pg.Tx{}).Return(nil) mockedImageTaggingRepo.On("UpdateReleaseTagInBulk", &pg.Tx{}, mock.Anything).Return(nil) + mockedImageTaggingReadService.On("GetImageTaggingServiceConfig").Return(&read.ImageTaggingServiceConfig{HideImageTaggingHardDelete: false}) res, err := imageTaggingService.CreateOrUpdateImageTagging(ciPipelineId, appId, artifactId, userId, testPayload) assert.Nil(tt, res) @@ -135,7 +144,7 @@ func TestImageTaggingService(t *testing.T) { t.Run("Valid Request, error in saveComment", func(tt *testing.T) { //tt.SkipNow() - imageTaggingService, mockedImageTaggingRepo, _, _, _ := initRepos() + imageTaggingService, mockedImageTaggingReadService, mockedImageTaggingRepo, _, _, _ := initRepos() saveCommentError := errors.New("error in saveComment") mockedImageTaggingRepo.On("SaveImageComment", &pg.Tx{}, mock.Anything).Return(saveCommentError) mockedImageTaggingRepo.On("DeleteReleaseTagInBulk", &pg.Tx{}, mock.Anything).Return(nil) @@ -144,6 +153,7 @@ func TestImageTaggingService(t *testing.T) { mockedImageTaggingRepo.On("UpdateReleaseTagInBulk", &pg.Tx{}, mock.Anything).Return(nil) mockedImageTaggingRepo.On("SaveReleaseTagsInBulk", &pg.Tx{}, mock.Anything).Return(nil) mockedImageTaggingRepo.On("GetImageComment", artifactId).Return(repository.ImageComment{}, nil) + mockedImageTaggingReadService.On("GetImageTaggingServiceConfig").Return(&read.ImageTaggingServiceConfig{HideImageTaggingHardDelete: false}) res, err := imageTaggingService.CreateOrUpdateImageTagging(ciPipelineId, appId, artifactId, userId, testPayload) assert.Nil(tt, res) @@ -153,7 +163,7 @@ func TestImageTaggingService(t *testing.T) { t.Run("Valid Request, error in SaveAuditLogsInBulk", func(tt *testing.T) { //tt.SkipNow() - imageTaggingService, mockedImageTaggingRepo, _, _, _ := initRepos() + imageTaggingService, mockedImageTaggingReadService, mockedImageTaggingRepo, _, _, _ := initRepos() saveAuditLogsInBulkError := errors.New("error in saveAuditLogsInBulk ") mockedImageTaggingRepo.On("SaveAuditLogsInBulk", &pg.Tx{}, mock.Anything).Return(saveAuditLogsInBulkError) mockedImageTaggingRepo.On("SaveImageComment", &pg.Tx{}, mock.Anything).Return(nil) @@ -163,6 +173,7 @@ func TestImageTaggingService(t *testing.T) { mockedImageTaggingRepo.On("UpdateReleaseTagInBulk", &pg.Tx{}, mock.Anything).Return(nil) mockedImageTaggingRepo.On("SaveReleaseTagsInBulk", &pg.Tx{}, mock.Anything).Return(nil) mockedImageTaggingRepo.On("GetImageComment", artifactId).Return(repository.ImageComment{}, nil) + mockedImageTaggingReadService.On("GetImageTaggingServiceConfig").Return(&read.ImageTaggingServiceConfig{HideImageTaggingHardDelete: false}) res, err := imageTaggingService.CreateOrUpdateImageTagging(ciPipelineId, appId, artifactId, userId, testPayload) assert.Nil(tt, res) @@ -173,9 +184,8 @@ func TestImageTaggingService(t *testing.T) { t.Run("Valid Request, error in GetTagsByAppId", func(tt *testing.T) { //tt.SkipNow() - imageTaggingService, mockedImageTaggingRepo, _, _, _ := initRepos() - GetTagsByAppIdError := errors.New("error in GetTagsByAppId ") - mockedImageTaggingRepo.On("GetTagsByAppId", appId).Return(nil, GetTagsByAppIdError) + imageTaggingService, mockedImageTaggingReadService, mockedImageTaggingRepo, _, _, _ := initRepos() + GetTagsByAppIdError := errors.New("error in GetTagsByAppId") mockedImageTaggingRepo.On("SaveAuditLogsInBulk", &pg.Tx{}, mock.Anything).Return(nil) mockedImageTaggingRepo.On("SaveImageComment", &pg.Tx{}, mock.Anything).Return(nil) mockedImageTaggingRepo.On("DeleteReleaseTagInBulk", &pg.Tx{}, mock.Anything).Return(nil) @@ -185,6 +195,8 @@ func TestImageTaggingService(t *testing.T) { mockedImageTaggingRepo.On("UpdateReleaseTagInBulk", &pg.Tx{}, mock.Anything).Return(nil) mockedImageTaggingRepo.On("SaveReleaseTagsInBulk", &pg.Tx{}, mock.Anything).Return(nil) mockedImageTaggingRepo.On("GetImageComment", artifactId).Return(repository.ImageComment{}, nil) + mockedImageTaggingReadService.On("GetImageTaggingServiceConfig").Return(&read.ImageTaggingServiceConfig{HideImageTaggingHardDelete: false}) + mockedImageTaggingReadService.On("GetUniqueTagsByAppId", appId).Return(nil, GetTagsByAppIdError) res, err := imageTaggingService.CreateOrUpdateImageTagging(ciPipelineId, appId, artifactId, userId, testPayload) assert.NotNil(tt, res) @@ -197,7 +209,7 @@ func TestImageTaggingService(t *testing.T) { t.Run("Valid Request, error in GetImageComment", func(tt *testing.T) { //tt.SkipNow() - imageTaggingService, mockedImageTaggingRepo, _, _, _ := initRepos() + imageTaggingService, mockedImageTaggingReadService, mockedImageTaggingRepo, _, _, _ := initRepos() GetImageCommentError := errors.New("error in GetImageComment ") mockedImageTaggingRepo.On("GetImageComment", artifactId).Return(repository.ImageComment{}, GetImageCommentError) mockedImageTaggingRepo.On("DeleteReleaseTagInBulk", &pg.Tx{}, mock.Anything).Return(nil) @@ -205,6 +217,7 @@ func TestImageTaggingService(t *testing.T) { mockedImageTaggingRepo.On("RollbackTx", &pg.Tx{}).Return(nil) mockedImageTaggingRepo.On("UpdateReleaseTagInBulk", &pg.Tx{}, mock.Anything).Return(nil) mockedImageTaggingRepo.On("SaveReleaseTagsInBulk", &pg.Tx{}, mock.Anything).Return(nil) + mockedImageTaggingReadService.On("GetImageTaggingServiceConfig").Return(&read.ImageTaggingServiceConfig{HideImageTaggingHardDelete: false}) testPayload.ImageComment.Id = 1 res, err := imageTaggingService.CreateOrUpdateImageTagging(ciPipelineId, appId, artifactId, userId, testPayload) @@ -218,7 +231,7 @@ func TestImageTaggingService(t *testing.T) { testPipelineId := 0 testError := fmt.Sprintf("error in fetching pipeline by pipelineId %v", testPipelineId) mockedCdPipelineRepo.On("FindById", testPipelineId).Return(nil, errors.New(testError)) - imageTaggingService := NewImageTaggingServiceImpl(nil, nil, mockedCdPipelineRepo, nil, sugaredLogger) + imageTaggingService := NewImageTaggingServiceImpl(nil, nil, nil, mockedCdPipelineRepo, nil, sugaredLogger) res, err := imageTaggingService.GetProdEnvByCdPipelineId(testPipelineId) assert.Equal(tt, false, res) assert.NotNil(tt, err) @@ -238,7 +251,7 @@ func TestImageTaggingService(t *testing.T) { } //testError := fmt.Sprintf("error in fetching pipeline by pipelineId %v", testPipelineId) mockedCdPipelineRepo.On("FindById", testPipelineId).Return(testPipeline, nil) - imageTaggingService := NewImageTaggingServiceImpl(nil, nil, mockedCdPipelineRepo, nil, sugaredLogger) + imageTaggingService := NewImageTaggingServiceImpl(nil, nil, nil, mockedCdPipelineRepo, nil, sugaredLogger) res, err := imageTaggingService.GetProdEnvByCdPipelineId(testPipelineId) assert.Equal(tt, true, res) assert.Nil(tt, err) @@ -261,7 +274,7 @@ func TestImageTaggingService(t *testing.T) { //testCiPipelinesResponse := []bean.CiPipeline mockedCdPipelineRepo.On("FindById", testPipelineId).Return(testPipeline, nil) mockedCiPipelineRepo.On("FindByParentCiPipelineId", testCiPipelineId).Return(nil, errors.New(testError)) - imageTaggingService := NewImageTaggingServiceImpl(nil, mockedCiPipelineRepo, mockedCdPipelineRepo, nil, sugaredLogger) + imageTaggingService := NewImageTaggingServiceImpl(nil, nil, mockedCiPipelineRepo, mockedCdPipelineRepo, nil, sugaredLogger) res, err := imageTaggingService.GetProdEnvByCdPipelineId(testPipelineId) assert.Equal(tt, false, res) assert.NotNil(tt, err) @@ -307,7 +320,7 @@ func TestImageTaggingService(t *testing.T) { mockedCiPipelineRepo.On("FindByParentCiPipelineId", testCiPipelineId).Return(testCipipelinesResp, nil) mockedEnvRepo.On("FindEnvLinkedWithCiPipelines", false, testCipipelineIds).Return(nil, errors.New(testError)) - imageTaggingService := NewImageTaggingServiceImpl(nil, mockedCiPipelineRepo, mockedCdPipelineRepo, mockedEnvRepo, sugaredLogger) + imageTaggingService := NewImageTaggingServiceImpl(nil, nil, mockedCiPipelineRepo, mockedCdPipelineRepo, mockedEnvRepo, sugaredLogger) res, err := imageTaggingService.GetProdEnvByCdPipelineId(testPipelineId) assert.Equal(tt, false, res) assert.NotNil(tt, err) @@ -361,7 +374,7 @@ func TestImageTaggingService(t *testing.T) { mockedEnvRepo.On("FindEnvLinkedWithCiPipelines", false, testCipipelineIds).Return(testEnvs, nil) //test the service - imageTaggingService := NewImageTaggingServiceImpl(nil, mockedCiPipelineRepo, mockedCdPipelineRepo, mockedEnvRepo, sugaredLogger) + imageTaggingService := NewImageTaggingServiceImpl(nil, nil, mockedCiPipelineRepo, mockedCdPipelineRepo, mockedEnvRepo, sugaredLogger) res, err := imageTaggingService.GetProdEnvByCdPipelineId(testPipelineId) assert.Equal(tt, false, res) assert.Nil(tt, err) @@ -414,7 +427,7 @@ func TestImageTaggingService(t *testing.T) { mockedCdPipelineRepo.On("FindById", testPipelineId).Return(testPipeline, nil) mockedCiPipelineRepo.On("FindByParentCiPipelineId", testCiPipelineId).Return(testCipipelinesResp, nil) mockedEnvRepo.On("FindEnvLinkedWithCiPipelines", false, testCipipelineIds).Return(testEnvs, nil) - imageTaggingService := NewImageTaggingServiceImpl(nil, mockedCiPipelineRepo, mockedCdPipelineRepo, mockedEnvRepo, sugaredLogger) + imageTaggingService := NewImageTaggingServiceImpl(nil, nil, mockedCiPipelineRepo, mockedCdPipelineRepo, mockedEnvRepo, sugaredLogger) res, err := imageTaggingService.GetProdEnvByCdPipelineId(testPipelineId) assert.Equal(tt, true, res) assert.Nil(tt, err) @@ -491,7 +504,7 @@ func TestImageTaggingService(t *testing.T) { assert.NotNil(ttt, err) assert.Equal(ttt, false, valid) } - imageTaggingService := NewImageTaggingServiceImpl(nil, nil, nil, nil, sugaredLogger) + imageTaggingService := NewImageTaggingServiceImpl(nil, nil, nil, nil, nil, sugaredLogger) tt.Run("valid payload", func(ttt *testing.T) { valid, err := imageTaggingService.ValidateImageTaggingRequest(&testImageTaggingRequest, appId, artifactId) @@ -544,7 +557,8 @@ func TestImageTaggingService(t *testing.T) { tt.Run("GetTagsDataMapByAppId, no error case", func(ttt *testing.T) { mockedImageTaggingRepo := mocks.NewImageTaggingRepository(tt) mockedImageTaggingRepo.On("GetTagsByAppId", appId).Return(testTags, nil) - imageTaggingService := NewImageTaggingServiceImpl(mockedImageTaggingRepo, nil, nil, nil, sugaredLogger) + mockedImageTaggingReadService := mocks4.NewImageTaggingReadService(t) + imageTaggingService := NewImageTaggingServiceImpl(mockedImageTaggingRepo, mockedImageTaggingReadService, nil, nil, nil, sugaredLogger) resMap, err := imageTaggingService.GetTagsDataMapByAppId(appId) assert.NotNil(ttt, resMap) assert.Nil(ttt, err) @@ -554,8 +568,9 @@ func TestImageTaggingService(t *testing.T) { tt.Run("GetTagsDataMapByAppId,GetTagsByAppId repo func throws error, return same error", func(ttt *testing.T) { testErr := "error in GetTagsByAppId" mockedImageTaggingRepo := mocks.NewImageTaggingRepository(tt) - mockedImageTaggingRepo.On("GetTagsByAppId", appId).Return(nil, errors.New(testErr)) - imageTaggingService := NewImageTaggingServiceImpl(mockedImageTaggingRepo, nil, nil, nil, sugaredLogger) + mockedImageTaggingRepo.On(":", appId).Return(nil, errors.New(testErr)) + mockedImageTaggingReadService := mocks4.NewImageTaggingReadService(t) + imageTaggingService := NewImageTaggingServiceImpl(mockedImageTaggingRepo, mockedImageTaggingReadService, nil, nil, nil, sugaredLogger) resMap, err := imageTaggingService.GetTagsDataMapByAppId(appId) assert.Nil(ttt, resMap) assert.NotNil(ttt, err) @@ -566,7 +581,8 @@ func TestImageTaggingService(t *testing.T) { tt.Run("GetImageCommentsDataMapByArtifactIds,no error case", func(ttt *testing.T) { mockedImageTaggingRepo := mocks.NewImageTaggingRepository(tt) mockedImageTaggingRepo.On("GetImageCommentsByArtifactIds", []int{testArtifactId1}).Return(testComments, nil) - imageTaggingService := NewImageTaggingServiceImpl(mockedImageTaggingRepo, nil, nil, nil, sugaredLogger) + mockedImageTaggingReadService := mocks4.NewImageTaggingReadService(t) + imageTaggingService := NewImageTaggingServiceImpl(mockedImageTaggingRepo, mockedImageTaggingReadService, nil, nil, nil, sugaredLogger) resMap, err := imageTaggingService.GetImageCommentsDataMapByArtifactIds([]int{testArtifactId1}) assert.NotNil(ttt, resMap) assert.Nil(ttt, err) @@ -577,7 +593,8 @@ func TestImageTaggingService(t *testing.T) { testErr := "error in GetImageCommentsByAppId" mockedImageTaggingRepo := mocks.NewImageTaggingRepository(tt) mockedImageTaggingRepo.On("GetImageCommentsByArtifactIds", []int{testArtifactId1}).Return(nil, errors.New(testErr)) - imageTaggingService := NewImageTaggingServiceImpl(mockedImageTaggingRepo, nil, nil, nil, sugaredLogger) + mockedImageTaggingReadService := mocks4.NewImageTaggingReadService(t) + imageTaggingService := NewImageTaggingServiceImpl(mockedImageTaggingRepo, mockedImageTaggingReadService, nil, nil, nil, sugaredLogger) resMap, err := imageTaggingService.GetImageCommentsDataMapByArtifactIds([]int{testArtifactId1}) assert.Nil(ttt, resMap) assert.NotNil(ttt, err) @@ -587,11 +604,12 @@ func TestImageTaggingService(t *testing.T) { }) - t.Run("getTagsByArtifactId, getTagsByArtifactId throws error", func(tt *testing.T) { - testErr := "error in getTagsByArtifactId" + t.Run("GetTagsByArtifactId, GetTagsByArtifactId throws error", func(tt *testing.T) { + testErr := "error in GetTagsByArtifactId" mockedImageTaggingRepo := mocks.NewImageTaggingRepository(tt) - mockedImageTaggingRepo.On("getTagsByArtifactId", artifactId).Return(nil, errors.New(testErr)) - imageTaggingService := NewImageTaggingServiceImpl(mockedImageTaggingRepo, nil, nil, nil, sugaredLogger) + mockedImageTaggingRepo.On("GetTagsByArtifactId", artifactId).Return(nil, errors.New(testErr)) + mockedImageTaggingReadService := mocks4.NewImageTaggingReadService(t) + imageTaggingService := NewImageTaggingServiceImpl(mockedImageTaggingRepo, mockedImageTaggingReadService, nil, nil, nil, sugaredLogger) tags, err := imageTaggingService.getTagsByArtifactId(artifactId) assert.Nil(tt, tags) assert.Equal(tt, 0, len(tags)) @@ -628,7 +646,9 @@ func TestImageTaggingService(t *testing.T) { mockedImageTaggingRepo.On("SaveReleaseTagsInBulk", tx, testImageTaggingRequest.CreateTags).Return(errors.New(testErr)) mockedImageTaggingRepo.On("UpdateReleaseTagInBulk", tx, testImageTaggingRequest.SoftDeleteTags).Return(nil) mockedImageTaggingRepo.On("DeleteReleaseTagInBulk", tx, testImageTaggingRequest.HardDeleteTags).Return(nil) - imageTaggingService := NewImageTaggingServiceImpl(mockedImageTaggingRepo, nil, nil, nil, sugaredLogger) + mockedImageTaggingReadService := mocks4.NewImageTaggingReadService(t) + mockedImageTaggingReadService.On("GetImageTaggingServiceConfig").Return(&read.ImageTaggingServiceConfig{HideImageTaggingHardDelete: false}) + imageTaggingService := NewImageTaggingServiceImpl(mockedImageTaggingRepo, mockedImageTaggingReadService, nil, nil, nil, sugaredLogger) res, err := imageTaggingService.performTagOperationsAndGetAuditList(tx, appId, artifactId, userId, &testImageTaggingRequest) assert.Nil(ttt, res) assert.NotNil(ttt, err) diff --git a/pkg/cluster/repository/mocks/EnvironmentRepository.go b/pkg/cluster/repository/mocks/EnvironmentRepository.go index fda0ef4ba8e..5080e4bb362 100644 --- a/pkg/cluster/repository/mocks/EnvironmentRepository.go +++ b/pkg/cluster/repository/mocks/EnvironmentRepository.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.32.0. DO NOT EDIT. +// Code generated by mockery v2.42.0. DO NOT EDIT. package mocks @@ -18,6 +18,10 @@ type EnvironmentRepository struct { func (_m *EnvironmentRepository) Create(mappings *repository.Environment) error { ret := _m.Called(mappings) + if len(ret) == 0 { + panic("no return value specified for Create") + } + var r0 error if rf, ok := ret.Get(0).(func(*repository.Environment) error); ok { r0 = rf(mappings) @@ -32,6 +36,10 @@ func (_m *EnvironmentRepository) Create(mappings *repository.Environment) error func (_m *EnvironmentRepository) FindAll() ([]repository.Environment, error) { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for FindAll") + } + var r0 []repository.Environment var r1 error if rf, ok := ret.Get(0).(func() ([]repository.Environment, error)); ok { @@ -58,6 +66,10 @@ func (_m *EnvironmentRepository) FindAll() ([]repository.Environment, error) { func (_m *EnvironmentRepository) FindAllActive() ([]*repository.Environment, error) { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for FindAllActive") + } + var r0 []*repository.Environment var r1 error if rf, ok := ret.Get(0).(func() ([]*repository.Environment, error)); ok { @@ -84,6 +96,10 @@ func (_m *EnvironmentRepository) FindAllActive() ([]*repository.Environment, err func (_m *EnvironmentRepository) FindAllActiveEnvOnlyDetails() ([]*repository.Environment, error) { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for FindAllActiveEnvOnlyDetails") + } + var r0 []*repository.Environment var r1 error if rf, ok := ret.Get(0).(func() ([]*repository.Environment, error)); ok { @@ -110,6 +126,10 @@ func (_m *EnvironmentRepository) FindAllActiveEnvOnlyDetails() ([]*repository.En func (_m *EnvironmentRepository) FindAllActiveEnvironmentCount() (int, error) { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for FindAllActiveEnvironmentCount") + } + var r0 int var r1 error if rf, ok := ret.Get(0).(func() (int, error)); ok { @@ -134,6 +154,10 @@ func (_m *EnvironmentRepository) FindAllActiveEnvironmentCount() (int, error) { func (_m *EnvironmentRepository) FindAllActiveWithFilter() ([]*repository.Environment, error) { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for FindAllActiveWithFilter") + } + var r0 []*repository.Environment var r1 error if rf, ok := ret.Get(0).(func() ([]*repository.Environment, error)); ok { @@ -160,6 +184,10 @@ func (_m *EnvironmentRepository) FindAllActiveWithFilter() ([]*repository.Enviro func (_m *EnvironmentRepository) FindByClusterId(clusterId int) ([]*repository.Environment, error) { ret := _m.Called(clusterId) + if len(ret) == 0 { + panic("no return value specified for FindByClusterId") + } + var r0 []*repository.Environment var r1 error if rf, ok := ret.Get(0).(func(int) ([]*repository.Environment, error)); ok { @@ -186,6 +214,10 @@ func (_m *EnvironmentRepository) FindByClusterId(clusterId int) ([]*repository.E func (_m *EnvironmentRepository) FindByClusterIdAndNamespace(namespaceClusterPair []*repository.ClusterNamespacePair) ([]*repository.Environment, error) { ret := _m.Called(namespaceClusterPair) + if len(ret) == 0 { + panic("no return value specified for FindByClusterIdAndNamespace") + } + var r0 []*repository.Environment var r1 error if rf, ok := ret.Get(0).(func([]*repository.ClusterNamespacePair) ([]*repository.Environment, error)); ok { @@ -212,6 +244,10 @@ func (_m *EnvironmentRepository) FindByClusterIdAndNamespace(namespaceClusterPai func (_m *EnvironmentRepository) FindByClusterIds(clusterIds []int) ([]*repository.Environment, error) { ret := _m.Called(clusterIds) + if len(ret) == 0 { + panic("no return value specified for FindByClusterIds") + } + var r0 []*repository.Environment var r1 error if rf, ok := ret.Get(0).(func([]int) ([]*repository.Environment, error)); ok { @@ -238,6 +274,10 @@ func (_m *EnvironmentRepository) FindByClusterIds(clusterIds []int) ([]*reposito func (_m *EnvironmentRepository) FindByClusterIdsWithFilter(clusterIds []int) ([]*repository.Environment, error) { ret := _m.Called(clusterIds) + if len(ret) == 0 { + panic("no return value specified for FindByClusterIdsWithFilter") + } + var r0 []*repository.Environment var r1 error if rf, ok := ret.Get(0).(func([]int) ([]*repository.Environment, error)); ok { @@ -264,6 +304,10 @@ func (_m *EnvironmentRepository) FindByClusterIdsWithFilter(clusterIds []int) ([ func (_m *EnvironmentRepository) FindByEnvName(envName string) ([]*repository.Environment, error) { ret := _m.Called(envName) + if len(ret) == 0 { + panic("no return value specified for FindByEnvName") + } + var r0 []*repository.Environment var r1 error if rf, ok := ret.Get(0).(func(string) ([]*repository.Environment, error)); ok { @@ -290,6 +334,10 @@ func (_m *EnvironmentRepository) FindByEnvName(envName string) ([]*repository.En func (_m *EnvironmentRepository) FindByEnvNameAndClusterIds(envName string, clusterIds []int) ([]*repository.Environment, error) { ret := _m.Called(envName, clusterIds) + if len(ret) == 0 { + panic("no return value specified for FindByEnvNameAndClusterIds") + } + var r0 []*repository.Environment var r1 error if rf, ok := ret.Get(0).(func(string, []int) ([]*repository.Environment, error)); ok { @@ -316,6 +364,10 @@ func (_m *EnvironmentRepository) FindByEnvNameAndClusterIds(envName string, clus func (_m *EnvironmentRepository) FindByEnvNameOrIdentifierOrNamespace(clusterId int, envName string, identifier string, namespace string) (*repository.Environment, error) { ret := _m.Called(clusterId, envName, identifier, namespace) + if len(ret) == 0 { + panic("no return value specified for FindByEnvNameOrIdentifierOrNamespace") + } + var r0 *repository.Environment var r1 error if rf, ok := ret.Get(0).(func(int, string, string, string) (*repository.Environment, error)); ok { @@ -342,6 +394,10 @@ func (_m *EnvironmentRepository) FindByEnvNameOrIdentifierOrNamespace(clusterId func (_m *EnvironmentRepository) FindById(id int) (*repository.Environment, error) { ret := _m.Called(id) + if len(ret) == 0 { + panic("no return value specified for FindById") + } + var r0 *repository.Environment var r1 error if rf, ok := ret.Get(0).(func(int) (*repository.Environment, error)); ok { @@ -368,6 +424,10 @@ func (_m *EnvironmentRepository) FindById(id int) (*repository.Environment, erro func (_m *EnvironmentRepository) FindByIdentifier(identifier string) (*repository.Environment, error) { ret := _m.Called(identifier) + if len(ret) == 0 { + panic("no return value specified for FindByIdentifier") + } + var r0 *repository.Environment var r1 error if rf, ok := ret.Get(0).(func(string) (*repository.Environment, error)); ok { @@ -394,6 +454,10 @@ func (_m *EnvironmentRepository) FindByIdentifier(identifier string) (*repositor func (_m *EnvironmentRepository) FindByIds(ids []*int) ([]*repository.Environment, error) { ret := _m.Called(ids) + if len(ret) == 0 { + panic("no return value specified for FindByIds") + } + var r0 []*repository.Environment var r1 error if rf, ok := ret.Get(0).(func([]*int) ([]*repository.Environment, error)); ok { @@ -420,6 +484,10 @@ func (_m *EnvironmentRepository) FindByIds(ids []*int) ([]*repository.Environmen func (_m *EnvironmentRepository) FindByName(name string) (*repository.Environment, error) { ret := _m.Called(name) + if len(ret) == 0 { + panic("no return value specified for FindByName") + } + var r0 *repository.Environment var r1 error if rf, ok := ret.Get(0).(func(string) (*repository.Environment, error)); ok { @@ -446,6 +514,10 @@ func (_m *EnvironmentRepository) FindByName(name string) (*repository.Environmen func (_m *EnvironmentRepository) FindByNameOrIdentifier(name string, identifier string) (*repository.Environment, error) { ret := _m.Called(name, identifier) + if len(ret) == 0 { + panic("no return value specified for FindByNameOrIdentifier") + } + var r0 *repository.Environment var r1 error if rf, ok := ret.Get(0).(func(string, string) (*repository.Environment, error)); ok { @@ -472,6 +544,10 @@ func (_m *EnvironmentRepository) FindByNameOrIdentifier(name string, identifier func (_m *EnvironmentRepository) FindByNames(envNames []string) ([]*repository.Environment, error) { ret := _m.Called(envNames) + if len(ret) == 0 { + panic("no return value specified for FindByNames") + } + var r0 []*repository.Environment var r1 error if rf, ok := ret.Get(0).(func([]string) ([]*repository.Environment, error)); ok { @@ -498,6 +574,10 @@ func (_m *EnvironmentRepository) FindByNames(envNames []string) ([]*repository.E func (_m *EnvironmentRepository) FindByNamespaceAndClusterName(namespaces string, clusterName string) (*repository.Environment, error) { ret := _m.Called(namespaces, clusterName) + if len(ret) == 0 { + panic("no return value specified for FindByNamespaceAndClusterName") + } + var r0 *repository.Environment var r1 error if rf, ok := ret.Get(0).(func(string, string) (*repository.Environment, error)); ok { @@ -520,10 +600,44 @@ func (_m *EnvironmentRepository) FindByNamespaceAndClusterName(namespaces string return r0, r1 } +// FindEnvByNameWithClusterDetails provides a mock function with given fields: envName +func (_m *EnvironmentRepository) FindEnvByNameWithClusterDetails(envName string) (*repository.Environment, error) { + ret := _m.Called(envName) + + if len(ret) == 0 { + panic("no return value specified for FindEnvByNameWithClusterDetails") + } + + var r0 *repository.Environment + var r1 error + if rf, ok := ret.Get(0).(func(string) (*repository.Environment, error)); ok { + return rf(envName) + } + if rf, ok := ret.Get(0).(func(string) *repository.Environment); ok { + r0 = rf(envName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*repository.Environment) + } + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(envName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // FindEnvClusterInfosByIds provides a mock function with given fields: _a0 func (_m *EnvironmentRepository) FindEnvClusterInfosByIds(_a0 []int) ([]*repository.EnvCluserInfo, error) { ret := _m.Called(_a0) + if len(ret) == 0 { + panic("no return value specified for FindEnvClusterInfosByIds") + } + var r0 []*repository.EnvCluserInfo var r1 error if rf, ok := ret.Get(0).(func([]int) ([]*repository.EnvCluserInfo, error)); ok { @@ -550,6 +664,10 @@ func (_m *EnvironmentRepository) FindEnvClusterInfosByIds(_a0 []int) ([]*reposit func (_m *EnvironmentRepository) FindEnvLinkedWithCiPipelines(externalCi bool, ciPipelineIds []int) ([]*repository.Environment, error) { ret := _m.Called(externalCi, ciPipelineIds) + if len(ret) == 0 { + panic("no return value specified for FindEnvLinkedWithCiPipelines") + } + var r0 []*repository.Environment var r1 error if rf, ok := ret.Get(0).(func(bool, []int) ([]*repository.Environment, error)); ok { @@ -572,10 +690,42 @@ func (_m *EnvironmentRepository) FindEnvLinkedWithCiPipelines(externalCi bool, c return r0, r1 } +// FindIdByName provides a mock function with given fields: name +func (_m *EnvironmentRepository) FindIdByName(name string) (int, error) { + ret := _m.Called(name) + + if len(ret) == 0 { + panic("no return value specified for FindIdByName") + } + + var r0 int + var r1 error + if rf, ok := ret.Get(0).(func(string) (int, error)); ok { + return rf(name) + } + if rf, ok := ret.Get(0).(func(string) int); ok { + r0 = rf(name) + } else { + r0 = ret.Get(0).(int) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(name) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // FindIdsByNames provides a mock function with given fields: envNames func (_m *EnvironmentRepository) FindIdsByNames(envNames []string) ([]int, error) { ret := _m.Called(envNames) + if len(ret) == 0 { + panic("no return value specified for FindIdsByNames") + } + var r0 []int var r1 error if rf, ok := ret.Get(0).(func([]string) ([]int, error)); ok { @@ -602,6 +752,10 @@ func (_m *EnvironmentRepository) FindIdsByNames(envNames []string) ([]int, error func (_m *EnvironmentRepository) FindOne(environment string) (*repository.Environment, error) { ret := _m.Called(environment) + if len(ret) == 0 { + panic("no return value specified for FindOne") + } + var r0 *repository.Environment var r1 error if rf, ok := ret.Get(0).(func(string) (*repository.Environment, error)); ok { @@ -628,6 +782,10 @@ func (_m *EnvironmentRepository) FindOne(environment string) (*repository.Enviro func (_m *EnvironmentRepository) FindOneByNamespaceAndClusterId(namespace string, clusterId int) (*repository.Environment, error) { ret := _m.Called(namespace, clusterId) + if len(ret) == 0 { + panic("no return value specified for FindOneByNamespaceAndClusterId") + } + var r0 *repository.Environment var r1 error if rf, ok := ret.Get(0).(func(string, int) (*repository.Environment, error)); ok { @@ -654,6 +812,10 @@ func (_m *EnvironmentRepository) FindOneByNamespaceAndClusterId(namespace string func (_m *EnvironmentRepository) GetConnection() *pg.DB { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for GetConnection") + } + var r0 *pg.DB if rf, ok := ret.Get(0).(func() *pg.DB); ok { r0 = rf() @@ -670,6 +832,10 @@ func (_m *EnvironmentRepository) GetConnection() *pg.DB { func (_m *EnvironmentRepository) MarkEnvironmentDeleted(mappings *repository.Environment, tx *pg.Tx) error { ret := _m.Called(mappings, tx) + if len(ret) == 0 { + panic("no return value specified for MarkEnvironmentDeleted") + } + var r0 error if rf, ok := ret.Get(0).(func(*repository.Environment, *pg.Tx) error); ok { r0 = rf(mappings, tx) @@ -684,6 +850,10 @@ func (_m *EnvironmentRepository) MarkEnvironmentDeleted(mappings *repository.Env func (_m *EnvironmentRepository) Update(mappings *repository.Environment) error { ret := _m.Called(mappings) + if len(ret) == 0 { + panic("no return value specified for Update") + } + var r0 error if rf, ok := ret.Get(0).(func(*repository.Environment) error); ok { r0 = rf(mappings) From fb3b7e9553c5a048315138001b315695cd847297 Mon Sep 17 00:00:00 2001 From: Ash-exp Date: Tue, 12 Nov 2024 00:08:56 +0530 Subject: [PATCH 6/7] added mock file --- .../read/mocks/ImageTaggingReadService.go | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 pkg/build/artifacts/imageTagging/read/mocks/ImageTaggingReadService.go diff --git a/pkg/build/artifacts/imageTagging/read/mocks/ImageTaggingReadService.go b/pkg/build/artifacts/imageTagging/read/mocks/ImageTaggingReadService.go new file mode 100644 index 00000000000..1569e7007ee --- /dev/null +++ b/pkg/build/artifacts/imageTagging/read/mocks/ImageTaggingReadService.go @@ -0,0 +1,107 @@ +// Code generated by mockery v2.42.0. DO NOT EDIT. + +package mocks + +import ( + read "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging/read" + mock "github.com/stretchr/testify/mock" +) + +// ImageTaggingReadService is an autogenerated mock type for the ImageTaggingReadService type +type ImageTaggingReadService struct { + mock.Mock +} + +// GetImageTaggingServiceConfig provides a mock function with given fields: +func (_m *ImageTaggingReadService) GetImageTaggingServiceConfig() *read.ImageTaggingServiceConfig { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetImageTaggingServiceConfig") + } + + var r0 *read.ImageTaggingServiceConfig + if rf, ok := ret.Get(0).(func() *read.ImageTaggingServiceConfig); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*read.ImageTaggingServiceConfig) + } + } + + return r0 +} + +// GetTagNamesByArtifactId provides a mock function with given fields: artifactId +func (_m *ImageTaggingReadService) GetTagNamesByArtifactId(artifactId int) ([]string, error) { + ret := _m.Called(artifactId) + + if len(ret) == 0 { + panic("no return value specified for GetTagNamesByArtifactId") + } + + var r0 []string + var r1 error + if rf, ok := ret.Get(0).(func(int) ([]string, error)); ok { + return rf(artifactId) + } + if rf, ok := ret.Get(0).(func(int) []string); ok { + r0 = rf(artifactId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + if rf, ok := ret.Get(1).(func(int) error); ok { + r1 = rf(artifactId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetUniqueTagsByAppId provides a mock function with given fields: appId +func (_m *ImageTaggingReadService) GetUniqueTagsByAppId(appId int) ([]string, error) { + ret := _m.Called(appId) + + if len(ret) == 0 { + panic("no return value specified for GetUniqueTagsByAppId") + } + + var r0 []string + var r1 error + if rf, ok := ret.Get(0).(func(int) ([]string, error)); ok { + return rf(appId) + } + if rf, ok := ret.Get(0).(func(int) []string); ok { + r0 = rf(appId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + if rf, ok := ret.Get(1).(func(int) error); ok { + r1 = rf(appId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NewImageTaggingReadService creates a new instance of ImageTaggingReadService. 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 NewImageTaggingReadService(t interface { + mock.TestingT + Cleanup(func()) +}) *ImageTaggingReadService { + mock := &ImageTaggingReadService{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} From b75f7118450f232e3d7c13a9ce176678895da843 Mon Sep 17 00:00:00 2001 From: Ash-exp Date: Tue, 12 Nov 2024 00:10:41 +0530 Subject: [PATCH 7/7] fix: TestImageTaggingService unit test cases --- pkg/build/artifacts/imageTagging/ImageTaggingService_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/build/artifacts/imageTagging/ImageTaggingService_test.go b/pkg/build/artifacts/imageTagging/ImageTaggingService_test.go index b066ca209f3..e8c756cd06b 100644 --- a/pkg/build/artifacts/imageTagging/ImageTaggingService_test.go +++ b/pkg/build/artifacts/imageTagging/ImageTaggingService_test.go @@ -568,7 +568,7 @@ func TestImageTaggingService(t *testing.T) { tt.Run("GetTagsDataMapByAppId,GetTagsByAppId repo func throws error, return same error", func(ttt *testing.T) { testErr := "error in GetTagsByAppId" mockedImageTaggingRepo := mocks.NewImageTaggingRepository(tt) - mockedImageTaggingRepo.On(":", appId).Return(nil, errors.New(testErr)) + mockedImageTaggingRepo.On("GetTagsByAppId", appId).Return(nil, errors.New(testErr)) mockedImageTaggingReadService := mocks4.NewImageTaggingReadService(t) imageTaggingService := NewImageTaggingServiceImpl(mockedImageTaggingRepo, mockedImageTaggingReadService, nil, nil, nil, sugaredLogger) resMap, err := imageTaggingService.GetTagsDataMapByAppId(appId)