Skip to content

Commit c38ee42

Browse files
committed
Added a test to check the behaviour when no clusters are present in the configuration file
1 parent b69f070 commit c38ee42

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

tests/KubernetesClientConfigurationTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public class KubernetesClientConfigurationTests
3333
/// </summary>
3434
private static readonly string kubeConfigNoServer = "assets/kubeconfig.no-server.yml";
3535

36+
/// <summary>
37+
/// Sample configuration file with incorrect cluster/server structure on purpose
38+
/// </summary>
39+
private static readonly string kubeConfigNoCluster = "assets/kubeconfig.no-cluster.yml";
40+
3641
/// <summary>
3742
/// The configuration file is not present. An KubeConfigException should be thrown
3843
/// </summary>
@@ -162,6 +167,16 @@ public void ServerNotFound()
162167
Assert.Throws<k8s.Exceptions.KubeConfigException>(() => new KubernetesClientConfiguration(fi));
163168
}
164169

170+
/// <summary>
171+
/// Checks that a KubeConfigException is thrown when the clusters section is missing
172+
/// </summary>
173+
[Fact]
174+
public void ClusterNotFound()
175+
{
176+
var fi = new FileInfo(kubeConfigNoCluster);
177+
Assert.Throws<k8s.Exceptions.KubeConfigException>(() => new KubernetesClientConfiguration(fi));
178+
}
179+
165180
// /// <summary>
166181
// /// Checks if the are pods
167182
// /// </summary>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Sample file based on https://kubernetes.io/docs/tasks/access-application-cluster/authenticate-across-clusters-kubeconfig/
2+
# WARNING: File includes minor fixes
3+
---
4+
current-context: federal-context
5+
apiVersion: v1
6+
contexts:
7+
- context:
8+
cluster: horse-cluster
9+
namespace: chisel-ns
10+
user: green-user
11+
name: federal-context
12+
kind: Config
13+
users:
14+
- name: green-user
15+
user:
16+
password: secret
17+
username: admin

0 commit comments

Comments
 (0)