Skip to content

Commit

Permalink
chore: update test and handle latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
idilhaq committed Dec 2, 2024
1 parent 9f3bd72 commit 78ee4c8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 64 deletions.
60 changes: 0 additions & 60 deletions api/handler/v1beta1/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,16 +352,6 @@ func (s *GrpcHandlersSuite) TestCreateProvider() {
Description: "Please enter your username",
},
},
Policies: []*domain.ProviderPolicy{
{
When: "$appeal.resource.type == 'project' && $appeal.resource.urn == 'data-gojek-id-mart'",
Policy: "policy1",
},
{
When: "$appeal.resource.type == 'dataset' && $appeal.resource.urn == 'data-gojek-id-mart'",
Policy: "policy2@3",
},
},
},
}
expectedResponse := &guardianv1beta1.CreateProviderResponse{
Expand Down Expand Up @@ -400,16 +390,6 @@ func (s *GrpcHandlersSuite) TestCreateProvider() {
Description: "Please enter your username",
},
},
Policies: []*guardianv1beta1.ProviderPolicy{
{
When: "$appeal.resource.type == 'project' && $appeal.resource.urn == 'data-gojek-id-mart'",
Policy: "policy1",
},
{
When: "$appeal.resource.type == 'dataset' && $appeal.resource.urn == 'data-gojek-id-mart'",
Policy: "policy2@3",
},
},
},
CreatedAt: timestamppb.New(timeNow),
UpdatedAt: timestamppb.New(timeNow),
Expand Down Expand Up @@ -454,16 +434,6 @@ func (s *GrpcHandlersSuite) TestCreateProvider() {
Description: "Please enter your username",
},
},
Policies: []*guardianv1beta1.ProviderPolicy{
{
When: "$appeal.resource.type == 'project' && $appeal.resource.urn == 'data-gojek-id-mart'",
Policy: "policy1",
},
{
When: "$appeal.resource.type == 'dataset' && $appeal.resource.urn == 'data-gojek-id-mart'",
Policy: "policy2@3",
},
},
},
}
res, err := s.grpcServer.CreateProvider(context.Background(), req)
Expand Down Expand Up @@ -538,16 +508,6 @@ func (s *GrpcHandlersSuite) TestUpdatedProvider() {
},
},
},
Policies: []*domain.ProviderPolicy{
{
When: "$appeal.resource.type == 'project' && $appeal.resource.urn == 'data-gojek-id-mart'",
Policy: "policy1",
},
{
When: "$appeal.resource.type == 'dataset' && $appeal.resource.urn == 'data-gojek-id-mart'",
Policy: "policy2@3",
},
},
},
}
expectedResponse := &guardianv1beta1.UpdateProviderResponse{
Expand All @@ -574,16 +534,6 @@ func (s *GrpcHandlersSuite) TestUpdatedProvider() {
},
},
},
Policies: []*guardianv1beta1.ProviderPolicy{
{
When: "$appeal.resource.type == 'project' && $appeal.resource.urn == 'data-gojek-id-mart'",
Policy: "policy1",
},
{
When: "$appeal.resource.type == 'dataset' && $appeal.resource.urn == 'data-gojek-id-mart'",
Policy: "policy2@3",
},
},
},
CreatedAt: timestamppb.New(timeNow),
UpdatedAt: timestamppb.New(timeNow),
Expand Down Expand Up @@ -616,16 +566,6 @@ func (s *GrpcHandlersSuite) TestUpdatedProvider() {
},
},
},
Policies: []*guardianv1beta1.ProviderPolicy{
{
When: "$appeal.resource.type == 'project' && $appeal.resource.urn == 'data-gojek-id-mart'",
Policy: "policy1",
},
{
When: "$appeal.resource.type == 'dataset' && $appeal.resource.urn == 'data-gojek-id-mart'",
Policy: "policy2@3",
},
},
},
}
res, err := s.grpcServer.UpdateProvider(context.Background(), req)
Expand Down
8 changes: 7 additions & 1 deletion core/appeal/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,7 @@ func getPolicy(a *domain.Appeal, p *domain.Provider, policiesMap map[string]map[
}

dynamicPolicyConfigData = pc.Policy
break
}
}

Expand All @@ -1570,7 +1571,12 @@ func getPolicy(a *domain.Appeal, p *domain.Provider, policiesMap map[string]map[
policyData := strings.Split(dynamicPolicyConfigData, "@")
dynamicPolicyConfig.ID = policyData[0]
if len(policyData) > 1 {
version, err := strconv.Atoi(policyData[1])
var version int
if policyData[1] == "latest" {
version = 0
} else {
version, err = strconv.Atoi(policyData[1])
}
if err != nil {
return nil, fmt.Errorf("invalid policy version: %w", err)
}
Expand Down
8 changes: 6 additions & 2 deletions core/appeal/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,11 @@ func (s *ServiceTestSuite) TestCreate() {
Policies: []*domain.ProviderPolicy{
{
When: "$appeal.resource.type == 'dataset'",
Policy: "policy_dataset",
Policy: "policy_dataset@latest",
},
{
When: "$appeal.resource.type == 'dataset2'",
Policy: "policy_dataset@2",
},
},
},
Expand Down Expand Up @@ -1687,7 +1691,7 @@ func (s *ServiceTestSuite) TestCreate() {
},
{
ID: "policy_table",
Version: 1,
Version: 2,
Steps: []*domain.Step{
{
Name: "step_1",
Expand Down
1 change: 0 additions & 1 deletion pkg/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func TestMakeRequestForGet(t *testing.T) {
}

func TestMakeRequestForPostWithPayload(t *testing.T) {
t.Parallel()
// Create a test server
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
Expand Down

0 comments on commit 78ee4c8

Please sign in to comment.