Skip to content

Commit

Permalink
add requirePDClient to cobra command
Browse files Browse the repository at this point in the history
Signed-off-by: Boyang Lyu <[email protected]>
  • Loading branch information
JackL9u committed Aug 9, 2024
1 parent 11be503 commit dc62cc2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion client/http/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,5 +219,5 @@ func GetKeyspaceMetaByNameURL(keyspaceName string) string {

// GetDeleteSafePointURI returns the URI for delete safepoint service
func GetDeleteSafePointURI(serviceID string) string {
return safepoint + "/" + serviceID
return fmt.Sprintf("%s/%s", safepoint, serviceID)
}
3 changes: 3 additions & 0 deletions tests/integrations/client/http_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ func (suite *httpClientTestSuite) TestGetGCSafePoint() {
ctx, cancel := context.WithCancel(suite.ctx)
defer cancel()

// adding some safepoints to the server
list := &api.ListServiceGCSafepoint{
ServiceGCSafepoints: []*endpoint.ServiceSafePoint{
{
Expand Down Expand Up @@ -873,13 +874,15 @@ func (suite *httpClientTestSuite) TestGetGCSafePoint() {
}
storage.SaveGCSafePoint(1)

// get the safepoints and start testing
l, err := client.GetGCSafePoint(ctx)
re.NoError(err)

re.Equal(uint64(1), l.GCSafePoint)
re.Equal(uint64(1), l.MinServiceGcSafepoint)
re.Len(l.ServiceGCSafepoints, 3)

// TODO : add some sorting to preserve order
for i, val := range l.ServiceGCSafepoints {
re.Equal(list.ServiceGCSafepoints[i].ServiceID, val.ServiceID)
re.Equal(list.ServiceGCSafepoints[i].SafePoint, val.SafePoint)
Expand Down
16 changes: 9 additions & 7 deletions tools/pd-ctl/pdctl/command/gc_safepoint_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ import (
// NewServiceGCSafepointCommand return a service gc safepoint subcommand of rootCmd
func NewServiceGCSafepointCommand() *cobra.Command {
l := &cobra.Command{
Use: "service-gc-safepoint",
Short: "show all service gc safepoint",
Run: showSSPs,
Use: "service-gc-safepoint",
Short: "show all service gc safepoint",
PersistentPreRunE: requirePDClient,
Run: showSSPs,
}
l.AddCommand(NewDeleteServiceGCSafepointCommand())
return l
Expand All @@ -34,10 +35,11 @@ func NewServiceGCSafepointCommand() *cobra.Command {
// NewDeleteServiceGCSafepointCommand return a subcommand to delete service gc safepoint
func NewDeleteServiceGCSafepointCommand() *cobra.Command {
l := &cobra.Command{
Use: "delete <service ID>",
Short: "delete a service gc safepoint",
Run: deleteSSP,
Hidden: true,
Use: "delete <service ID>",
Short: "delete a service gc safepoint",
PersistentPreRunE: requirePDClient,
Run: deleteSSP,
Hidden: true,
}
return l
}
Expand Down

0 comments on commit dc62cc2

Please sign in to comment.