From c38ee42c37c7288e4a0d6a5bf9c37845a30555da Mon Sep 17 00:00:00 2001 From: Sergio Sisternes Date: Tue, 27 Jun 2017 20:09:08 +0200 Subject: [PATCH] Added a test to check the behaviour when no clusters are present in the configuration file --- tests/KubernetesClientConfigurationTests.cs | 15 +++++++++++++++ tests/assets/kubeconfig.no-cluster.yml | 17 +++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 tests/assets/kubeconfig.no-cluster.yml diff --git a/tests/KubernetesClientConfigurationTests.cs b/tests/KubernetesClientConfigurationTests.cs index 9d05b07..2417802 100755 --- a/tests/KubernetesClientConfigurationTests.cs +++ b/tests/KubernetesClientConfigurationTests.cs @@ -33,6 +33,11 @@ namespace k8s.Tests /// private static readonly string kubeConfigNoServer = "assets/kubeconfig.no-server.yml"; + /// + /// Sample configuration file with incorrect cluster/server structure on purpose + /// + private static readonly string kubeConfigNoCluster = "assets/kubeconfig.no-cluster.yml"; + /// /// The configuration file is not present. An KubeConfigException should be thrown /// @@ -162,6 +167,16 @@ namespace k8s.Tests Assert.Throws(() => new KubernetesClientConfiguration(fi)); } + /// + /// Checks that a KubeConfigException is thrown when the clusters section is missing + /// + [Fact] + public void ClusterNotFound() + { + var fi = new FileInfo(kubeConfigNoCluster); + Assert.Throws(() => new KubernetesClientConfiguration(fi)); + } + // /// // /// Checks if the are pods // /// diff --git a/tests/assets/kubeconfig.no-cluster.yml b/tests/assets/kubeconfig.no-cluster.yml new file mode 100644 index 0000000..a3a79c2 --- /dev/null +++ b/tests/assets/kubeconfig.no-cluster.yml @@ -0,0 +1,17 @@ +# Sample file based on https://kubernetes.io/docs/tasks/access-application-cluster/authenticate-across-clusters-kubeconfig/ +# WARNING: File includes minor fixes +--- +current-context: federal-context +apiVersion: v1 +contexts: +- context: + cluster: horse-cluster + namespace: chisel-ns + user: green-user + name: federal-context +kind: Config +users: +- name: green-user + user: + password: secret + username: admin \ No newline at end of file