@@ -3,7 +3,7 @@ import { expect } from 'chai';
3
3
import nock = require( 'nock' ) ;
4
4
import { KubeConfig } from './config' ;
5
5
import { V1Status , HttpError } from './gen/api' ;
6
- import { Metrics , NodeMetricsList , PodMetricsList } from './metrics' ;
6
+ import { Metrics , NodeMetricsList , PodMetricsList , SinglePodMetrics } from './metrics' ;
7
7
8
8
const emptyPodMetrics : PodMetricsList = {
9
9
kind : 'PodMetricsList' ,
@@ -72,6 +72,25 @@ const mockedNodeMetrics: NodeMetricsList = {
72
72
] ,
73
73
} ;
74
74
75
+ const mockedSinglePodMetrics : SinglePodMetrics = {
76
+
77
+ kind : 'PodMetrics' ,
78
+ apiVersion : 'metrics.k8s.io/v1beta1' ,
79
+ metadata : {
80
+ name : 'a-pod' ,
81
+ namespace : 'default' ,
82
+ creationTimestamp : '2021-09-26T16:01:53Z' ,
83
+ labels : {
84
+ label : 'aLabel'
85
+ }
86
+ } ,
87
+ timestamp : '2021-09-26T16:01:53Z' ,
88
+ window : '7m' ,
89
+ containers : [
90
+ { name : 'nginx' , usage : { cpu : '4414124n' , memory : '123Ki' } }
91
+ ] ,
92
+ } ;
93
+
75
94
const TEST_NAMESPACE = 'test-namespace' ;
76
95
77
96
const testConfigOptions : any = {
@@ -128,6 +147,7 @@ describe('Metrics', () => {
128
147
129
148
s . done ( ) ;
130
149
} ) ;
150
+
131
151
it ( 'should return namespace scope pods metric list' , async ( ) => {
132
152
const [ metricsClient , scope ] = systemUnderTest ( ) ;
133
153
const s = scope
@@ -138,6 +158,18 @@ describe('Metrics', () => {
138
158
expect ( response ) . to . deep . equal ( mockedPodMetrics ) ;
139
159
s . done ( ) ;
140
160
} ) ;
161
+ it ( 'should return single pod metrics if given namespace and pod name' , async ( ) => {
162
+ const podName = 'pod-name' ;
163
+ const [ metricsClient , scope ] = systemUnderTest ( ) ;
164
+ const s = scope
165
+ . get ( `/apis/metrics.k8s.io/v1beta1/namespaces/${ TEST_NAMESPACE } /pods/${ podName } ` )
166
+ . reply ( 200 , mockedSinglePodMetrics ) ;
167
+
168
+ const response = await metricsClient . getPodMetrics ( TEST_NAMESPACE , podName ) ;
169
+ expect ( response ) . to . deep . equal ( mockedSinglePodMetrics ) ;
170
+
171
+ s . done ( ) ;
172
+ } ) ;
141
173
it ( 'should when connection refused' , async ( ) => {
142
174
const kc = new KubeConfig ( ) ;
143
175
kc . loadFromOptions ( {
0 commit comments