@@ -10,13 +10,12 @@ public class KubernetesMetricsTests
10
10
{
11
11
private readonly ITestOutputHelper testOutput ;
12
12
13
- // Copy / Paste from metrics server on minikube
13
+ // All payloads' response are Copy / Paste from metrics server on minikube
14
14
public const string NodeMetricsResponse = "{\n \" kind\" : \" NodeMetricsList\" ,\n \" apiVersion\" : \" metrics.k8s.io/v1beta1\" ,\n \" metadata\" : {\n \" selfLink\" : \" /apis/metrics.k8s.io/v1beta1/nodes/\" \n },\n \" items\" : [\n {\n \" metadata\" : {\n \" name\" : \" minikube\" ,\n \" selfLink\" : \" /apis/metrics.k8s.io/v1beta1/nodes/minikube\" ,\n \" creationTimestamp\" : \" 2020-07-28T20:01:05Z\" \n },\n \" timestamp\" : \" 2020-07-28T20:01:00Z\" ,\n \" window\" : \" 1m0s\" ,\n \" usage\" : {\n \" cpu\" : \" 394m\" ,\n \" memory\" : \" 1948140Ki\" \n }\n }\n ]\n }" ;
15
- // Copy / Paste from metrics server minikube
15
+ public const string OptionalPropertyNodeMetricsResponse = "{ \n \" kind \" : \" NodeMetricsList \" , \n \" apiVersion \" : \" metrics.k8s.io/v1beta1 \" , \n \" metadata \" : { \n \" selfLink \" : \" /apis/ metrics.k8s.io/v1beta1/nodes/ \" \n }, \n \" items \" : [ \n { \n \" metadata \" : { \n \" name \" : \" minikube\" , \n \" selfLink \" : \" /apis/metrics.k8s.io/v1beta1/nodes/minikube \" , \n \" creationTimestamp \" : \" 2020-07-28T20:01:05Z \" \n }, \n \" timestamp \" : null, \n \" window \" : \" 1m0s \" , \n \" usage \" : { \n \" cpu \" : \" 394m \" , \n \" memory \" : \" 1948140Ki \" \n } \n } \n ] \n }" ;
16
16
public const string PodMetricsResponse = "{\n \" kind\" : \" PodMetricsList\" ,\n \" apiVersion\" : \" metrics.k8s.io/v1beta1\" ,\n \" metadata\" : {\n \" selfLink\" : \" /apis/metrics.k8s.io/v1beta1/namespaces/default/pods/\" \n },\n \" items\" : [\n {\n \" metadata\" : {\n \" name\" : \" dotnet-test-d4894bfbd-2q2dw\" ,\n \" namespace\" : \" default\" ,\n \" selfLink\" : \" /apis/metrics.k8s.io/v1beta1/namespaces/default/pods/dotnet-test-d4894bfbd-2q2dw\" ,\n \" creationTimestamp\" : \" 2020-08-01T07:40:05Z\" \n },\n \" timestamp\" : \" 2020-08-01T07:40:00Z\" ,\n \" window\" : \" 1m0s\" ,\n \" containers\" : [\n {\n \" name\" : \" dotnet-test\" ,\n \" usage\" : {\n \" cpu\" : \" 0\" ,\n \" memory\" : \" 14512Ki\" \n }\n }\n ]\n }\n ]\n }" ;
17
- // Copy / Paste from metrics server minikube
17
+ public const string OptionalPropertyPodMetricsResponse = "{ \n \" kind \" : \" PodMetricsList \" , \n \" apiVersion \" : \" metrics.k8s.io/v1beta1 \" , \n \" metadata \" : { \n \" selfLink \" : \" /apis/metrics.k8s.io/v1beta1/namespaces/default/pods/ \" \n }, \n \" items \" : [ \n { \n \" metadata \" : { \n \" name \" : \" dotnet-test-d4894bfbd-2q2dw \" , \n \" namespace \" : \" default \" , \n \" selfLink \" : \" /apis/metrics.k8s.io/v1beta1/namespaces/default/pods/dotnet-test-d4894bfbd-2q2dw \" , \n \" creationTimestamp \" : \" 2020-08-01T07:40:05Z \" \n }, \n \" timestamp \" : null, \n \" window \" : \" 1m0s \" , \n \" containers \" : [ \n { \n \" name \" : \" dotnet-test \" , \n \" usage \" : { \n \" cpu \" : \" 0 \" , \n \" memory \" : \" 14512Ki \" \n } \n } \n ] \n } \n ] \n }" ; // Copy / Paste from metrics server minikube
18
18
public const string EmptyPodMetricsResponse = "{\n \" kind\" : \" PodMetricsList\" ,\n \" apiVersion\" : \" metrics.k8s.io/v1beta1\" ,\n \" metadata\" : {\n \" selfLink\" : \" /apis/metrics.k8s.io/v1beta1/namespaces/empty/pods/\" \n },\n \" items\" : []\n }" ;
19
- // Copy / Paste from metrics server minikube
20
19
public const string NonExistingNamespaceResponse = "{\n \" kind\" : \" PodMetricsList\" ,\n \" apiVersion\" : \" metrics.k8s.io/v1beta1\" ,\n \" metadata\" : {\n \" selfLink\" : \" /apis/metrics.k8s.io/v1beta1/namespaces/nonexisting/pods/\" \n },\n \" items\" : []\n }" ;
21
20
22
21
public const string DefaultNodeName = "minikube" ;
@@ -49,6 +48,20 @@ public async Task NodesMetrics()
49
48
}
50
49
}
51
50
51
+ [ Fact ( DisplayName = "Node metrics optionnal property" ) ]
52
+ public async Task NodesMetricsOptionalProperty ( )
53
+ {
54
+ using ( var server = new MockKubeApiServer ( testOutput , resp : OptionalPropertyNodeMetricsResponse ) )
55
+ {
56
+ var client = new Kubernetes ( new KubernetesClientConfiguration { Host = server . Uri . ToString ( ) } ) ;
57
+
58
+ // Should not throw with timespan optional property
59
+ var exception = await Record . ExceptionAsync ( async ( ) => await client . GetKubernetesNodesMetricsAsync ( ) . ConfigureAwait ( false ) ) . ConfigureAwait ( false ) ;
60
+
61
+ Assert . Null ( exception ) ;
62
+ }
63
+ }
64
+
52
65
[ Fact ( DisplayName = "Pod metrics" ) ]
53
66
public async Task PodsMetrics ( )
54
67
{
@@ -73,6 +86,20 @@ public async Task PodsMetrics()
73
86
}
74
87
}
75
88
89
+ [ Fact ( DisplayName = "Pod metrics optionnal property" ) ]
90
+ public async Task PodsMetricsOptionalProperty ( )
91
+ {
92
+ using ( var server = new MockKubeApiServer ( testOutput , resp : OptionalPropertyPodMetricsResponse ) )
93
+ {
94
+ var client = new Kubernetes ( new KubernetesClientConfiguration { Host = server . Uri . ToString ( ) } ) ;
95
+
96
+ // Should not throw with timespan optional property
97
+ var exception = await Record . ExceptionAsync ( async ( ) => await client . GetKubernetesPodsMetricsAsync ( ) . ConfigureAwait ( false ) ) . ConfigureAwait ( false ) ;
98
+
99
+ Assert . Null ( exception ) ;
100
+ }
101
+ }
102
+
76
103
[ Fact ( DisplayName = "Pod metrics empty response" ) ]
77
104
public async Task PodsMetricsEmptyResponse ( )
78
105
{
0 commit comments