@@ -80,6 +80,75 @@ func TestNewListCmdOutputsJSON(t *testing.T) {
8080 }
8181}
8282
83+ func TestNewListCmdDefaultsToAllNamespacesForCurrentOwner (t * testing.T ) {
84+ server := httptest .NewTLSServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
85+ w .Header ().Set ("Content-Type" , "application/json" )
86+ switch r .URL .Path {
87+ case "/api/v1/pods" :
88+ _ , _ = io .WriteString (w , `{"kind":"PodList","apiVersion":"v1","items":[{"metadata":{"namespace":"proj-tango","name":"okdev-sess-a","creationTimestamp":"2026-03-29T00:00:00Z","labels":{"okdev.io/session":"sess-a","okdev.io/owner":"alice","okdev.io/workload-type":"pod"}},"status":{"phase":"Running","containerStatuses":[{"name":"dev","ready":true,"restartCount":1}]}}]}` )
89+ case "/api/v1/namespaces/default/pods" :
90+ _ , _ = io .WriteString (w , `{"kind":"PodList","apiVersion":"v1","items":[]}` )
91+ default :
92+ http .NotFound (w , r )
93+ }
94+ }))
95+ defer server .Close ()
96+
97+ t .Setenv ("KUBECONFIG" , writeCLITLSTestKubeconfig (t , server ))
98+ cfgPath := writeCLIConfig (t , "default" )
99+ opts := & Options {ConfigPath : cfgPath , Context : "dev" , Output : "json" , Owner : "alice" }
100+ cmd := newListCmd (opts )
101+ var out bytes.Buffer
102+ cmd .SetOut (& out )
103+ cmd .SetErr (io .Discard )
104+
105+ if err := cmd .Execute (); err != nil {
106+ t .Fatalf ("list execute: %v" , err )
107+ }
108+
109+ var rows []map [string ]any
110+ if err := json .Unmarshal (out .Bytes (), & rows ); err != nil {
111+ t .Fatalf ("json unmarshal: %v\n %s" , err , out .String ())
112+ }
113+ if len (rows ) != 1 || rows [0 ]["session" ] != "sess-a" || rows [0 ]["namespace" ] != "proj-tango" {
114+ t .Fatalf ("unexpected list rows: %#v" , rows )
115+ }
116+ }
117+
118+ func TestNewListCmdNamespaceOverrideNarrowsResults (t * testing.T ) {
119+ server := httptest .NewTLSServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
120+ w .Header ().Set ("Content-Type" , "application/json" )
121+ switch r .URL .Path {
122+ case "/api/v1/namespaces/demo/pods" :
123+ _ , _ = io .WriteString (w , `{"kind":"PodList","apiVersion":"v1","items":[{"metadata":{"namespace":"demo","name":"okdev-sess-a","creationTimestamp":"2026-03-29T00:00:00Z","labels":{"okdev.io/session":"sess-a","okdev.io/owner":"alice","okdev.io/workload-type":"pod"}},"status":{"phase":"Running","containerStatuses":[{"name":"dev","ready":true,"restartCount":1}]}}]}` )
124+ case "/api/v1/pods" :
125+ _ , _ = io .WriteString (w , `{"kind":"PodList","apiVersion":"v1","items":[{"metadata":{"namespace":"proj-tango","name":"okdev-sess-b","creationTimestamp":"2026-03-29T00:00:00Z","labels":{"okdev.io/session":"sess-b","okdev.io/owner":"alice","okdev.io/workload-type":"pod"}},"status":{"phase":"Running","containerStatuses":[{"name":"dev","ready":true,"restartCount":1}]}}]}` )
126+ default :
127+ http .NotFound (w , r )
128+ }
129+ }))
130+ defer server .Close ()
131+
132+ t .Setenv ("KUBECONFIG" , writeCLITLSTestKubeconfig (t , server ))
133+ opts := & Options {Namespace : "demo" , Context : "dev" , Output : "json" , Owner : "alice" }
134+ cmd := newListCmd (opts )
135+ var out bytes.Buffer
136+ cmd .SetOut (& out )
137+ cmd .SetErr (io .Discard )
138+
139+ if err := cmd .Execute (); err != nil {
140+ t .Fatalf ("list execute: %v" , err )
141+ }
142+
143+ var rows []map [string ]any
144+ if err := json .Unmarshal (out .Bytes (), & rows ); err != nil {
145+ t .Fatalf ("json unmarshal: %v\n %s" , err , out .String ())
146+ }
147+ if len (rows ) != 1 || rows [0 ]["session" ] != "sess-a" || rows [0 ]["namespace" ] != "demo" {
148+ t .Fatalf ("unexpected list rows: %#v" , rows )
149+ }
150+ }
151+
83152func TestNewStatusCmdDetailsRequiresSingleSession (t * testing.T ) {
84153 server := httptest .NewTLSServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
85154 w .Header ().Set ("Content-Type" , "application/json" )
0 commit comments