@@ -71,12 +71,12 @@ func TestPodsTopMetricsAvailable(t *testing.T) {
7171 if req .URL .Path == "/apis/metrics.k8s.io/v1beta1/pods" {
7272 if req .URL .Query ().Get ("labelSelector" ) == "app=pod-ns-5-42" {
7373 _ , _ = w .Write ([]byte (`{"kind":"PodMetricsList","apiVersion":"metrics.k8s.io/v1beta1","items":[` +
74- `{"metadata":{"name":"pod-ns-5-42","namespace":"ns-5"},"containers":[{"name":"container-1","usage":{"cpu":"42m","memory":"42Mi"}}]}` +
74+ `{"metadata":{"name":"pod-ns-5-42","namespace":"ns-5"},"containers":[{"name":"container-1","usage":{"cpu":"42m","memory":"42Mi","swap":"42Mi" }}]}` +
7575 `]}` ))
7676 } else {
7777 _ , _ = w .Write ([]byte (`{"kind":"PodMetricsList","apiVersion":"metrics.k8s.io/v1beta1","items":[` +
78- `{"metadata":{"name":"pod-1","namespace":"default"},"containers":[{"name":"container-1","usage":{"cpu":"100m","memory":"200Mi"}},{"name":"container-2","usage":{"cpu":"200m","memory":"300Mi"}}]},` +
79- `{"metadata":{"name":"pod-2","namespace":"ns-1"},"containers":[{"name":"container-1-ns-1","usage":{"cpu":"300m","memory":"400Mi"}}]}` +
78+ `{"metadata":{"name":"pod-1","namespace":"default"},"containers":[{"name":"container-1","usage":{"cpu":"100m","memory":"200Mi","swap":"13Mi" }},{"name":"container-2","usage":{"cpu":"200m","memory":"300Mi","swap":"37Mi "}}]},` +
79+ `{"metadata":{"name":"pod-2","namespace":"ns-1"},"containers":[{"name":"container-1-ns-1","usage":{"cpu":"300m","memory":"400Mi","swap":"42Mi" }}]}` +
8080 `]}` ))
8181
8282 }
@@ -85,22 +85,22 @@ func TestPodsTopMetricsAvailable(t *testing.T) {
8585 // Pod Metrics from configured namespace
8686 if req .URL .Path == "/apis/metrics.k8s.io/v1beta1/namespaces/default/pods" {
8787 _ , _ = w .Write ([]byte (`{"kind":"PodMetricsList","apiVersion":"metrics.k8s.io/v1beta1","items":[` +
88- `{"metadata":{"name":"pod-1","namespace":"default"},"containers":[{"name":"container-1","usage":{"cpu":"10m","memory":"20Mi"}},{"name":"container-2","usage":{"cpu":"30m","memory":"40Mi"}}]}` +
88+ `{"metadata":{"name":"pod-1","namespace":"default"},"containers":[{"name":"container-1","usage":{"cpu":"10m","memory":"20Mi","swap":"13Mi" }},{"name":"container-2","usage":{"cpu":"30m","memory":"40Mi","swap":"37Mi "}}]}` +
8989 `]}` ))
9090 return
9191 }
9292 // Pod Metrics from ns-5 namespace
9393 if req .URL .Path == "/apis/metrics.k8s.io/v1beta1/namespaces/ns-5/pods" {
9494 _ , _ = w .Write ([]byte (`{"kind":"PodMetricsList","apiVersion":"metrics.k8s.io/v1beta1","items":[` +
95- `{"metadata":{"name":"pod-ns-5-1","namespace":"ns-5"},"containers":[{"name":"container-1","usage":{"cpu":"10m","memory":"20Mi"}}]}` +
95+ `{"metadata":{"name":"pod-ns-5-1","namespace":"ns-5"},"containers":[{"name":"container-1","usage":{"cpu":"10m","memory":"20Mi","swap":"42Mi" }}]}` +
9696 `]}` ))
9797 return
9898 }
9999 // Pod Metrics from ns-5 namespace with pod-ns-5-5 pod name
100100 if req .URL .Path == "/apis/metrics.k8s.io/v1beta1/namespaces/ns-5/pods/pod-ns-5-5" {
101101 _ , _ = w .Write ([]byte (`{"kind":"PodMetrics","apiVersion":"metrics.k8s.io/v1beta1",` +
102102 `"metadata":{"name":"pod-ns-5-5","namespace":"ns-5"},` +
103- `"containers":[{"name":"container-1","usage":{"cpu":"13m","memory":"37Mi"}}]` +
103+ `"containers":[{"name":"container-1","usage":{"cpu":"13m","memory":"37Mi","swap":"42Mi" }}]` +
104104 `}` ))
105105 }
106106 }))
@@ -113,21 +113,21 @@ func TestPodsTopMetricsAvailable(t *testing.T) {
113113 if podsTopDefaults .IsError {
114114 t .Fatalf ("call tool failed %s" , textContent )
115115 }
116- expectedHeaders := regexp .MustCompile (`(?m)^\s*NAMESPACE\s+POD\s+NAME\s+CPU\(cores\)\s+MEMORY\(bytes\)\s*$` )
116+ expectedHeaders := regexp .MustCompile (`(?m)^\s*NAMESPACE\s+POD\s+NAME\s+CPU\(cores\)\s+MEMORY\(bytes\)\s+SWAP\(bytes\)\s *$` )
117117 if ! expectedHeaders .MatchString (textContent ) {
118118 t .Errorf ("Expected headers '%s' not found in output:\n %s" , expectedHeaders .String (), textContent )
119119 }
120120 expectedRows := []string {
121- "default\\ s+pod-1\\ s+container-1\\ s+100m\\ s+200Mi" ,
122- "default\\ s+pod-1\\ s+container-2\\ s+200m\\ s+300Mi" ,
123- "ns-1\\ s+pod-2\\ s+container-1-ns-1\\ s+300m\\ s+400Mi" ,
121+ "default\\ s+pod-1\\ s+container-1\\ s+100m\\ s+200Mi\\ s+13Mi " ,
122+ "default\\ s+pod-1\\ s+container-2\\ s+200m\\ s+300Mi\\ s+37Mi " ,
123+ "ns-1\\ s+pod-2\\ s+container-1-ns-1\\ s+300m\\ s+400Mi\\ s+42Mi " ,
124124 }
125125 for _ , row := range expectedRows {
126126 if ! regexp .MustCompile (row ).MatchString (textContent ) {
127127 t .Errorf ("Expected row '%s' not found in output:\n %s" , row , textContent )
128128 }
129129 }
130- expectedTotal := regexp .MustCompile (`(?m)^\s+600m\s+900Mi\s*$` )
130+ expectedTotal := regexp .MustCompile (`(?m)^\s+600m\s+900Mi\s+92Mi\s *$` )
131131 if ! expectedTotal .MatchString (textContent ) {
132132 t .Errorf ("Expected total row '%s' not found in output:\n %s" , expectedTotal .String (), textContent )
133133 }
@@ -141,15 +141,15 @@ func TestPodsTopMetricsAvailable(t *testing.T) {
141141 }
142142 textContent := podsTopConfiguredNamespace .Content [0 ].(mcp.TextContent ).Text
143143 expectedRows := []string {
144- "default\\ s+pod-1\\ s+container-1\\ s+10m\\ s+20Mi" ,
145- "default\\ s+pod-1\\ s+container-2\\ s+30m\\ s+40Mi" ,
144+ "default\\ s+pod-1\\ s+container-1\\ s+10m\\ s+20Mi\\ s+13Mi " ,
145+ "default\\ s+pod-1\\ s+container-2\\ s+30m\\ s+40Mi\\ s+37Mi " ,
146146 }
147147 for _ , row := range expectedRows {
148148 if ! regexp .MustCompile (row ).MatchString (textContent ) {
149149 t .Errorf ("Expected row '%s' not found in output:\n %s" , row , textContent )
150150 }
151151 }
152- expectedTotal := regexp .MustCompile (`(?m)^\s+40m\s+60Mi\s*$` )
152+ expectedTotal := regexp .MustCompile (`(?m)^\s+40m\s+60Mi\s+50Mi\s *$` )
153153 if ! expectedTotal .MatchString (textContent ) {
154154 t .Errorf ("Expected total row '%s' not found in output:\n %s" , expectedTotal .String (), textContent )
155155 }
@@ -162,11 +162,11 @@ func TestPodsTopMetricsAvailable(t *testing.T) {
162162 t .Fatalf ("call tool failed %v" , err )
163163 }
164164 textContent := podsTopNamespace .Content [0 ].(mcp.TextContent ).Text
165- expectedRow := regexp .MustCompile (`ns-5\s+pod-ns-5-1\s+container-1\s+10m\s+20Mi` )
165+ expectedRow := regexp .MustCompile (`ns-5\s+pod-ns-5-1\s+container-1\s+10m\s+20Mi\s+42Mi ` )
166166 if ! expectedRow .MatchString (textContent ) {
167167 t .Errorf ("Expected row '%s' not found in output:\n %s" , expectedRow .String (), textContent )
168168 }
169- expectedTotal := regexp .MustCompile (`(?m)^\s+10m\s+20Mi\s*$` )
169+ expectedTotal := regexp .MustCompile (`(?m)^\s+10m\s+20Mi\s+42Mi\s *$` )
170170 if ! expectedTotal .MatchString (textContent ) {
171171 t .Errorf ("Expected total row '%s' not found in output:\n %s" , expectedTotal .String (), textContent )
172172 }
@@ -180,11 +180,11 @@ func TestPodsTopMetricsAvailable(t *testing.T) {
180180 t .Fatalf ("call tool failed %v" , err )
181181 }
182182 textContent := podsTopNamespaceName .Content [0 ].(mcp.TextContent ).Text
183- expectedRow := regexp .MustCompile (`ns-5\s+pod-ns-5-5\s+container-1\s+13m\s+37Mi` )
183+ expectedRow := regexp .MustCompile (`ns-5\s+pod-ns-5-5\s+container-1\s+13m\s+37Mi\s+42Mi ` )
184184 if ! expectedRow .MatchString (textContent ) {
185185 t .Errorf ("Expected row '%s' not found in output:\n %s" , expectedRow .String (), textContent )
186186 }
187- expectedTotal := regexp .MustCompile (`(?m)^\s+13m\s+37Mi\s*$` )
187+ expectedTotal := regexp .MustCompile (`(?m)^\s+13m\s+37Mi\s+42Mi\s *$` )
188188 if ! expectedTotal .MatchString (textContent ) {
189189 t .Errorf ("Expected total row '%s' not found in output:\n %s" , expectedTotal .String (), textContent )
190190 }
@@ -201,7 +201,7 @@ func TestPodsTopMetricsAvailable(t *testing.T) {
201201 if ! expectedRow .MatchString (textContent ) {
202202 t .Errorf ("Expected row '%s' not found in output:\n %s" , expectedRow .String (), textContent )
203203 }
204- expectedTotal := regexp .MustCompile (`(?m)^\s+42m\s+42Mi\s*$` )
204+ expectedTotal := regexp .MustCompile (`(?m)^\s+42m\s+42Mi\s+42Mi\s *$` )
205205 if ! expectedTotal .MatchString (textContent ) {
206206 t .Errorf ("Expected total row '%s' not found in output:\n %s" , expectedTotal .String (), textContent )
207207 }
0 commit comments