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