1
- using Xunit ;
1
+ using Xunit ;
2
2
using System . IO ;
3
3
4
4
namespace k8s . Tests
5
5
{
6
6
public class KubernetesClientConfigurationTests
7
7
{
8
8
9
- public static string readLine ( string fileName ) {
10
- StreamReader reader = new StreamReader ( new FileStream ( fileName , FileMode . Open , FileAccess . Read ) ) ;
9
+ public static string readLine ( string fileName )
10
+ {
11
+ StreamReader reader = new StreamReader ( new FileStream ( fileName , FileMode . Open , FileAccess . Read ) ) ;
11
12
return reader . ReadLine ( ) ;
12
13
}
13
14
@@ -63,7 +64,7 @@ public static string readLine(string fileName) {
63
64
public void ConfigurationFileNotFound ( )
64
65
{
65
66
var fi = new FileInfo ( "/path/to/nowhere" ) ;
66
- Assert . Throws < k8s . Exceptions . KubeConfigException > ( ( ) => new KubernetesClientConfiguration ( fi ) ) ;
67
+ Assert . Throws < k8s . Exceptions . KubeConfigException > ( ( ) => new KubernetesClientConfiguration ( fi ) ) ;
67
68
}
68
69
69
70
/// <summary>
@@ -74,17 +75,17 @@ public void DefaultConfigurationLoaded()
74
75
{
75
76
var cfg = new KubernetesClientConfiguration ( new FileInfo ( kubeConfigFileName ) ) ;
76
77
Assert . NotNull ( cfg . Host ) ;
77
- }
78
-
78
+ }
79
+
79
80
/// <summary>
80
81
/// Check if host is properly loaded, per context
81
82
/// </summary>
82
83
[ Theory ]
83
84
[ InlineData ( "federal-context" , "https://horse.org:4443" ) ]
84
85
[ InlineData ( "queen-anne-context" , "https://pig.org:443" ) ]
85
86
public void ContextHostTest ( string context , string host )
86
- {
87
- var fi = new FileInfo ( kubeConfigFileName ) ;
87
+ {
88
+ var fi = new FileInfo ( kubeConfigFileName ) ;
88
89
var cfg = new KubernetesClientConfiguration ( fi , context ) ;
89
90
Assert . Equal ( host , cfg . Host ) ;
90
91
}
@@ -99,11 +100,11 @@ public void ContextHostTest(string context, string host)
99
100
[ InlineData ( "queen-anne-context" , "black-token" ) ]
100
101
public void ContextUserTokenTest ( string context , string token )
101
102
{
102
- var fi = new FileInfo ( kubeConfigFileName ) ;
103
- var cfg = new KubernetesClientConfiguration ( fi , context ) ;
103
+ var fi = new FileInfo ( kubeConfigFileName ) ;
104
+ var cfg = new KubernetesClientConfiguration ( fi , context ) ;
104
105
Assert . Equal ( context , cfg . CurrentContext ) ;
105
106
Assert . Null ( cfg . Username ) ;
106
- Assert . Equal ( token , cfg . AccessToken ) ;
107
+ Assert . Equal ( token , cfg . AccessToken ) ;
107
108
}
108
109
109
110
/// <summary>
@@ -113,7 +114,7 @@ public void ContextUserTokenTest(string context, string token)
113
114
/// <param name="clientCertData">'client-certificate-data' node content</param>
114
115
/// <param name="clientCertKey">'client-key-data' content</param>
115
116
[ Theory ]
116
- [ InlineData ( "federal-context" , "assets/client.crt" , "assets/client.key" ) ]
117
+ [ InlineData ( "federal-context" , "assets/client.crt" , "assets/client.key" ) ]
117
118
public void ContextCertificateTest ( string context , string clientCert , string clientCertKey )
118
119
{
119
120
var fi = new FileInfo ( kubeConfigFileName ) ;
@@ -147,7 +148,7 @@ public void ClientDataTest(string context)
147
148
public void ContextNotFoundTest ( )
148
149
{
149
150
var fi = new FileInfo ( kubeConfigFileName ) ;
150
- Assert . Throws < k8s . Exceptions . KubeConfigException > ( ( ) => new KubernetesClientConfiguration ( fi , "context-not-found" ) ) ;
151
+ Assert . Throws < k8s . Exceptions . KubeConfigException > ( ( ) => new KubernetesClientConfiguration ( fi , "context-not-found" ) ) ;
151
152
}
152
153
153
154
/// <summary>
@@ -157,8 +158,8 @@ public void ContextNotFoundTest()
157
158
public void NoContexts ( )
158
159
{
159
160
var fi = new FileInfo ( kubeConfigNoContexts ) ;
160
- Assert . Throws < k8s . Exceptions . KubeConfigException > ( ( ) => new KubernetesClientConfiguration ( fi ) ) ;
161
- }
161
+ Assert . Throws < k8s . Exceptions . KubeConfigException > ( ( ) => new KubernetesClientConfiguration ( fi ) ) ;
162
+ }
162
163
163
164
/// <summary>
164
165
/// Test if KubeConfigException is thrown when no Contexts are set and we specify a concrete context name
@@ -167,7 +168,7 @@ public void NoContexts()
167
168
public void NoContextsExplicit ( )
168
169
{
169
170
var fi = new FileInfo ( kubeConfigNoContexts ) ;
170
- Assert . Throws < k8s . Exceptions . KubeConfigException > ( ( ) => new KubernetesClientConfiguration ( fi , "context" ) ) ;
171
+ Assert . Throws < k8s . Exceptions . KubeConfigException > ( ( ) => new KubernetesClientConfiguration ( fi , "context" ) ) ;
171
172
}
172
173
173
174
/// <summary>
@@ -189,7 +190,7 @@ public void UserPasswordAuthentication()
189
190
public void IncompleteUserCredentials ( )
190
191
{
191
192
var fi = new FileInfo ( kubeConfigNoCredentials ) ;
192
- Assert . Throws < k8s . Exceptions . KubeConfigException > ( ( ) => new KubernetesClientConfiguration ( fi ) ) ;
193
+ Assert . Throws < k8s . Exceptions . KubeConfigException > ( ( ) => new KubernetesClientConfiguration ( fi ) ) ;
193
194
}
194
195
195
196
/// <summary>
@@ -199,7 +200,7 @@ public void IncompleteUserCredentials()
199
200
public void ServerNotFound ( )
200
201
{
201
202
var fi = new FileInfo ( kubeConfigNoServer ) ;
202
- Assert . Throws < k8s . Exceptions . KubeConfigException > ( ( ) => new KubernetesClientConfiguration ( fi ) ) ;
203
+ Assert . Throws < k8s . Exceptions . KubeConfigException > ( ( ) => new KubernetesClientConfiguration ( fi ) ) ;
203
204
}
204
205
205
206
/// <summary>
@@ -209,17 +210,17 @@ public void ServerNotFound()
209
210
public void ClusterNotFound ( )
210
211
{
211
212
var fi = new FileInfo ( kubeConfigNoCluster ) ;
212
- Assert . Throws < k8s . Exceptions . KubeConfigException > ( ( ) => new KubernetesClientConfiguration ( fi ) ) ;
213
- }
214
-
213
+ Assert . Throws < k8s . Exceptions . KubeConfigException > ( ( ) => new KubernetesClientConfiguration ( fi ) ) ;
214
+ }
215
+
215
216
/// <summary>
216
217
/// Checks that a KubeConfigException is thrown when the cluster defined in clusters and contexts do not match
217
218
/// </summary>
218
219
[ Fact ]
219
220
public void ClusterNameMissmatch ( )
220
221
{
221
222
var fi = new FileInfo ( kubeConfigClusterMissmatch ) ;
222
- Assert . Throws < k8s . Exceptions . KubeConfigException > ( ( ) => new KubernetesClientConfiguration ( fi ) ) ;
223
+ Assert . Throws < k8s . Exceptions . KubeConfigException > ( ( ) => new KubernetesClientConfiguration ( fi ) ) ;
223
224
}
224
225
225
226
/// <summary>
@@ -229,7 +230,7 @@ public void ClusterNameMissmatch()
229
230
public void CheckClusterTlsCorrectness ( )
230
231
{
231
232
var fi = new FileInfo ( kubeConfigTlsNoSkipError ) ;
232
- Assert . Throws < k8s . Exceptions . KubeConfigException > ( ( ) => new KubernetesClientConfiguration ( fi ) ) ;
233
+ Assert . Throws < k8s . Exceptions . KubeConfigException > ( ( ) => new KubernetesClientConfiguration ( fi ) ) ;
233
234
}
234
235
235
236
/// <summary>
@@ -239,11 +240,11 @@ public void CheckClusterTlsCorrectness()
239
240
public void CheckClusterTlsSkipCorrectness ( )
240
241
{
241
242
var fi = new FileInfo ( kubeConfigTlsSkip ) ;
242
- var cfg = new KubernetesClientConfiguration ( fi ) ;
243
+ var cfg = new KubernetesClientConfiguration ( fi ) ;
243
244
Assert . NotNull ( cfg . Host ) ;
244
245
Assert . Null ( cfg . SslCaCert ) ;
245
246
Assert . True ( cfg . SkipTlsVerify ) ;
246
- }
247
+ }
247
248
248
249
// /// <summary>
249
250
// /// Checks if the are pods
0 commit comments