|
8 | 8 | "github.com/stretchr/testify/require" |
9 | 9 | corev1 "k8s.io/api/core/v1" |
10 | 10 | "k8s.io/apimachinery/pkg/api/resource" |
| 11 | + "k8s.io/cli-runtime/pkg/genericclioptions" |
| 12 | + cmdutil "k8s.io/kubectl/pkg/cmd/util" |
11 | 13 | "k8s.io/utils/ptr" |
12 | 14 |
|
13 | 15 | "github.com/ray-project/kuberay/kubectl-plugin/pkg/util" |
@@ -104,10 +106,17 @@ func TestCreateWorkerGroupCommandComplete(t *testing.T) { |
104 | 106 | }, |
105 | 107 | }, |
106 | 108 | { |
107 | | - name: "Valid input without namespace flag", |
108 | | - args: []string{"example-group"}, |
109 | | - flags: map[string]string{}, |
110 | | - expectedError: "failed to get namespace: flag accessed but not defined: namespace", |
| 109 | + name: "Valid input without namespace flag", |
| 110 | + args: []string{"example-group"}, |
| 111 | + flags: map[string]string{ |
| 112 | + "namespace": "", |
| 113 | + }, |
| 114 | + expected: &CreateWorkerGroupOptions{ |
| 115 | + namespace: "default", |
| 116 | + groupName: "example-group", |
| 117 | + image: "rayproject/ray:latest", |
| 118 | + rayVersion: "latest", |
| 119 | + }, |
111 | 120 | }, |
112 | 121 | { |
113 | 122 | name: "mMissing group name", |
@@ -181,12 +190,16 @@ func TestCreateWorkerGroupCommandComplete(t *testing.T) { |
181 | 190 |
|
182 | 191 | for _, tt := range tests { |
183 | 192 | t.Run(tt.name, func(t *testing.T) { |
184 | | - cmd := &cobra.Command{} |
| 193 | + configFlags := genericclioptions.NewConfigFlags(true) |
| 194 | + cmd := &cobra.Command{} |
| 195 | + configFlags.AddFlags(cmd.Flags()) |
185 | 196 | for key, value := range tt.flags { |
186 | | - cmd.Flags().String(key, value, "") |
| 197 | + cmd.Flags().Set(key, value) |
187 | 198 | } |
188 | 199 |
|
| 200 | + factory := cmdutil.NewFactory(configFlags) |
189 | 201 | options := &CreateWorkerGroupOptions{ |
| 202 | + cmdFactory: factory, |
190 | 203 | rayVersion: "latest", |
191 | 204 | } |
192 | 205 |
|
|
0 commit comments