diff --git a/api/handler/v1beta1/job_spec.go b/api/handler/v1beta1/job_spec.go index e09b336b8a..27a931fce5 100644 --- a/api/handler/v1beta1/job_spec.go +++ b/api/handler/v1beta1/job_spec.go @@ -399,6 +399,7 @@ func (sv *JobSpecServiceServer) GetJobSpecifications(ctx context.Context, req *p JobName: req.GetJobName(), ResourceDestination: req.GetResourceDestination(), NamespaceName: req.GetNamespaceName(), + IncludeDeleted: req.GetIncludeDeleted(), } jobSpecs, err := sv.jobSvc.GetByFilter(ctx, jobSpecFilter) if err != nil { diff --git a/api/handler/v1beta1/job_spec_test.go b/api/handler/v1beta1/job_spec_test.go index 57cd76ddb1..16f6d25513 100644 --- a/api/handler/v1beta1/job_spec_test.go +++ b/api/handler/v1beta1/job_spec_test.go @@ -375,8 +375,8 @@ func (s *JobSpecServiceServerTestSuite) TestGetJobSpecification_Fail_JobServiceG } func (s *JobSpecServiceServerTestSuite) TestGetJobSpecifications_Success() { - req := &pb.GetJobSpecificationsRequest{JobName: "job-1", NamespaceName: "namespace-1"} - jobSpecFilter := models.JobSpecFilter{JobName: req.GetJobName(), NamespaceName: req.GetNamespaceName()} + req := &pb.GetJobSpecificationsRequest{JobName: "job-1", NamespaceName: "namespace-1", IncludeDeleted: true} + jobSpecFilter := models.JobSpecFilter{JobName: req.GetJobName(), NamespaceName: req.GetNamespaceName(), IncludeDeleted: req.GetIncludeDeleted()} execUnit1 := new(mock.YamlMod) execUnit1.On("PluginInfo").Return(&models.PluginInfoResponse{Name: "task"}, nil) diff --git a/internal/store/postgres/job_spec_repository.go b/internal/store/postgres/job_spec_repository.go index f49fa15b77..80d7a2c538 100644 --- a/internal/store/postgres/job_spec_repository.go +++ b/internal/store/postgres/job_spec_repository.go @@ -32,53 +32,68 @@ func NewJobSpecRepository(db *gorm.DB, adapter *JobSpecAdapter) (store.JobSpecRe }, nil } -func (j jobSpecRepository) GetAllByProjectName(ctx context.Context, projectName string) ([]models.JobSpec, error) { - var jobs []Job - if err := j.db.WithContext(ctx). +func (j jobSpecRepository) GetAllByProjectName(ctx context.Context, projectName string, includeDeleted bool) ([]models.JobSpec, error) { + query := j.db.WithContext(ctx). Preload("Namespace"). Preload("Project"). Joins("Project"). - Where(`"Project"."name" = ?`, projectName). - Find(&jobs).Error; err != nil { + Where(`"Project"."name" = ?`, projectName) + + if includeDeleted { + query = query.Unscoped() + } + + var jobs []Job + if err := query.Find(&jobs).Error; err != nil { return nil, err } return j.toJobSpecs(jobs) } -func (j jobSpecRepository) GetAllByProjectNameAndNamespaceName(ctx context.Context, projectName, namespaceName string) ([]models.JobSpec, error) { - var jobs []Job - if err := j.db.WithContext(ctx). +func (j jobSpecRepository) GetAllByProjectNameAndNamespaceName(ctx context.Context, projectName, namespaceName string, includeDeleted bool) ([]models.JobSpec, error) { + query := j.db.WithContext(ctx). Preload("Namespace"). Preload("Project"). Joins("Project"). Joins("Namespace"). - Where(`"Project"."name" = ? and "Namespace"."name" = ?`, projectName, namespaceName). - Find(&jobs).Error; err != nil { + Where(`"Project"."name" = ? and "Namespace"."name" = ?`, projectName, namespaceName) + + if includeDeleted { + query = query.Unscoped() + } + + var jobs []Job + if err := query.Find(&jobs).Error; err != nil { return nil, err } return j.toJobSpecs(jobs) } -func (j jobSpecRepository) GetByNameAndProjectName(ctx context.Context, name, projectName string) (models.JobSpec, error) { - job, err := j.getByNameAndProjectName(ctx, name, projectName) +func (j jobSpecRepository) GetByNameAndProjectName(ctx context.Context, name, projectName string, includeDeleted bool) (models.JobSpec, error) { + job, err := j.getByNameAndProjectName(ctx, name, projectName, includeDeleted) if err != nil { return models.JobSpec{}, err } return j.adapter.ToSpec(job) } -func (j jobSpecRepository) GetByResourceDestinationURN(ctx context.Context, resourceDestinationURN string) ([]models.JobSpec, error) { - var jobs []Job - if err := j.db.WithContext(ctx). +func (j jobSpecRepository) GetByResourceDestinationURN(ctx context.Context, resourceDestinationURN string, includeDeleted bool) ([]models.JobSpec, error) { + query := j.db.WithContext(ctx). Preload("Namespace"). Preload("Project"). - Where("destination = ?", resourceDestinationURN). - Find(&jobs).Error; err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - return []models.JobSpec{}, store.ErrResourceNotFound - } + Where("destination = ?", resourceDestinationURN) + + if includeDeleted { + query = query.Unscoped() + } + + var jobs []Job + if err := query.Find(&jobs).Error; err != nil { return []models.JobSpec{}, err } + if len(jobs) == 0 { + return []models.JobSpec{}, store.ErrResourceNotFound + } return j.toJobSpecs(jobs) } @@ -156,7 +171,7 @@ func (j jobSpecRepository) Save(ctx context.Context, incomingJobSpec models.JobS return err } - existingJob, err := j.getByNameAndProjectName(ctx, incomingJob.Name, incomingJob.Project.Name) + existingJob, err := j.getByNameAndProjectName(ctx, incomingJob.Name, incomingJob.Project.Name, false) if errors.Is(err, store.ErrResourceNotFound) { return j.insert(ctx, incomingJob) } else if err != nil { @@ -181,14 +196,19 @@ func (j jobSpecRepository) DeleteByID(ctx context.Context, id uuid.UUID) error { }) } -func (j jobSpecRepository) getByNameAndProjectName(ctx context.Context, name, projectName string) (Job, error) { - var job Job - if err := j.db.WithContext(ctx). +func (j jobSpecRepository) getByNameAndProjectName(ctx context.Context, name, projectName string, includeDeleted bool) (Job, error) { + query := j.db.WithContext(ctx). Preload("Namespace"). Preload("Project"). Joins("Project"). - Where(`"job"."name" = ? and "Project"."name" = ?`, name, projectName). - First(&job).Error; err != nil { + Where(`"job"."name" = ? and "Project"."name" = ?`, name, projectName) + + if includeDeleted { + query = query.Unscoped() + } + + var job Job + if err := query.First(&job).Error; err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { return Job{}, store.ErrResourceNotFound } diff --git a/internal/store/postgres/job_spec_repository_test.go b/internal/store/postgres/job_spec_repository_test.go index 55556dfd4b..0e0bc86c0a 100644 --- a/internal/store/postgres/job_spec_repository_test.go +++ b/internal/store/postgres/job_spec_repository_test.go @@ -72,8 +72,36 @@ func (j *JobSpecRepositoryTestSuite) TestGetAllByProjectName() { ctx := context.Background() projectName := projectTarget.Name - actualJobSpecs, actualError := repository.GetAllByProjectName(ctx, projectName) + actualJobSpecs, actualError := repository.GetAllByProjectName(ctx, projectName, false) + j.NoError(actualError) + j.Len(actualJobSpecs, 2) + j.Equal(job1Target.Name, actualJobSpecs[0].Name) + j.Equal(job1Target.Project.Name, actualJobSpecs[0].NamespaceSpec.ProjectSpec.Name) + j.Equal(job2Target.Name, actualJobSpecs[1].Name) + j.Equal(job2Target.Project.Name, actualJobSpecs[1].NamespaceSpec.ProjectSpec.Name) + }) + + j.Run("should return all jobs within a project including the deleted and nil", func() { + pluginRepository := mock.NewPluginRepository(j.T()) + pluginRepository.On("GetByName", "").Return(nil, nil) + db := j.db + adapter := postgres.NewAdapter(pluginRepository) + repository, err := postgres.NewJobSpecRepository(db, adapter) + if err != nil { + panic(err) + } + + ctx := context.Background() + projectName := projectTarget.Name + + jobToDelete, err := repository.GetByNameAndProjectName(ctx, job2Target.Name, projectName, false) + j.NoError(err) + + err = repository.DeleteByID(ctx, jobToDelete.ID) + j.NoError(err) + + actualJobSpecs, actualError := repository.GetAllByProjectName(ctx, projectName, true) j.NoError(actualError) j.Len(actualJobSpecs, 2) j.Equal(job1Target.Name, actualJobSpecs[0].Name) @@ -81,6 +109,33 @@ func (j *JobSpecRepositoryTestSuite) TestGetAllByProjectName() { j.Equal(job2Target.Name, actualJobSpecs[1].Name) j.Equal(job2Target.Project.Name, actualJobSpecs[1].NamespaceSpec.ProjectSpec.Name) }) + + j.Run("should return all jobs within a project excluding the deleted and nil", func() { + pluginRepository := mock.NewPluginRepository(j.T()) + pluginRepository.On("GetByName", "").Return(nil, nil) + + db := j.db + adapter := postgres.NewAdapter(pluginRepository) + repository, err := postgres.NewJobSpecRepository(db, adapter) + if err != nil { + panic(err) + } + + ctx := context.Background() + projectName := projectTarget.Name + + jobToDelete, err := repository.GetByNameAndProjectName(ctx, job2Target.Name, projectName, false) + j.NoError(err) + + err = repository.DeleteByID(ctx, jobToDelete.ID) + j.NoError(err) + + actualJobSpecs, actualError := repository.GetAllByProjectName(ctx, projectName, false) + j.NoError(actualError) + j.Len(actualJobSpecs, 1) + j.Equal(job1Target.Name, actualJobSpecs[0].Name) + j.Equal(job1Target.Project.Name, actualJobSpecs[0].NamespaceSpec.ProjectSpec.Name) + }) } func (j *JobSpecRepositoryTestSuite) TestGetAllByProjectNameAndNamespaceName() { @@ -110,8 +165,37 @@ func (j *JobSpecRepositoryTestSuite) TestGetAllByProjectNameAndNamespaceName() { projectName := projectTarget.Name namespaceName := namespaceTarget.Name - actualJobSpecs, actualError := repository.GetAllByProjectNameAndNamespaceName(ctx, projectName, namespaceName) + actualJobSpecs, actualError := repository.GetAllByProjectNameAndNamespaceName(ctx, projectName, namespaceName, false) + j.NoError(actualError) + j.Len(actualJobSpecs, 2) + j.Equal(job1Target.Name, actualJobSpecs[0].Name) + j.Equal(job1Target.Namespace.Name, actualJobSpecs[0].NamespaceSpec.Name) + j.Equal(job2Target.Name, actualJobSpecs[1].Name) + j.Equal(job2Target.Namespace.Name, actualJobSpecs[1].NamespaceSpec.Name) + }) + + j.Run("should return all jobs including deleted jobs within a project with the specified namespace and nil", func() { + pluginRepository := mock.NewPluginRepository(j.T()) + pluginRepository.On("GetByName", "").Return(nil, nil) + + db := j.db + adapter := postgres.NewAdapter(pluginRepository) + repository, err := postgres.NewJobSpecRepository(db, adapter) + if err != nil { + panic(err) + } + + ctx := context.Background() + projectName := projectTarget.Name + namespaceName := namespaceTarget.Name + + jobToDelete, err := repository.GetByNameAndProjectName(ctx, job2Target.Name, projectName, false) + j.NoError(err) + + err = repository.DeleteByID(ctx, jobToDelete.ID) + j.NoError(err) + actualJobSpecs, actualError := repository.GetAllByProjectNameAndNamespaceName(ctx, projectName, namespaceName, true) j.NoError(actualError) j.Len(actualJobSpecs, 2) j.Equal(job1Target.Name, actualJobSpecs[0].Name) @@ -119,6 +203,34 @@ func (j *JobSpecRepositoryTestSuite) TestGetAllByProjectNameAndNamespaceName() { j.Equal(job2Target.Name, actualJobSpecs[1].Name) j.Equal(job2Target.Namespace.Name, actualJobSpecs[1].NamespaceSpec.Name) }) + + j.Run("should return all jobs excluding deleted jobs within a project with the specified namespace and nil", func() { + pluginRepository := mock.NewPluginRepository(j.T()) + pluginRepository.On("GetByName", "").Return(nil, nil) + + db := j.db + adapter := postgres.NewAdapter(pluginRepository) + repository, err := postgres.NewJobSpecRepository(db, adapter) + if err != nil { + panic(err) + } + + ctx := context.Background() + projectName := projectTarget.Name + namespaceName := namespaceTarget.Name + + jobToDelete, err := repository.GetByNameAndProjectName(ctx, job2Target.Name, projectName, false) + j.NoError(err) + + err = repository.DeleteByID(ctx, jobToDelete.ID) + j.NoError(err) + + actualJobSpecs, actualError := repository.GetAllByProjectNameAndNamespaceName(ctx, projectName, namespaceName, false) + j.NoError(actualError) + j.Len(actualJobSpecs, 1) + j.Equal(job1Target.Name, actualJobSpecs[0].Name) + j.Equal(job1Target.Namespace.Name, actualJobSpecs[0].NamespaceSpec.Name) + }) } func (j *JobSpecRepositoryTestSuite) TestGetByNameAndProjectName() { @@ -144,8 +256,7 @@ func (j *JobSpecRepositoryTestSuite) TestGetByNameAndProjectName() { jobName := "unknown_job" projectName := storedProject.Name - actualJobSpec, actualError := repository.GetByNameAndProjectName(ctx, jobName, projectName) - + actualJobSpec, actualError := repository.GetByNameAndProjectName(ctx, jobName, projectName, false) j.Error(actualError) j.Empty(actualJobSpec) }) @@ -165,11 +276,62 @@ func (j *JobSpecRepositoryTestSuite) TestGetByNameAndProjectName() { jobName := storedJob.Name projectName := storedProject.Name - actualJobSpec, actualError := repository.GetByNameAndProjectName(ctx, jobName, projectName) + actualJobSpec, actualError := repository.GetByNameAndProjectName(ctx, jobName, projectName, false) + j.NoError(actualError) + j.Equal(jobName, actualJobSpec.Name) + }) + + j.Run("should return deleted job spec and nil if no error is encountered and include deleted is true", func() { + pluginRepository := mock.NewPluginRepository(j.T()) + pluginRepository.On("GetByName", "").Return(nil, nil) + + db := j.db + adapter := postgres.NewAdapter(pluginRepository) + repository, err := postgres.NewJobSpecRepository(db, adapter) + if err != nil { + panic(err) + } + + ctx := context.Background() + jobName := storedJob.Name + projectName := storedProject.Name + + jobToDelete, err := repository.GetByNameAndProjectName(ctx, jobName, storedProject.Name, false) + j.NoError(err) + + err = repository.DeleteByID(ctx, jobToDelete.ID) + j.NoError(err) + actualJobSpec, actualError := repository.GetByNameAndProjectName(ctx, jobName, projectName, true) j.NoError(actualError) j.Equal(jobName, actualJobSpec.Name) }) + + j.Run("should return job spec excluding the deleted and nil if no error is encountered and include deleted is false", func() { + pluginRepository := mock.NewPluginRepository(j.T()) + pluginRepository.On("GetByName", "").Return(nil, nil) + + db := j.db + adapter := postgres.NewAdapter(pluginRepository) + repository, err := postgres.NewJobSpecRepository(db, adapter) + if err != nil { + panic(err) + } + + ctx := context.Background() + jobName := storedJob.Name + projectName := storedProject.Name + + jobToDelete, err := repository.GetByNameAndProjectName(ctx, jobName, storedProject.Name, false) + j.NoError(err) + + err = repository.DeleteByID(ctx, jobToDelete.ID) + j.NoError(err) + + actualJobSpec, actualError := repository.GetByNameAndProjectName(ctx, jobName, projectName, false) + j.Error(actualError) + j.Empty(actualJobSpec) + }) } func (j *JobSpecRepositoryTestSuite) TestGetByResourceDestinationURN() { @@ -181,8 +343,10 @@ func (j *JobSpecRepositoryTestSuite) TestGetByResourceDestinationURN() { insertRecords(j.db, []*postgres.Namespace{storedNamespace}) insertRecords(j.db, []*postgres.Job{storedJob}) - j.Run("should return empty and error if error is encountered", func() { + j.Run("should return job and nil if no error encountered", func() { pluginRepository := mock.NewPluginRepository(j.T()) + pluginRepository.On("GetByName", "").Return(nil, nil) + db := j.db adapter := postgres.NewAdapter(pluginRepository) repository, err := postgres.NewJobSpecRepository(db, adapter) @@ -191,15 +355,14 @@ func (j *JobSpecRepositoryTestSuite) TestGetByResourceDestinationURN() { } ctx := context.Background() - destination := "unknown_destination" - - actualJobSpec, actualError := repository.GetByResourceDestinationURN(ctx, destination) + destination := storedJob.Destination - j.Error(actualError) - j.Empty(actualJobSpec) + actualJobSpec, actualError := repository.GetByResourceDestinationURN(ctx, destination, false) + j.NoError(actualError) + j.Equal(storedJob.Name, actualJobSpec[0].Name) }) - j.Run("should return job and nil if no error encountered", func() { + j.Run("should return job including the deleted and nil if no error encountered", func() { pluginRepository := mock.NewPluginRepository(j.T()) pluginRepository.On("GetByName", "").Return(nil, nil) @@ -213,8 +376,13 @@ func (j *JobSpecRepositoryTestSuite) TestGetByResourceDestinationURN() { ctx := context.Background() destination := storedJob.Destination - actualJobSpec, actualError := repository.GetByResourceDestinationURN(ctx, destination) + jobToDelete, err := repository.GetByNameAndProjectName(ctx, storedJob.Name, storedProject.Name, false) + j.NoError(err) + + err = repository.DeleteByID(ctx, jobToDelete.ID) + j.NoError(err) + actualJobSpec, actualError := repository.GetByResourceDestinationURN(ctx, destination, true) j.NoError(actualError) j.Equal(storedJob.Name, actualJobSpec[0].Name) }) diff --git a/internal/store/store.go b/internal/store/store.go index 6016d45247..9f80a6dc11 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -20,11 +20,11 @@ const ( ) type JobSpecRepository interface { - GetAllByProjectName(ctx context.Context, projectName string) ([]models.JobSpec, error) - GetAllByProjectNameAndNamespaceName(ctx context.Context, projectName, namespaceName string) ([]models.JobSpec, error) + GetAllByProjectName(ctx context.Context, projectName string, includeDeleted bool) ([]models.JobSpec, error) + GetAllByProjectNameAndNamespaceName(ctx context.Context, projectName, namespaceName string, includeDeleted bool) ([]models.JobSpec, error) - GetByNameAndProjectName(ctx context.Context, name, projectName string) (models.JobSpec, error) - GetByResourceDestinationURN(ctx context.Context, resourceDestinationURN string) ([]models.JobSpec, error) + GetByNameAndProjectName(ctx context.Context, name, projectName string, includeDeleted bool) (models.JobSpec, error) + GetByResourceDestinationURN(ctx context.Context, resourceDestinationURN string, includeDeleted bool) ([]models.JobSpec, error) GetDependentJobs(ctx context.Context, jobName, resourceDestinationURN, projectName string) ([]models.JobSpec, error) GetInferredDependenciesPerJobID(ctx context.Context, projectName string) (map[uuid.UUID][]models.JobSpec, error) diff --git a/job/dependency_resolver.go b/job/dependency_resolver.go index 7c429a4fe7..e43ebe60c4 100644 --- a/job/dependency_resolver.go +++ b/job/dependency_resolver.go @@ -107,7 +107,7 @@ func (d *dependencyResolver) GetStaticDependencies(ctx context.Context, jobSpec if depSpec.Job == nil { switch depSpec.Type { case models.JobSpecDependencyTypeIntra: - job, getJobError := d.jobSpecRepo.GetByNameAndProjectName(ctx, depName, projectSpec.Name) + job, getJobError := d.jobSpecRepo.GetByNameAndProjectName(ctx, depName, projectSpec.Name, false) if getJobError != nil { err = multierror.Append(err, fmt.Errorf("%s for job %s: %w", ErrUnknownLocalDependency, depName, getJobError)) } else { @@ -126,7 +126,7 @@ func (d *dependencyResolver) GetStaticDependencies(ctx context.Context, jobSpec } else { projectName := depParts[0] jobName := depParts[1] - job, getJobError := d.jobSpecRepo.GetByNameAndProjectName(ctx, jobName, projectName) + job, getJobError := d.jobSpecRepo.GetByNameAndProjectName(ctx, jobName, projectName, false) if getJobError != nil { unresolvedDependency, _ := convertDependencyNamesToUnresolvedJobDependency(depName) @@ -190,7 +190,7 @@ func (d *dependencyResolver) resolveInferredDependencies(ctx context.Context, jo // get job spec of these destinations and append to current jobSpec for _, depDestination := range jobDependencies { - dependencyJobSpecs, err := d.jobSpecRepo.GetByResourceDestinationURN(ctx, depDestination) + dependencyJobSpecs, err := d.jobSpecRepo.GetByResourceDestinationURN(ctx, depDestination, false) if err != nil { if errors.Is(err, store.ErrResourceNotFound) { // should not fail for unknown dependency, its okay to not have a upstream job @@ -251,7 +251,7 @@ func (d *dependencyResolver) GetJobSpecsWithDependencies(ctx context.Context, pr if projectName == "" { return nil, nil, errors.New("project name is empty") } - jobSpecs, err := d.jobSpecRepo.GetAllByProjectName(ctx, projectName) + jobSpecs, err := d.jobSpecRepo.GetAllByProjectName(ctx, projectName, false) if err != nil { return nil, nil, err } @@ -301,7 +301,7 @@ func (d *dependencyResolver) getJobsByResourceDestinations(ctx context.Context, subjectJobName string, logWriter writer.LogWriter) ([]models.JobSpec, error) { jobSpecDependencyList := []models.JobSpec{} for _, depDestination := range upstreamDestinations { - dependencyJobSpec, err := d.jobSpecRepo.GetByResourceDestinationURN(ctx, depDestination) + dependencyJobSpec, err := d.jobSpecRepo.GetByResourceDestinationURN(ctx, depDestination, false) if err != nil { if errors.Is(err, store.ErrResourceNotFound) { // should not fail for unknown dependency, its okay to not have a upstream job diff --git a/job/dependency_resolver_test.go b/job/dependency_resolver_test.go index eeb93936c5..1871ef6868 100644 --- a/job/dependency_resolver_test.go +++ b/job/dependency_resolver_test.go @@ -123,7 +123,7 @@ func TestDependencyResolver(t *testing.T) { jobSourceRepo.On("Save", ctx, projectSpec.ID, jobSpec2.ID, nil).Return(nil) jobSpecRepository := mock.NewJobSpecRepository(t) - jobSpecRepository.On("GetByResourceDestinationURN", ctx, jobSpec1Sources[0]).Return([]models.JobSpec{jobSpec2}, nil) + jobSpecRepository.On("GetByResourceDestinationURN", ctx, jobSpec1Sources[0], false).Return([]models.JobSpec{jobSpec2}, nil) // hook dependency hookUnit1.On("PluginInfo").Return(&models.PluginInfoResponse{ @@ -212,7 +212,7 @@ func TestDependencyResolver(t *testing.T) { } jobSpecRepository := new(mock.JobSpecRepository) - jobSpecRepository.On("GetByResourceDestinationURN", ctx, "project.dataset.table2_destination").Return([]models.JobSpec{jobSpec2}, nil) + jobSpecRepository.On("GetByResourceDestinationURN", ctx, "project.dataset.table2_destination", false).Return([]models.JobSpec{jobSpec2}, nil) defer jobSpecRepository.AssertExpectations(t) jobSpec1Sources := []string{"project.dataset.table2_destination"} @@ -285,7 +285,7 @@ func TestDependencyResolver(t *testing.T) { } jobSpecRepository := new(mock.JobSpecRepository) - jobSpecRepository.On("GetByResourceDestinationURN", ctx, "project.dataset.table2_destination").Return([]models.JobSpec{jobSpec2}, errors.New("random error")) + jobSpecRepository.On("GetByResourceDestinationURN", ctx, "project.dataset.table2_destination", false).Return([]models.JobSpec{jobSpec2}, errors.New("random error")) defer jobSpecRepository.AssertExpectations(t) pluginService := mock.NewPluginService(t) @@ -409,7 +409,7 @@ func TestDependencyResolver(t *testing.T) { } jobSpecRepository := new(mock.JobSpecRepository) - jobSpecRepository.On("GetByResourceDestinationURN", ctx, "project.dataset.table3_destination").Return([]models.JobSpec{}, errors.New("spec not found")) + jobSpecRepository.On("GetByResourceDestinationURN", ctx, "project.dataset.table3_destination", false).Return([]models.JobSpec{}, errors.New("spec not found")) defer jobSpecRepository.AssertExpectations(t) pluginService := mock.NewPluginService(t) @@ -476,8 +476,8 @@ func TestDependencyResolver(t *testing.T) { jobSpec1Sources := []string{"project.dataset.table1_destination"} jobSpecRepository := new(mock.JobSpecRepository) - jobSpecRepository.On("GetByResourceDestinationURN", ctx, jobSpec1Sources[0]).Return([]models.JobSpec{jobSpec1}, nil) - jobSpecRepository.On("GetByNameAndProjectName", ctx, "static_dep", projectName).Return(models.JobSpec{}, errors.New("spec not found")) + jobSpecRepository.On("GetByResourceDestinationURN", ctx, jobSpec1Sources[0], false).Return([]models.JobSpec{jobSpec1}, nil) + jobSpecRepository.On("GetByNameAndProjectName", ctx, "static_dep", projectName, false).Return(models.JobSpec{}, errors.New("spec not found")) defer jobSpecRepository.AssertExpectations(t) pluginService := mock.NewPluginService(t) @@ -542,7 +542,7 @@ func TestDependencyResolver(t *testing.T) { jobSpec1Sources := []string{"project.dataset.table1_destination"} jobSpecRepository := new(mock.JobSpecRepository) - jobSpecRepository.On("GetByResourceDestinationURN", ctx, jobSpec1Sources[0]).Return([]models.JobSpec{jobSpec1}, nil) + jobSpecRepository.On("GetByResourceDestinationURN", ctx, jobSpec1Sources[0], false).Return([]models.JobSpec{jobSpec1}, nil) defer jobSpecRepository.AssertExpectations(t) pluginService := mock.NewPluginService(t) @@ -628,8 +628,8 @@ func TestDependencyResolver(t *testing.T) { jobSpec1Sources := []string{"project.dataset.table2_destination"} jobSpecRepository := new(mock.JobSpecRepository) - jobSpecRepository.On("GetByResourceDestinationURN", ctx, jobSpec1Sources[0]).Return([]models.JobSpec{jobSpec2}, nil) - jobSpecRepository.On("GetByNameAndProjectName", ctx, "test3", projectName).Return(jobSpec3, nil) + jobSpecRepository.On("GetByResourceDestinationURN", ctx, jobSpec1Sources[0], false).Return([]models.JobSpec{jobSpec2}, nil) + jobSpecRepository.On("GetByNameAndProjectName", ctx, "test3", projectName, false).Return(jobSpec3, nil) defer jobSpecRepository.AssertExpectations(t) pluginService := mock.NewPluginService(t) @@ -752,9 +752,9 @@ func TestDependencyResolver(t *testing.T) { } jobSpecRepository := new(mock.JobSpecRepository) - jobSpecRepository.On("GetByResourceDestinationURN", ctx, jobSpec1Sources[0]).Return([]models.JobSpec{jobSpec2}, nil) - jobSpecRepository.On("GetByResourceDestinationURN", ctx, jobSpec1Sources[1]).Return([]models.JobSpec{jobSpecExternal}, nil) - jobSpecRepository.On("GetByNameAndProjectName", ctx, "test3", externalProjectName).Return(jobSpec3, nil) + jobSpecRepository.On("GetByResourceDestinationURN", ctx, jobSpec1Sources[0], false).Return([]models.JobSpec{jobSpec2}, nil) + jobSpecRepository.On("GetByResourceDestinationURN", ctx, jobSpec1Sources[1], false).Return([]models.JobSpec{jobSpecExternal}, nil) + jobSpecRepository.On("GetByNameAndProjectName", ctx, "test3", externalProjectName, false).Return(jobSpec3, nil) defer jobSpecRepository.AssertExpectations(t) pluginService := mock.NewPluginService(t) @@ -815,7 +815,7 @@ func TestDependencyResolver(t *testing.T) { ctx := context.Background() projectName := "project_test" - jobSpecRepo.On("GetAllByProjectName", ctx, projectName).Return(nil, errors.New("random error")) + jobSpecRepo.On("GetAllByProjectName", ctx, projectName, false).Return(nil, errors.New("random error")) actualJobSpecs, _, actualError := dependencyResolver.GetJobSpecsWithDependencies(ctx, projectName) @@ -830,7 +830,7 @@ func TestDependencyResolver(t *testing.T) { ctx := context.Background() projectName := "project_test" - jobSpecRepo.On("GetAllByProjectName", ctx, projectName).Return([]models.JobSpec{}, nil) + jobSpecRepo.On("GetAllByProjectName", ctx, projectName, false).Return([]models.JobSpec{}, nil) jobSpecRepo.On("GetStaticDependenciesPerJobID", ctx, projectName).Return(nil, errors.New("random error")) actualJobSpecs, _, actualError := dependencyResolver.GetJobSpecsWithDependencies(ctx, projectName) @@ -846,7 +846,7 @@ func TestDependencyResolver(t *testing.T) { ctx := context.Background() projectName := "project_test" - jobSpecRepo.On("GetAllByProjectName", ctx, projectName).Return([]models.JobSpec{}, nil) + jobSpecRepo.On("GetAllByProjectName", ctx, projectName, false).Return([]models.JobSpec{}, nil) jobSpecRepo.On("GetStaticDependenciesPerJobID", ctx, projectName).Return(map[uuid.UUID][]models.JobSpec{}, nil) jobSpecRepo.On("GetInferredDependenciesPerJobID", ctx, projectName).Return(nil, errors.New("random error")) @@ -911,7 +911,7 @@ func TestDependencyResolver(t *testing.T) { DependsOn: []string{"plugin-c"}, }, nil) - jobSpecRepo.On("GetAllByProjectName", ctx, projectSpec.Name).Return([]models.JobSpec{jobSpec}, nil) + jobSpecRepo.On("GetAllByProjectName", ctx, projectSpec.Name, false).Return([]models.JobSpec{jobSpec}, nil) jobSpecRepo.On("GetStaticDependenciesPerJobID", ctx, projectSpec.Name).Return(staticDependencies, nil) jobSpecRepo.On("GetInferredDependenciesPerJobID", ctx, projectSpec.Name).Return(inferredDependencies, nil) @@ -985,7 +985,7 @@ func TestDependencyResolver(t *testing.T) { DependsOn: []string{"plugin-c"}, }, nil) - jobSpecRepo.On("GetAllByProjectName", ctx, projectSpec.Name).Return([]models.JobSpec{jobSpec}, nil) + jobSpecRepo.On("GetAllByProjectName", ctx, projectSpec.Name, false).Return([]models.JobSpec{jobSpec}, nil) jobSpecRepo.On("GetStaticDependenciesPerJobID", ctx, projectSpec.Name).Return(staticDependencies, nil) jobSpecRepo.On("GetInferredDependenciesPerJobID", ctx, projectSpec.Name).Return(inferredDependencies, nil) @@ -1060,7 +1060,7 @@ func TestDependencyResolver(t *testing.T) { DependsOn: []string{"plugin-c"}, }, nil) - jobSpecRepo.On("GetAllByProjectName", ctx, projectSpec.Name).Return([]models.JobSpec{jobSpec}, nil) + jobSpecRepo.On("GetAllByProjectName", ctx, projectSpec.Name, false).Return([]models.JobSpec{jobSpec}, nil) jobSpecRepo.On("GetStaticDependenciesPerJobID", ctx, projectSpec.Name).Return(staticDependencies, nil) jobSpecRepo.On("GetInferredDependenciesPerJobID", ctx, projectSpec.Name).Return(inferredDependencies, nil) @@ -1123,7 +1123,7 @@ func TestDependencyResolver(t *testing.T) { DependsOn: []string{"plugin-c"}, }, nil) - jobSpecRepo.On("GetAllByProjectName", ctx, projectSpec.Name).Return([]models.JobSpec{jobSpec}, nil) + jobSpecRepo.On("GetAllByProjectName", ctx, projectSpec.Name, false).Return([]models.JobSpec{jobSpec}, nil) jobSpecRepo.On("GetStaticDependenciesPerJobID", ctx, projectSpec.Name).Return(nil, nil) jobSpecRepo.On("GetInferredDependenciesPerJobID", ctx, projectSpec.Name).Return(nil, nil) @@ -1248,7 +1248,7 @@ func TestDependencyResolver(t *testing.T) { DependsOn: []string{"plugin-c"}, }, nil) - jobSpecRepo.On("GetAllByProjectName", ctx, projectSpec.Name).Return([]models.JobSpec{jobSpec}, nil) + jobSpecRepo.On("GetAllByProjectName", ctx, projectSpec.Name, false).Return([]models.JobSpec{jobSpec}, nil) jobSpecRepo.On("GetStaticDependenciesPerJobID", ctx, projectSpec.Name).Return(nil, nil) jobSpecRepo.On("GetInferredDependenciesPerJobID", ctx, projectSpec.Name).Return(nil, nil) @@ -1370,7 +1370,7 @@ func TestDependencyResolver(t *testing.T) { }, } - jobSpecRepo.On("GetAllByProjectName", ctx, projectSpec.Name).Return([]models.JobSpec{jobSpec}, nil) + jobSpecRepo.On("GetAllByProjectName", ctx, projectSpec.Name, false).Return([]models.JobSpec{jobSpec}, nil) jobSpecRepo.On("GetStaticDependenciesPerJobID", ctx, projectSpec.Name).Return(make(map[uuid.UUID][]models.JobSpec), nil) jobSpecRepo.On("GetInferredDependenciesPerJobID", ctx, projectSpec.Name).Return(inferredDependenciesPerJobID, nil) diff --git a/job/replay_test.go b/job/replay_test.go index 6a1d1290fc..c1401a4d17 100644 --- a/job/replay_test.go +++ b/job/replay_test.go @@ -129,7 +129,7 @@ func TestReplay(t *testing.T) { cyclicDagSpec = append(cyclicDagSpec, cyclicDag1, cyclicDag2) jobSpecRepository := mock.NewJobSpecRepository(t) - jobSpecRepository.On("GetAllByProjectName", ctx, projSpec.Name).Return(cyclicDagSpec, nil) + jobSpecRepository.On("GetAllByProjectName", ctx, projSpec.Name, false).Return(cyclicDagSpec, nil) // resolve dependencies depenResolver := new(mock.DependencyResolver) @@ -155,7 +155,7 @@ func TestReplay(t *testing.T) { t.Run("resolve create replay tree for a dag with three day task window and mentioned dependencies", func(t *testing.T) { jobSpecRepository := mock.NewJobSpecRepository(t) - jobSpecRepository.On("GetAllByProjectName", ctx, projSpec.Name).Return(jobSpecs, nil) + jobSpecRepository.On("GetAllByProjectName", ctx, projSpec.Name, false).Return(jobSpecs, nil) depenResolver := new(mock.DependencyResolver) depenResolver.On("GetJobSpecsWithDependencies", ctx, projSpec.Name).Return(jobSpecs, nil, nil) @@ -201,7 +201,7 @@ func TestReplay(t *testing.T) { t.Run("resolve create replay tree for a dag with three day task window and mentioned dependencies", func(t *testing.T) { jobSpecRepository := mock.NewJobSpecRepository(t) - jobSpecRepository.On("GetAllByProjectName", ctx, projSpec.Name).Return(jobSpecs, nil) + jobSpecRepository.On("GetAllByProjectName", ctx, projSpec.Name, false).Return(jobSpecs, nil) depenResolver := new(mock.DependencyResolver) depenResolver.On("GetJobSpecsWithDependencies", ctx, projSpec.Name).Return(jobSpecs, nil, nil) @@ -257,7 +257,7 @@ func TestReplay(t *testing.T) { t.Run("should able to exclude downstream from replay dry run tree if ignored", func(t *testing.T) { jobSpecRepository := mock.NewJobSpecRepository(t) - jobSpecRepository.On("GetAllByProjectName", ctx, projSpec.Name).Return(jobSpecs, nil) + jobSpecRepository.On("GetAllByProjectName", ctx, projSpec.Name, false).Return(jobSpecs, nil) // resolve dependencies depenResolver := new(mock.DependencyResolver) @@ -296,7 +296,7 @@ func TestReplay(t *testing.T) { t.Run("should able to exclude downstream of same namespace from replay dry run tree if not directly "+ "dependent to same namespace", func(t *testing.T) { jobSpecRepository := mock.NewJobSpecRepository(t) - jobSpecRepository.On("GetAllByProjectName", ctx, projSpec.Name).Return(jobSpecs, nil) + jobSpecRepository.On("GetAllByProjectName", ctx, projSpec.Name, false).Return(jobSpecs, nil) // resolve dependencies depenResolver := new(mock.DependencyResolver) @@ -355,7 +355,7 @@ func TestReplay(t *testing.T) { t.Run("should fail if replay manager throws an error", func(t *testing.T) { jobSpecRepository := mock.NewJobSpecRepository(t) - jobSpecRepository.On("GetAllByProjectName", ctx, projSpec.Name).Return(jobSpecs, nil) + jobSpecRepository.On("GetAllByProjectName", ctx, projSpec.Name, false).Return(jobSpecs, nil) depenResolver := new(mock.DependencyResolver) depenResolver.On("GetJobSpecsWithDependencies", ctx, projSpec.Name).Return(jobSpecs, nil, nil) @@ -391,7 +391,7 @@ func TestReplay(t *testing.T) { t.Run("should succeed if replay manager successfully processes request", func(t *testing.T) { jobSpecRepository := mock.NewJobSpecRepository(t) - jobSpecRepository.On("GetAllByProjectName", ctx, projSpec.Name).Return(jobSpecs, nil) + jobSpecRepository.On("GetAllByProjectName", ctx, projSpec.Name, false).Return(jobSpecs, nil) depenResolver := new(mock.DependencyResolver) depenResolver.On("GetJobSpecsWithDependencies", ctx, projSpec.Name).Return(jobSpecs, nil, nil) diff --git a/job/service.go b/job/service.go index cd0fcaaad5..4747b31e9d 100644 --- a/job/service.go +++ b/job/service.go @@ -145,7 +145,7 @@ func (srv *Service) Create(ctx context.Context, namespace models.NamespaceSpec, return models.JobSpec{}, fmt.Errorf("failed to save job: %s: %w", spec.Name, err) } - result, err := srv.jobSpecRepository.GetByNameAndProjectName(ctx, spec.Name, spec.GetProjectSpec().Name) + result, err := srv.jobSpecRepository.GetByNameAndProjectName(ctx, spec.Name, spec.GetProjectSpec().Name, false) if err != nil { return models.JobSpec{}, fmt.Errorf("failed to fetch job on create: %s: %w", spec.Name, err) } @@ -209,7 +209,7 @@ func (srv *Service) bulkCreate(ctx context.Context, namespace models.NamespaceSp // GetByName fetches a Job by name for a specific namespace // TODO: replace namespace with project name func (srv *Service) GetByName(ctx context.Context, name string, namespace models.NamespaceSpec) (models.JobSpec, error) { - jobSpec, err := srv.jobSpecRepository.GetByNameAndProjectName(ctx, name, namespace.ProjectSpec.Name) + jobSpec, err := srv.jobSpecRepository.GetByNameAndProjectName(ctx, name, namespace.ProjectSpec.Name, false) if err != nil { return models.JobSpec{}, fmt.Errorf("failed to retrieve job: %w", err) } @@ -218,7 +218,7 @@ func (srv *Service) GetByName(ctx context.Context, name string, namespace models func (srv *Service) GetByFilter(ctx context.Context, filter models.JobSpecFilter) ([]models.JobSpec, error) { if filter.ResourceDestination != "" { - jobSpecs, err := srv.jobSpecRepository.GetByResourceDestinationURN(ctx, filter.ResourceDestination) + jobSpecs, err := srv.jobSpecRepository.GetByResourceDestinationURN(ctx, filter.ResourceDestination, filter.IncludeDeleted) if err != nil { if errors.Is(err, store.ErrResourceNotFound) { return []models.JobSpec{}, nil @@ -228,7 +228,7 @@ func (srv *Service) GetByFilter(ctx context.Context, filter models.JobSpecFilter return jobSpecs, nil } if filter.JobName != "" && filter.ProjectName != "" { - jobSpec, err := srv.jobSpecRepository.GetByNameAndProjectName(ctx, filter.JobName, filter.ProjectName) + jobSpec, err := srv.jobSpecRepository.GetByNameAndProjectName(ctx, filter.JobName, filter.ProjectName, filter.IncludeDeleted) if err != nil { if errors.Is(err, store.ErrResourceNotFound) { return []models.JobSpec{}, nil @@ -238,7 +238,7 @@ func (srv *Service) GetByFilter(ctx context.Context, filter models.JobSpecFilter return []models.JobSpec{jobSpec}, nil } if filter.NamespaceName != "" && filter.ProjectName != "" { - jobSpecs, err := srv.jobSpecRepository.GetAllByProjectNameAndNamespaceName(ctx, filter.ProjectName, filter.NamespaceName) + jobSpecs, err := srv.jobSpecRepository.GetAllByProjectNameAndNamespaceName(ctx, filter.ProjectName, filter.NamespaceName, filter.IncludeDeleted) if err != nil { if errors.Is(err, store.ErrResourceNotFound) { return []models.JobSpec{}, nil @@ -248,7 +248,7 @@ func (srv *Service) GetByFilter(ctx context.Context, filter models.JobSpecFilter return jobSpecs, nil } if filter.ProjectName != "" { - return srv.jobSpecRepository.GetAllByProjectName(ctx, filter.ProjectName) + return srv.jobSpecRepository.GetAllByProjectName(ctx, filter.ProjectName, filter.IncludeDeleted) } return nil, fmt.Errorf("filters not specified") } @@ -256,7 +256,7 @@ func (srv *Service) GetByFilter(ctx context.Context, filter models.JobSpecFilter // GetByNameForProject fetches a Job by name for a specific project // TODO: replace project spec with project name, and remove namespace from return func (srv *Service) GetByNameForProject(ctx context.Context, name string, proj models.ProjectSpec) (models.JobSpec, models.NamespaceSpec, error) { - jobSpec, err := srv.jobSpecRepository.GetByNameAndProjectName(ctx, name, proj.Name) + jobSpec, err := srv.jobSpecRepository.GetByNameAndProjectName(ctx, name, proj.Name, false) if err != nil { return models.JobSpec{}, models.NamespaceSpec{}, fmt.Errorf("failed to retrieve job: %w", err) } @@ -265,7 +265,7 @@ func (srv *Service) GetByNameForProject(ctx context.Context, name string, proj m // TODO: use project name and namespace name instead func (srv *Service) GetAll(ctx context.Context, namespace models.NamespaceSpec) ([]models.JobSpec, error) { - jobSpecs, err := srv.jobSpecRepository.GetAllByProjectNameAndNamespaceName(ctx, namespace.ProjectSpec.Name, namespace.Name) + jobSpecs, err := srv.jobSpecRepository.GetAllByProjectNameAndNamespaceName(ctx, namespace.ProjectSpec.Name, namespace.Name, false) if err != nil { return nil, fmt.Errorf("failed to retrieve jobs: %w", err) } @@ -482,7 +482,7 @@ func (srv *Service) GetDownstreamJobs(ctx context.Context, jobName, resourceDest func (srv *Service) GetByDestination(ctx context.Context, projectSpec models.ProjectSpec, destination string) (models.JobSpec, error) { // generate job spec using datastore destination. if a destination can be owned by multiple jobs, need to change to list - jobSpecs, err := srv.jobSpecRepository.GetByResourceDestinationURN(ctx, destination) + jobSpecs, err := srv.jobSpecRepository.GetByResourceDestinationURN(ctx, destination, false) if err != nil { return models.JobSpec{}, err } @@ -546,7 +546,7 @@ func (srv *Service) prepareJobSpecMap(ctx context.Context, projectSpec models.Pr } func (srv *Service) prepareNamespaceJobSpecMap(ctx context.Context, projectSpec models.ProjectSpec) (map[string]string, error) { - jobSpecs, err := srv.jobSpecRepository.GetAllByProjectName(ctx, projectSpec.Name) + jobSpecs, err := srv.jobSpecRepository.GetAllByProjectName(ctx, projectSpec.Name, false) if err != nil { return nil, err } @@ -705,7 +705,7 @@ func (srv *Service) fetchJobSpecs(ctx context.Context, projectSpec models.Projec } else if len(namespaceNames) > 0 { return srv.fetchAllJobSpecsForGivenNamespaces(ctx, projectSpec, namespaceNames) } - return srv.jobSpecRepository.GetAllByProjectName(ctx, projectSpec.Name) + return srv.jobSpecRepository.GetAllByProjectName(ctx, projectSpec.Name, false) } func (srv *Service) fetchAllJobSpecsForGivenNamespaces(ctx context.Context, projectSpec models.ProjectSpec, namespaceNames []string) ([]models.JobSpec, error) { @@ -737,7 +737,7 @@ func (srv *Service) fetchSpecsForGivenJobNames(ctx context.Context, projectSpec } func (srv *Service) GetJobNamesWithDuplicateDestination(ctx context.Context, jobFullName, resourceDestination string) (string, error) { - jobsWithSameDestination, err := srv.jobSpecRepository.GetByResourceDestinationURN(ctx, resourceDestination) + jobsWithSameDestination, err := srv.jobSpecRepository.GetByResourceDestinationURN(ctx, resourceDestination, false) if err != nil { if errors.Is(err, store.ErrResourceNotFound) { return "", nil @@ -860,7 +860,7 @@ func (srv *Service) Deploy(ctx context.Context, projectName string, namespaceNam } func (srv *Service) getJobsDiff(ctx context.Context, namespace models.NamespaceSpec, requestedJobSpecs []models.JobSpec) ([]models.JobSpec, []models.JobSpec, []models.JobSpec, error) { - existingJobSpecs, err := srv.jobSpecRepository.GetAllByProjectNameAndNamespaceName(ctx, namespace.ProjectSpec.Name, namespace.Name) + existingJobSpecs, err := srv.jobSpecRepository.GetAllByProjectNameAndNamespaceName(ctx, namespace.ProjectSpec.Name, namespace.Name, false) if err != nil { return nil, nil, nil, err } diff --git a/job/service_test.go b/job/service_test.go index 5b62768cf1..c5752aa950 100644 --- a/job/service_test.go +++ b/job/service_test.go @@ -56,7 +56,7 @@ func TestService(t *testing.T) { jobSpecRepository := mock.NewJobSpecRepository(t) jobSpecRepository.On("Save", ctx, jobSpec).Return(nil) - jobSpecRepository.On("GetByNameAndProjectName", ctx, jobSpec.Name, jobSpec.GetProjectSpec().Name).Return(enrichedJobSpec, nil) + jobSpecRepository.On("GetByNameAndProjectName", ctx, jobSpec.Name, jobSpec.GetProjectSpec().Name, false).Return(enrichedJobSpec, nil) svc := job.NewService(nil, nil, nil, nil, nil, nil, nil, nil, pluginService, jobSpecRepository, nil) _, err := svc.Create(ctx, namespaceSpec, jobSpec) @@ -91,7 +91,7 @@ func TestService(t *testing.T) { jobSpecRepository := mock.NewJobSpecRepository(t) jobSpecRepository.On("Save", ctx, jobSpec).Return(nil) - jobSpecRepository.On("GetByNameAndProjectName", ctx, jobSpec.Name, jobSpec.GetProjectSpec().Name).Return(enrichedJobSpec, nil) + jobSpecRepository.On("GetByNameAndProjectName", ctx, jobSpec.Name, jobSpec.GetProjectSpec().Name, false).Return(enrichedJobSpec, nil) svc := job.NewService(nil, nil, nil, nil, nil, nil, nil, nil, pluginService, jobSpecRepository, nil) _, err := svc.Create(ctx, namespaceSpec, jobSpec) @@ -166,7 +166,7 @@ func TestService(t *testing.T) { jobSpecRepository := mock.NewJobSpecRepository(t) jobSpecRepository.On("Save", ctx, jobSpec).Return(nil) - jobSpecRepository.On("GetByNameAndProjectName", ctx, jobSpec.Name, projSpec.Name).Return(models.JobSpec{}, errors.New("unknown error")) + jobSpecRepository.On("GetByNameAndProjectName", ctx, jobSpec.Name, projSpec.Name, false).Return(models.JobSpec{}, errors.New("unknown error")) svc := job.NewService(nil, nil, nil, nil, nil, nil, nil, nil, pluginService, jobSpecRepository, nil) _, err := svc.Create(ctx, namespaceSpec, jobSpec) @@ -197,7 +197,7 @@ func TestService(t *testing.T) { } jobSpecRepository := mock.NewJobSpecRepository(t) - jobSpecRepository.On("GetByNameAndProjectName", ctx, jobSpec.Name, namespaceSpec.ProjectSpec.Name).Return(jobSpec, nil) + jobSpecRepository.On("GetByNameAndProjectName", ctx, jobSpec.Name, namespaceSpec.ProjectSpec.Name, false).Return(jobSpec, nil) svc := job.NewService(nil, nil, nil, nil, nil, nil, nil, nil, nil, jobSpecRepository, nil) _, err := svc.GetByName(ctx, jobSpec.Name, namespaceSpec) @@ -227,7 +227,7 @@ func TestService(t *testing.T) { } jobSpecRepository := mock.NewJobSpecRepository(t) - jobSpecRepository.On("GetByNameAndProjectName", ctx, jobSpec.Name, namespaceSpec.ProjectSpec.Name).Return(models.JobSpec{}, errors.New("unknown error")) + jobSpecRepository.On("GetByNameAndProjectName", ctx, jobSpec.Name, namespaceSpec.ProjectSpec.Name, false).Return(models.JobSpec{}, errors.New("unknown error")) svc := job.NewService(nil, nil, nil, nil, nil, nil, nil, nil, nil, jobSpecRepository, nil) _, err := svc.GetByName(ctx, jobSpec.Name, namespaceSpec) @@ -547,7 +547,7 @@ func TestService(t *testing.T) { defer logWriter.AssertExpectations(t) jobSpecRepository := mock.NewJobSpecRepository(t) - jobSpecRepository.On("GetAllByProjectNameAndNamespaceName", ctx, namespaceSpec.ProjectSpec.Name, namespaceSpec.Name).Return(nil, errors.New("unknown error")) + jobSpecRepository.On("GetAllByProjectNameAndNamespaceName", ctx, namespaceSpec.ProjectSpec.Name, namespaceSpec.Name, false).Return(nil, errors.New("unknown error")) namespaceService.On("Get", ctx, projSpec.Name, namespaceSpec.Name).Return(namespaceSpec, nil) @@ -595,7 +595,7 @@ func TestService(t *testing.T) { NamespaceSpec: namespaceSpec, }, } - jobSpecRepository.On("GetAllByProjectNameAndNamespaceName", ctx, inputProjectName, inputNamespaceName).Return(existingJobSpecs, nil) + jobSpecRepository.On("GetAllByProjectNameAndNamespaceName", ctx, inputProjectName, inputNamespaceName, false).Return(existingJobSpecs, nil) logWriter := new(mock.LogWriter) logWriter.On("Write", tMock.Anything, tMock.Anything).Return(nil) @@ -623,7 +623,7 @@ func TestService(t *testing.T) { } destination := "destination_test" - jobSpecRepository.On("GetByResourceDestinationURN", ctx, destination).Return([]models.JobSpec{}, errors.New("unknown error")) + jobSpecRepository.On("GetByResourceDestinationURN", ctx, destination, false).Return([]models.JobSpec{}, errors.New("unknown error")) actualJobSpec, actualError := svc.GetByDestination(ctx, projSpec, destination) @@ -646,7 +646,7 @@ func TestService(t *testing.T) { } destination := "destination_test" - jobSpecRepository.On("GetByResourceDestinationURN", ctx, destination).Return([]models.JobSpec{jobSpec}, nil) + jobSpecRepository.On("GetByResourceDestinationURN", ctx, destination, false).Return([]models.JobSpec{jobSpec}, nil) actualJobSpec, actualError := svc.GetByDestination(ctx, projSpec, destination) @@ -672,7 +672,7 @@ func TestService(t *testing.T) { } destination := "destination_test" - jobSpecRepository.On("GetByResourceDestinationURN", ctx, destination).Return([]models.JobSpec{jobSpec}, nil) + jobSpecRepository.On("GetByResourceDestinationURN", ctx, destination, false).Return([]models.JobSpec{jobSpec}, nil) actualJobSpec, actualError := svc.GetByDestination(ctx, projSpec2, destination) @@ -691,7 +691,7 @@ func TestService(t *testing.T) { ResourceDestination: "destination_test", } - jobSpecRepository.On("GetByResourceDestinationURN", ctx, filter.ResourceDestination).Return([]models.JobSpec{}, errors.New("unknown error")) + jobSpecRepository.On("GetByResourceDestinationURN", ctx, filter.ResourceDestination, filter.IncludeDeleted).Return([]models.JobSpec{}, errors.New("unknown error")) actualJobSpecs, actualError := service.GetByFilter(ctx, filter) @@ -708,7 +708,7 @@ func TestService(t *testing.T) { ResourceDestination: "destination_test", } - jobSpecRepository.On("GetByResourceDestinationURN", ctx, filter.ResourceDestination).Return([]models.JobSpec{}, store.ErrResourceNotFound) + jobSpecRepository.On("GetByResourceDestinationURN", ctx, filter.ResourceDestination, filter.IncludeDeleted).Return([]models.JobSpec{}, store.ErrResourceNotFound) actualJobSpecs, actualError := service.GetByFilter(ctx, filter) @@ -725,7 +725,7 @@ func TestService(t *testing.T) { ResourceDestination: "destination_test", } - jobSpecRepository.On("GetByResourceDestinationURN", ctx, filter.ResourceDestination).Return([]models.JobSpec{{}}, nil) + jobSpecRepository.On("GetByResourceDestinationURN", ctx, filter.ResourceDestination, filter.IncludeDeleted).Return([]models.JobSpec{{}}, nil) actualJobSpecs, actualError := service.GetByFilter(ctx, filter) @@ -742,7 +742,7 @@ func TestService(t *testing.T) { ProjectName: "project_test", } - jobSpecRepository.On("GetAllByProjectName", ctx, filter.ProjectName).Return([]models.JobSpec{}, nil) + jobSpecRepository.On("GetAllByProjectName", ctx, filter.ProjectName, filter.IncludeDeleted).Return([]models.JobSpec{}, nil) actualJobSpecs, actualError := service.GetByFilter(ctx, filter) @@ -760,7 +760,7 @@ func TestService(t *testing.T) { JobName: "job_test", } - jobSpecRepository.On("GetByNameAndProjectName", ctx, filter.JobName, filter.ProjectName).Return(models.JobSpec{}, errors.New("unknown error")) + jobSpecRepository.On("GetByNameAndProjectName", ctx, filter.JobName, filter.ProjectName, filter.IncludeDeleted).Return(models.JobSpec{}, errors.New("unknown error")) actualJobSpecs, actualError := service.GetByFilter(ctx, filter) @@ -778,7 +778,7 @@ func TestService(t *testing.T) { JobName: "job_test", } - jobSpecRepository.On("GetByNameAndProjectName", ctx, filter.JobName, filter.ProjectName).Return(models.JobSpec{}, store.ErrResourceNotFound) + jobSpecRepository.On("GetByNameAndProjectName", ctx, filter.JobName, filter.ProjectName, filter.IncludeDeleted).Return(models.JobSpec{}, store.ErrResourceNotFound) actualJobSpecs, actualError := service.GetByFilter(ctx, filter) @@ -796,7 +796,7 @@ func TestService(t *testing.T) { JobName: "job_test", } - jobSpecRepository.On("GetByNameAndProjectName", ctx, filter.JobName, filter.ProjectName).Return(models.JobSpec{}, nil) + jobSpecRepository.On("GetByNameAndProjectName", ctx, filter.JobName, filter.ProjectName, filter.IncludeDeleted).Return(models.JobSpec{}, nil) actualJobSpecs, actualError := service.GetByFilter(ctx, filter) @@ -814,7 +814,7 @@ func TestService(t *testing.T) { NamespaceName: "namespace_test", } - jobSpecRepository.On("GetAllByProjectNameAndNamespaceName", ctx, filter.ProjectName, filter.NamespaceName).Return([]models.JobSpec{{}}, nil) + jobSpecRepository.On("GetAllByProjectNameAndNamespaceName", ctx, filter.ProjectName, filter.NamespaceName, filter.IncludeDeleted).Return([]models.JobSpec{{}}, nil) actualJobSpecs, actualError := service.GetByFilter(ctx, filter) @@ -832,7 +832,7 @@ func TestService(t *testing.T) { NamespaceName: "namespace_test", } - jobSpecRepository.On("GetAllByProjectNameAndNamespaceName", ctx, filter.ProjectName, filter.NamespaceName).Return(nil, store.ErrResourceNotFound) + jobSpecRepository.On("GetAllByProjectNameAndNamespaceName", ctx, filter.ProjectName, filter.NamespaceName, filter.IncludeDeleted).Return(nil, store.ErrResourceNotFound) actualJobSpecs, actualError := service.GetByFilter(ctx, filter) @@ -850,7 +850,7 @@ func TestService(t *testing.T) { NamespaceName: "namespace_test", } - jobSpecRepository.On("GetAllByProjectNameAndNamespaceName", ctx, filter.ProjectName, filter.NamespaceName).Return(nil, errors.New("internal error")) + jobSpecRepository.On("GetAllByProjectNameAndNamespaceName", ctx, filter.ProjectName, filter.NamespaceName, filter.IncludeDeleted).Return(nil, errors.New("internal error")) actualJobSpecs, actualError := service.GetByFilter(ctx, filter) @@ -997,7 +997,7 @@ func TestService(t *testing.T) { projectService.On("Get", ctx, projSpec.Name).Return(projSpec, nil) jobSpecRepository := mock.NewJobSpecRepository(t) - jobSpecRepository.On("GetAllByProjectName", ctx, projSpec.Name).Return(jobSpecsBase, nil) + jobSpecRepository.On("GetAllByProjectName", ctx, projSpec.Name, false).Return(jobSpecsBase, nil) pluginService.On("GenerateDependencies", ctx, jobSpecsBase[0], namespaceSpec, false).Return(&models.GenerateDependenciesResponse{Dependencies: resourceURNs}, nil) jobSourceRepo.On("Save", ctx, projSpec.ID, jobID, resourceURNs).Return(nil) @@ -1055,7 +1055,7 @@ func TestService(t *testing.T) { namespaceService.On("Get", ctx, projSpec.Name, namespaceSpec.Name).Return(namespaceSpec, nil) jobSpecRepository := mock.NewJobSpecRepository(t) - jobSpecRepository.On("GetAllByProjectNameAndNamespaceName", ctx, namespaceSpec.ProjectSpec.Name, namespaceSpec.Name).Return(jobSpecsBase, nil) + jobSpecRepository.On("GetAllByProjectNameAndNamespaceName", ctx, namespaceSpec.ProjectSpec.Name, namespaceSpec.Name, false).Return(jobSpecsBase, nil) pluginService.On("GenerateDependencies", ctx, jobSpecsBase[0], namespaceSpec, false).Return(&models.GenerateDependenciesResponse{Dependencies: resourceURNs}, nil) jobSourceRepo.On("Save", ctx, projSpec.ID, jobID, resourceURNs).Return(nil) @@ -1117,7 +1117,7 @@ func TestService(t *testing.T) { projectService.On("Get", ctx, projSpec.Name).Return(projSpec, nil) jobSpecRepository := mock.NewJobSpecRepository(t) - jobSpecRepository.On("GetByNameAndProjectName", ctx, jobNames[0], projSpec.Name).Return(jobSpecsBase[0], nil) + jobSpecRepository.On("GetByNameAndProjectName", ctx, jobNames[0], projSpec.Name, false).Return(jobSpecsBase[0], nil) pluginService.On("GenerateDependencies", ctx, jobSpecsBase[0], namespaceSpec, false).Return(&models.GenerateDependenciesResponse{Dependencies: resourceURNs}, nil) jobSourceRepo.On("Save", ctx, projSpec.ID, jobID, resourceURNs).Return(nil) @@ -1182,7 +1182,7 @@ func TestService(t *testing.T) { projectService.On("Get", ctx, projSpec.Name).Return(projSpec, nil) jobSpecRepository := mock.NewJobSpecRepository(t) - jobSpecRepository.On("GetAllByProjectName", ctx, projSpec.Name).Return([]models.JobSpec{}, errors.New(errorMsg)) + jobSpecRepository.On("GetAllByProjectName", ctx, projSpec.Name, false).Return([]models.JobSpec{}, errors.New(errorMsg)) service := job.NewService(nil, nil, dependencyResolver, nil, nil, namespaceService, projectService, deployManager, nil, jobSpecRepository, jobSourceRepo) @@ -1251,7 +1251,7 @@ func TestService(t *testing.T) { namespaceService.On("Get", ctx, projSpec.Name, namespaceSpec.Name).Return(namespaceSpec, nil) jobSpecRepository := mock.NewJobSpecRepository(t) - jobSpecRepository.On("GetAllByProjectNameAndNamespaceName", ctx, namespaceSpec.ProjectSpec.Name, namespaceSpec.Name).Return([]models.JobSpec{}, errors.New(errorMsg)) + jobSpecRepository.On("GetAllByProjectNameAndNamespaceName", ctx, namespaceSpec.ProjectSpec.Name, namespaceSpec.Name, false).Return([]models.JobSpec{}, errors.New(errorMsg)) service := job.NewService(nil, nil, dependencyResolver, nil, nil, namespaceService, projectService, deployManager, nil, jobSpecRepository, jobSourceRepo) @@ -1297,7 +1297,7 @@ func TestService(t *testing.T) { projectService.On("Get", ctx, projSpec.Name).Return(projSpec, nil) jobSpecRepository := mock.NewJobSpecRepository(t) - jobSpecRepository.On("GetByNameAndProjectName", ctx, jobSpecsBase[0].Name, projSpec.Name).Return(models.JobSpec{}, errors.New(errorMsg)) + jobSpecRepository.On("GetByNameAndProjectName", ctx, jobSpecsBase[0].Name, projSpec.Name, false).Return(models.JobSpec{}, errors.New(errorMsg)) service := job.NewService(nil, nil, dependencyResolver, nil, nil, namespaceService, projectService, deployManager, nil, jobSpecRepository, jobSourceRepo) @@ -1359,7 +1359,7 @@ func TestService(t *testing.T) { projectService.On("Get", ctx, projSpec.Name).Return(projSpec, nil) jobSpecRepository := mock.NewJobSpecRepository(t) - jobSpecRepository.On("GetAllByProjectName", ctx, projSpec.Name).Return(jobSpecsBase, nil) + jobSpecRepository.On("GetAllByProjectName", ctx, projSpec.Name, false).Return(jobSpecsBase, nil) pluginService.On("GenerateDependencies", ctx, jobSpecsBase[0], namespaceSpec, false).Return(&models.GenerateDependenciesResponse{Dependencies: resourceURNs}, nil).Once() jobSourceRepo.On("Save", ctx, projSpec.ID, jobID, resourceURNs).Return(nil).Once() @@ -1429,7 +1429,7 @@ func TestService(t *testing.T) { projectService.On("Get", ctx, projSpec.Name).Return(projSpec, nil) jobSpecRepository := mock.NewJobSpecRepository(t) - jobSpecRepository.On("GetAllByProjectName", ctx, projSpec.Name).Return(jobSpecsBase, nil) + jobSpecRepository.On("GetAllByProjectName", ctx, projSpec.Name, false).Return(jobSpecsBase, nil) pluginService.On("GenerateDependencies", ctx, jobSpecsBase[0], namespaceSpec, false).Return(&models.GenerateDependenciesResponse{Dependencies: resourceURNs}, nil) jobSourceRepo.On("Save", ctx, projSpec.ID, jobID, resourceURNs).Return(nil) @@ -1487,7 +1487,7 @@ func TestService(t *testing.T) { projectService.On("Get", ctx, projSpec.Name).Return(projSpec, nil) jobSpecRepository := mock.NewJobSpecRepository(t) - jobSpecRepository.On("GetAllByProjectName", ctx, projSpec.Name).Return(jobSpecsBase, nil) + jobSpecRepository.On("GetAllByProjectName", ctx, projSpec.Name, false).Return(jobSpecsBase, nil) pluginService.On("GenerateDependencies", ctx, jobSpecsBase[0], namespaceSpec, false).Return(&models.GenerateDependenciesResponse{Dependencies: resourceURNs}, nil) jobSourceRepo.On("Save", ctx, projSpec.ID, jobID, resourceURNs).Return(nil) @@ -1592,7 +1592,7 @@ func TestService(t *testing.T) { jobSpecRepository := mock.NewJobSpecRepository(t) jobSpecRepository.On("Save", ctx, jobSpec).Return(nil) - jobSpecRepository.On("GetByNameAndProjectName", ctx, jobSpec.Name, jobSpec.GetProjectSpec().Name).Return(enrichedJobSpec, nil) + jobSpecRepository.On("GetByNameAndProjectName", ctx, jobSpec.Name, jobSpec.GetProjectSpec().Name, false).Return(enrichedJobSpec, nil) deployManager := new(mock.DeployManager) defer deployManager.AssertExpectations(t) @@ -1648,7 +1648,7 @@ func TestService(t *testing.T) { batchScheduler.On("VerifyJob", ctx, namespaceSpec, jobSpec).Return(nil) jobSpecRepo := mock.NewJobSpecRepository(t) - jobSpecRepo.On("GetByResourceDestinationURN", ctx, destination.URN()).Return([]models.JobSpec{jobSpec}, nil) + jobSpecRepo.On("GetByResourceDestinationURN", ctx, destination.URN(), false).Return([]models.JobSpec{jobSpec}, nil) svc := job.NewService( batchScheduler, diff --git a/mock/job.go b/mock/job.go index 2335db4fe9..8b73a94175 100644 --- a/mock/job.go +++ b/mock/job.go @@ -31,20 +31,20 @@ func (_m *JobSpecRepository) DeleteByID(ctx context.Context, id uuid.UUID) error return r0 } -// GetAllByProjectName provides a mock function with given fields: ctx, projectName -func (_m *JobSpecRepository) GetAllByProjectName(ctx context.Context, projectName string) ([]models.JobSpec, error) { - ret := _m.Called(ctx, projectName) +// GetAllByProjectName provides a mock function with given fields: ctx, projectName, includeDeleted +func (_m *JobSpecRepository) GetAllByProjectName(ctx context.Context, projectName string, includeDeleted bool) ([]models.JobSpec, error) { + ret := _m.Called(ctx, projectName, includeDeleted) var r0 []models.JobSpec - if rf, ok := ret.Get(0).(func(context.Context, string) []models.JobSpec); ok { - r0 = rf(ctx, projectName) + if rf, ok := ret.Get(0).(func(context.Context, string, bool) []models.JobSpec); ok { + r0 = rf(ctx, projectName, includeDeleted) } else if ret.Get(0) != nil { r0 = ret.Get(0).([]models.JobSpec) } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { - r1 = rf(ctx, projectName) + if rf, ok := ret.Get(1).(func(context.Context, string, bool) error); ok { + r1 = rf(ctx, projectName, includeDeleted) } else { r1 = ret.Error(1) } @@ -52,20 +52,20 @@ func (_m *JobSpecRepository) GetAllByProjectName(ctx context.Context, projectNam return r0, r1 } -// GetAllByProjectNameAndNamespaceName provides a mock function with given fields: ctx, projectName, namespaceName -func (_m *JobSpecRepository) GetAllByProjectNameAndNamespaceName(ctx context.Context, projectName string, namespaceName string) ([]models.JobSpec, error) { - ret := _m.Called(ctx, projectName, namespaceName) +// GetAllByProjectNameAndNamespaceName provides a mock function with given fields: ctx, projectName, namespaceName, includeDeleted +func (_m *JobSpecRepository) GetAllByProjectNameAndNamespaceName(ctx context.Context, projectName string, namespaceName string, includeDeleted bool) ([]models.JobSpec, error) { + ret := _m.Called(ctx, projectName, namespaceName, includeDeleted) var r0 []models.JobSpec - if rf, ok := ret.Get(0).(func(context.Context, string, string) []models.JobSpec); ok { - r0 = rf(ctx, projectName, namespaceName) + if rf, ok := ret.Get(0).(func(context.Context, string, string, bool) []models.JobSpec); ok { + r0 = rf(ctx, projectName, namespaceName, includeDeleted) } else if ret.Get(0) != nil { r0 = ret.Get(0).([]models.JobSpec) } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { - r1 = rf(ctx, projectName, namespaceName) + if rf, ok := ret.Get(1).(func(context.Context, string, string, bool) error); ok { + r1 = rf(ctx, projectName, namespaceName, includeDeleted) } else { r1 = ret.Error(1) } @@ -73,20 +73,20 @@ func (_m *JobSpecRepository) GetAllByProjectNameAndNamespaceName(ctx context.Con return r0, r1 } -// GetByNameAndProjectName provides a mock function with given fields: ctx, name, projectName -func (_m *JobSpecRepository) GetByNameAndProjectName(ctx context.Context, name string, projectName string) (models.JobSpec, error) { - ret := _m.Called(ctx, name, projectName) +// GetByNameAndProjectName provides a mock function with given fields: ctx, name, projectName, includeDeleted +func (_m *JobSpecRepository) GetByNameAndProjectName(ctx context.Context, name string, projectName string, includeDeleted bool) (models.JobSpec, error) { + ret := _m.Called(ctx, name, projectName, includeDeleted) var r0 models.JobSpec - if rf, ok := ret.Get(0).(func(context.Context, string, string) models.JobSpec); ok { - r0 = rf(ctx, name, projectName) + if rf, ok := ret.Get(0).(func(context.Context, string, string, bool) models.JobSpec); ok { + r0 = rf(ctx, name, projectName, includeDeleted) } else { r0 = ret.Get(0).(models.JobSpec) } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { - r1 = rf(ctx, name, projectName) + if rf, ok := ret.Get(1).(func(context.Context, string, string, bool) error); ok { + r1 = rf(ctx, name, projectName, includeDeleted) } else { r1 = ret.Error(1) } @@ -94,20 +94,20 @@ func (_m *JobSpecRepository) GetByNameAndProjectName(ctx context.Context, name s return r0, r1 } -// GetByResourceDestinationURN provides a mock function with given fields: ctx, resourceDestinationURN -func (_m *JobSpecRepository) GetByResourceDestinationURN(ctx context.Context, resourceDestinationURN string) ([]models.JobSpec, error) { - ret := _m.Called(ctx, resourceDestinationURN) +// GetByResourceDestinationURN provides a mock function with given fields: ctx, resourceDestinationURN, includeDeleted +func (_m *JobSpecRepository) GetByResourceDestinationURN(ctx context.Context, resourceDestinationURN string, includeDeleted bool) ([]models.JobSpec, error) { + ret := _m.Called(ctx, resourceDestinationURN, includeDeleted) var r0 []models.JobSpec - if rf, ok := ret.Get(0).(func(context.Context, string) []models.JobSpec); ok { - r0 = rf(ctx, resourceDestinationURN) - } else { + if rf, ok := ret.Get(0).(func(context.Context, string, bool) []models.JobSpec); ok { + r0 = rf(ctx, resourceDestinationURN, includeDeleted) + } else if ret.Get(0) != nil { r0 = ret.Get(0).([]models.JobSpec) } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { - r1 = rf(ctx, resourceDestinationURN) + if rf, ok := ret.Get(1).(func(context.Context, string, bool) error); ok { + r1 = rf(ctx, resourceDestinationURN, includeDeleted) } else { r1 = ret.Error(1) } @@ -115,20 +115,20 @@ func (_m *JobSpecRepository) GetByResourceDestinationURN(ctx context.Context, re return r0, r1 } -// GetDependentJobs provides a mock function with given fields: ctx, jobName, projectName, resourceDestinationURN -func (_m *JobSpecRepository) GetDependentJobs(ctx context.Context, jobName string, projectName string, resourceDestinationURN string) ([]models.JobSpec, error) { - ret := _m.Called(ctx, jobName, projectName, resourceDestinationURN) +// GetDependentJobs provides a mock function with given fields: ctx, jobName, resourceDestinationURN, projectName +func (_m *JobSpecRepository) GetDependentJobs(ctx context.Context, jobName string, resourceDestinationURN string, projectName string) ([]models.JobSpec, error) { + ret := _m.Called(ctx, jobName, resourceDestinationURN, projectName) var r0 []models.JobSpec if rf, ok := ret.Get(0).(func(context.Context, string, string, string) []models.JobSpec); ok { - r0 = rf(ctx, jobName, projectName, resourceDestinationURN) + r0 = rf(ctx, jobName, resourceDestinationURN, projectName) } else if ret.Get(0) != nil { r0 = ret.Get(0).([]models.JobSpec) } var r1 error if rf, ok := ret.Get(1).(func(context.Context, string, string, string) error); ok { - r1 = rf(ctx, jobName, projectName, resourceDestinationURN) + r1 = rf(ctx, jobName, resourceDestinationURN, projectName) } else { r1 = ret.Error(1) } diff --git a/models/job.go b/models/job.go index ef6255b334..ea7aac731d 100644 --- a/models/job.go +++ b/models/job.go @@ -402,6 +402,7 @@ type JobSpecFilter struct { JobName string ResourceDestination string NamespaceName string + IncludeDeleted bool } type JobEventType string diff --git a/tests/bench/1_job_spec_repo_test.go b/tests/bench/1_job_spec_repo_test.go index ef615e940d..972e25648d 100644 --- a/tests/bench/1_job_spec_repo_test.go +++ b/tests/bench/1_job_spec_repo_test.go @@ -92,7 +92,7 @@ func BenchmarkJobRepository(b *testing.B) { num := i % 1000 name := fmt.Sprintf("job_%d", num) - jb, err := jobSpecRepository.GetByNameAndProjectName(ctx, name, project.Name) + jb, err := jobSpecRepository.GetByNameAndProjectName(ctx, name, project.Name, false) if err != nil { panic(err) } @@ -122,7 +122,7 @@ func BenchmarkJobRepository(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - jbs, err := jobSpecRepository.GetAllByProjectName(ctx, project.Name) + jbs, err := jobSpecRepository.GetAllByProjectName(ctx, project.Name, false) if err != nil { panic(err) }