mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-25 01:14:18 +00:00
Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Tiger Kaovilai <passawit.kaovilai@gmail.com>
This commit is contained in:
co-authored by
Copilot
parent
3c49bbec75
commit
80440f5d5a
@@ -40,9 +40,17 @@ func completeNames(f client.Factory, list kbclient.ObjectList) completionFunc {
|
||||
if err != nil {
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
parentCtx := context.Background()
|
||||
if cmd != nil && cmd.Context() != nil {
|
||||
parentCtx = cmd.Context()
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(parentCtx, 3*time.Second)
|
||||
defer cancel()
|
||||
freshList := list.DeepCopyObject().(kbclient.ObjectList)
|
||||
freshObject := list.DeepCopyObject()
|
||||
freshList, ok := freshObject.(kbclient.ObjectList)
|
||||
if !ok {
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
if err := kbClient.List(ctx, freshList, &kbclient.ListOptions{Namespace: f.Namespace()}); err != nil {
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ func TestCompleteNames(t *testing.T) {
|
||||
got, directive := completionFn(&cobra.Command{}, tc.args, tc.toComplete)
|
||||
|
||||
assert.Equal(t, cobra.ShellCompDirectiveNoFileComp, directive)
|
||||
assert.Equal(t, tc.want, got)
|
||||
assert.ElementsMatch(t, tc.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user