Skip to content

Commit

Permalink
fix: error type on tenancy checks
Browse files Browse the repository at this point in the history
  • Loading branch information
JadhavPoonam committed Oct 24, 2023
1 parent e12b377 commit 5af20c0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion agent/grpc-external/services/resource/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (s *Server) Read(ctx context.Context, req *pbresource.ReadRequest) (*pbreso
}

// Check tenancy exists for the V2 resource.
if err = tenancyExists(reg, s.TenancyBridge, req.Id.Tenancy, codes.NotFound); err != nil {
if err = tenancyExists(reg, s.TenancyBridge, req.Id.Tenancy, codes.InvalidArgument); err != nil {
return nil, err
}

Expand Down
48 changes: 24 additions & 24 deletions agent/grpc-external/services/resource/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,30 @@ func TestRead_InputValidation(t *testing.T) {
},
errContains: "cannot have a namespace",
},
"partition not found when namespace scoped": {
modFn: func(artistId, _, _ *pbresource.ID) *pbresource.ID {
id := clone(artistId)
id.Tenancy.Partition = "boguspartition"
return id
},
errContains: "partition not found",
},
"namespace not found when namespace scoped": {
modFn: func(artistId, _, _ *pbresource.ID) *pbresource.ID {
id := clone(artistId)
id.Tenancy.Namespace = "bogusnamespace"
return id
},
errContains: "namespace not found",
},
"partition not found when partition scoped": {
modFn: func(_, recordLabelId, _ *pbresource.ID) *pbresource.ID {
id := clone(recordLabelId)
id.Tenancy.Partition = "boguspartition"
return id
},
errContains: "partition not found",
},
}
for desc, tc := range testCases {
t.Run(desc, func(t *testing.T) {
Expand Down Expand Up @@ -175,30 +199,6 @@ func TestRead_ResourceNotFound(t *testing.T) {
},
errContains: "resource not found",
},
"partition not found when namespace scoped": {
modFn: func(artistId, _ *pbresource.ID) *pbresource.ID {
id := clone(artistId)
id.Tenancy.Partition = "boguspartition"
return id
},
errContains: "partition not found",
},
"namespace not found when namespace scoped": {
modFn: func(artistId, _ *pbresource.ID) *pbresource.ID {
id := clone(artistId)
id.Tenancy.Namespace = "bogusnamespace"
return id
},
errContains: "namespace not found",
},
"partition not found when partition scoped": {
modFn: func(_, recordLabelId *pbresource.ID) *pbresource.ID {
id := clone(recordLabelId)
id.Tenancy.Partition = "boguspartition"
return id
},
errContains: "partition not found",
},
}
for tenancyDesc, tenancyCase := range tenancyCases {
t.Run(tenancyDesc, func(t *testing.T) {
Expand Down
20 changes: 10 additions & 10 deletions internal/tenancy/tenancytest/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,6 @@ func TestReadNamespace_NotFound(t *testing.T) {
Build(),
errMsg: "resource not found",
},
{
name: "tenancy units: partition not present",
resource: rtest.Resource(pbtenancy.NamespaceType, "ns1").
WithTenancy(&pbresource.Tenancy{
Partition: "partition1",
}).
WithData(t, validNamespace()).
Build(),
errMsg: "partition not found: partition1",
},
}

for _, tc := range cases {
Expand Down Expand Up @@ -146,6 +136,16 @@ func TestReadNamespace_InvalidArgument(t *testing.T) {
Build(),
errMsg: fmt.Sprintf("partition scoped resource %s.%s.%s cannot have a namespace. got: ns2", pbtenancy.NamespaceType.Group, pbtenancy.NamespaceType.GroupVersion, pbtenancy.NamespaceType.Kind),
},
{
name: "tenancy units: partition not present",
resource: rtest.Resource(pbtenancy.NamespaceType, "ns1").
WithTenancy(&pbresource.Tenancy{
Partition: "partition1",
}).
WithData(t, validNamespace()).
Build(),
errMsg: "partition not found: partition1",
},
}

for _, tc := range cases {
Expand Down

0 comments on commit 5af20c0

Please sign in to comment.