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:
Tiger Kaovilai
2026-08-05 08:17:44 -07:00
committed by Joseph
co-authored by Copilot
parent 3c49bbec75
commit 80440f5d5a
2 changed files with 11 additions and 3 deletions
+10 -2
View File
@@ -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
}
+1 -1
View File
@@ -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)
})
}
}