@@ -32,6 +32,7 @@ import (
3232 "github.com/NVIDIA/skyhook/operator/api/v1alpha1"
3333 "github.com/NVIDIA/skyhook/operator/internal/cli/client"
3434 "github.com/NVIDIA/skyhook/operator/internal/cli/context"
35+ "github.com/NVIDIA/skyhook/operator/internal/cli/utils"
3536)
3637
3738var _ = Describe ("Node List Command" , func () {
@@ -58,14 +59,6 @@ var _ = Describe("Node List Command", func() {
5859 Expect (err .Error ()).To (ContainSubstring ("skyhook" ))
5960 })
6061
61- It ("should have output flag" , func () {
62- ctx := context .NewCLIContext (nil )
63- cmd := NewListCmd (ctx )
64-
65- outputFlag := cmd .Flags ().Lookup ("output" )
66- Expect (outputFlag ).NotTo (BeNil ())
67- Expect (outputFlag .Shorthand ).To (Equal ("o" ))
68- })
6962 })
7063
7164 Describe ("outputNodeListTableOrWide" , func () {
@@ -123,12 +116,14 @@ var _ = Describe("Node List Command", func() {
123116 output * bytes.Buffer
124117 mockKube * fake.Clientset
125118 kubeClient * client.Client
119+ cliCtx * context.CLIContext
126120 )
127121
128122 BeforeEach (func () {
129123 output = & bytes.Buffer {}
130124 mockKube = fake .NewSimpleClientset ()
131125 kubeClient = client .NewWithClientsAndConfig (mockKube , nil , nil )
126+ cliCtx = context .NewCLIContext (context .NewCLIConfig (context .WithOutputWriter (output )))
132127 })
133128
134129 It ("should show no nodes when none have the skyhook" , func () {
@@ -141,8 +136,8 @@ var _ = Describe("Node List Command", func() {
141136 _ , err := mockKube .CoreV1 ().Nodes ().Create (gocontext .Background (), node , metav1.CreateOptions {})
142137 Expect (err ).NotTo (HaveOccurred ())
143138
144- opts := & nodeListOptions {skyhookName : "my-skyhook" , output : "table" }
145- err = runNodeList (gocontext .Background (), output , kubeClient , opts )
139+ opts := & nodeListOptions {skyhookName : "my-skyhook" }
140+ err = runNodeList (gocontext .Background (), kubeClient , opts , cliCtx )
146141 Expect (err ).NotTo (HaveOccurred ())
147142 Expect (output .String ()).To (ContainSubstring ("No nodes found" ))
148143 })
@@ -166,8 +161,8 @@ var _ = Describe("Node List Command", func() {
166161 Expect (err ).NotTo (HaveOccurred ())
167162 }
168163
169- opts := & nodeListOptions {skyhookName : "my-skyhook" , output : "table" }
170- err := runNodeList (gocontext .Background (), output , kubeClient , opts )
164+ opts := & nodeListOptions {skyhookName : "my-skyhook" }
165+ err := runNodeList (gocontext .Background (), kubeClient , opts , cliCtx )
171166 Expect (err ).NotTo (HaveOccurred ())
172167
173168 outputStr := output .String ()
@@ -209,8 +204,8 @@ var _ = Describe("Node List Command", func() {
209204 _ , err = mockKube .CoreV1 ().Nodes ().Create (gocontext .Background (), node2 , metav1.CreateOptions {})
210205 Expect (err ).NotTo (HaveOccurred ())
211206
212- opts := & nodeListOptions {skyhookName : "skyhook-a" , output : "table" }
213- err = runNodeList (gocontext .Background (), output , kubeClient , opts )
207+ opts := & nodeListOptions {skyhookName : "skyhook-a" }
208+ err = runNodeList (gocontext .Background (), kubeClient , opts , cliCtx )
214209 Expect (err ).NotTo (HaveOccurred ())
215210
216211 outputStr := output .String ()
@@ -235,8 +230,9 @@ var _ = Describe("Node List Command", func() {
235230 _ , err := mockKube .CoreV1 ().Nodes ().Create (gocontext .Background (), node , metav1.CreateOptions {})
236231 Expect (err ).NotTo (HaveOccurred ())
237232
238- opts := & nodeListOptions {skyhookName : "my-skyhook" , output : "json" }
239- err = runNodeList (gocontext .Background (), output , kubeClient , opts )
233+ opts := & nodeListOptions {skyhookName : "my-skyhook" }
234+ cliCtx .GlobalFlags .OutputFormat = utils .OutputFormatJSON
235+ err = runNodeList (gocontext .Background (), kubeClient , opts , cliCtx )
240236 Expect (err ).NotTo (HaveOccurred ())
241237
242238 var result struct {
@@ -291,8 +287,9 @@ var _ = Describe("Node List Command", func() {
291287 Expect (err ).NotTo (HaveOccurred ())
292288 }
293289
294- opts := & nodeListOptions {skyhookName : "my-skyhook" , output : "json" }
295- err := runNodeList (gocontext .Background (), output , kubeClient , opts )
290+ opts := & nodeListOptions {skyhookName : "my-skyhook" }
291+ cliCtx .GlobalFlags .OutputFormat = utils .OutputFormatJSON
292+ err := runNodeList (gocontext .Background (), kubeClient , opts , cliCtx )
296293 Expect (err ).NotTo (HaveOccurred ())
297294
298295 var result struct {
0 commit comments