Skip to content

Commit

Permalink
feat: flag to disable asset on job list api (#179)
Browse files Browse the repository at this point in the history
* feat: flag to disable asset on job list api

* feat: use latest proton commit
  • Loading branch information
deryrahman committed Nov 17, 2023
1 parent 427f9ac commit eee95a0
Show file tree
Hide file tree
Showing 6 changed files with 745 additions and 677 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ NAME = "github.com/goto/optimus"
LAST_COMMIT := $(shell git rev-parse --short HEAD)
LAST_TAG := "$(shell git rev-list --tags --max-count=1)"
OPMS_VERSION := "$(shell git describe --tags ${LAST_TAG})-next"
PROTON_COMMIT := "da19922df91b97b5d65ad99bd3ce1fd02fa72078"
PROTON_COMMIT := "d83768b3bcb187741326f5f3e8296109009708a2"


.PHONY: build test test-ci generate-proto unit-test-ci integration-test vet coverage clean install lint
Expand Down
6 changes: 5 additions & 1 deletion core/job/handler/v1beta1/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,11 @@ func (jh *JobHandler) ListJobSpecification(ctx context.Context, req *pb.ListJobS

jobSpecificationProtos := make([]*pb.JobSpecification, len(jobSpecs))
for i, jobSpec := range jobSpecs {
jobSpecificationProtos[i] = ToJobProto(jobSpec)
jobSpecProto := ToJobProto(jobSpec)
if req.IgnoreAssets {
jobSpecProto.Assets = map[string]string{}
}
jobSpecificationProtos[i] = jobSpecProto
}

// TODO: make a stream response
Expand Down
34 changes: 32 additions & 2 deletions core/job/handler/v1beta1/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,9 @@ func TestNewJobHandler(t *testing.T) {
})
})
t.Run("ListJobSpecification", func(t *testing.T) {
asset := map[string]string{
"query.sql": "select * from something",
}
t.Run("return error when service get by filter failed", func(t *testing.T) {
jobService := new(JobService)
defer jobService.AssertExpectations(t)
Expand All @@ -1315,9 +1318,34 @@ func TestNewJobHandler(t *testing.T) {
NamespaceName: sampleTenant.NamespaceName().String(),
}

specA, _ := job.NewSpecBuilder(jobVersion, "job-A", sampleOwner, jobSchedule, jobWindow, jobTask).Build()
specA, _ := job.NewSpecBuilder(jobVersion, "job-A", sampleOwner, jobSchedule, jobWindow, jobTask).WithAsset(asset).Build()
jobA := job.NewJob(sampleTenant, specA, "table-A", []job.ResourceURN{"table-B"})
specB, _ := job.NewSpecBuilder(jobVersion, "job-B", sampleOwner, jobSchedule, jobWindow, jobTask).Build()
specB, _ := job.NewSpecBuilder(jobVersion, "job-B", sampleOwner, jobSchedule, jobWindow, jobTask).WithAsset(asset).Build()
jobB := job.NewJob(sampleTenant, specB, "table-B", []job.ResourceURN{"table-C"})

jobService.On("GetByFilter", ctx, mock.Anything, mock.Anything).Return([]*job.Job{jobA, jobB}, nil)
jobHandler := v1beta1.NewJobHandler(jobService, log)
resp, err := jobHandler.ListJobSpecification(ctx, &request)
assert.NoError(t, err)
assert.NotNil(t, resp)
assert.NotEmpty(t, resp.Jobs)
assert.Len(t, resp.Jobs, 2)
assert.Equal(t, asset, resp.Jobs[0].Assets)
assert.Equal(t, asset, resp.Jobs[1].Assets)
})
t.Run("return success without asset", func(t *testing.T) {
jobService := new(JobService)
defer jobService.AssertExpectations(t)

request := pb.ListJobSpecificationRequest{
ProjectName: sampleTenant.ProjectName().String(),
NamespaceName: sampleTenant.NamespaceName().String(),
IgnoreAssets: true,
}

specA, _ := job.NewSpecBuilder(jobVersion, "job-A", sampleOwner, jobSchedule, jobWindow, jobTask).WithAsset(asset).Build()
jobA := job.NewJob(sampleTenant, specA, "table-A", []job.ResourceURN{"table-B"})
specB, _ := job.NewSpecBuilder(jobVersion, "job-B", sampleOwner, jobSchedule, jobWindow, jobTask).WithAsset(asset).Build()
jobB := job.NewJob(sampleTenant, specB, "table-B", []job.ResourceURN{"table-C"})

jobService.On("GetByFilter", ctx, mock.Anything, mock.Anything).Return([]*job.Job{jobA, jobB}, nil)
Expand All @@ -1327,6 +1355,8 @@ func TestNewJobHandler(t *testing.T) {
assert.NotNil(t, resp)
assert.NotEmpty(t, resp.Jobs)
assert.Len(t, resp.Jobs, 2)
assert.Empty(t, resp.Jobs[0].Assets)
assert.Empty(t, resp.Jobs[1].Assets)
})
})
t.Run("CheckJobSpecifications", func(t *testing.T) {
Expand Down
Loading

0 comments on commit eee95a0

Please sign in to comment.