Skip to content

Commit

Permalink
Improve message when sortBy field is missing in ListUnifiedResources (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoandredinis authored Oct 29, 2024
1 parent 2b79932 commit 79184f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/auth/auth_with_roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4739,6 +4739,14 @@ func TestListUnifiedResources_KindsFilter(t *testing.T) {
r := resource.GetDatabaseServer()
require.Equal(t, types.KindDatabaseServer, r.GetKind())
}

// Check for invalid sort error message
_, err = clt.ListUnifiedResources(ctx, &proto.ListUnifiedResourcesRequest{
Kinds: []string{types.KindDatabase},
Limit: 5,
SortBy: types.SortBy{},
})
require.ErrorContains(t, err, "sort field is required")
}

func TestListUnifiedResources_WithPinnedResources(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion lib/services/unified_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,10 @@ func (c *UnifiedResourceCache) getSortTree(sortField string) (*btree.BTreeG[*ite
return c.nameTree, nil
case sortByKind:
return c.typeTree, nil
case "":
return nil, trace.BadParameter("sort field is required")
default:
return nil, trace.NotImplemented("sorting by %v is not supporting in unified resources", sortField)
return nil, trace.NotImplemented("sorting by %v is not supported in unified resources", sortField)
}

}
Expand Down

0 comments on commit 79184f6

Please sign in to comment.