Added tow new tests, checking for no credentials and no server
This commit is contained in:
@@ -23,6 +23,16 @@ namespace k8s.Tests
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private static readonly string kubeConfigUserPassword = "assets/kubeconfig.user-pass.yml";
|
private static readonly string kubeConfigUserPassword = "assets/kubeconfig.user-pass.yml";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sample configuration file with incorrect user credentials structures on purpose
|
||||||
|
/// </summary>
|
||||||
|
private static readonly string kubeConfigNoCredentials = "assets/kubeconfig.no-credentials.yml";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sample configuration file with incorrect cluster/server structure on purpose
|
||||||
|
/// </summary>
|
||||||
|
private static readonly string kubeConfigNoServer = "assets/kubeconfig.no-server.yml";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The configuration file is not present. An KubeConfigException should be thrown
|
/// The configuration file is not present. An KubeConfigException should be thrown
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -132,6 +142,26 @@ namespace k8s.Tests
|
|||||||
Assert.Equal("secret", cfg.Password);
|
Assert.Equal("secret", cfg.Password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks that a KubeConfigException is thrown when incomplete user credentials
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void IncompleteUserCredentials()
|
||||||
|
{
|
||||||
|
var fi = new FileInfo(kubeConfigNoCredentials);
|
||||||
|
Assert.Throws<k8s.Exceptions.KubeConfigException>(() => new KubernetesClientConfiguration(fi));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks that a KubeConfigException is thrown when the server property is not set in cluster
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void ServerNotFound()
|
||||||
|
{
|
||||||
|
var fi = new FileInfo(kubeConfigNoServer);
|
||||||
|
Assert.Throws<k8s.Exceptions.KubeConfigException>(() => new KubernetesClientConfiguration(fi));
|
||||||
|
}
|
||||||
|
|
||||||
// /// <summary>
|
// /// <summary>
|
||||||
// /// Checks if the are pods
|
// /// Checks if the are pods
|
||||||
// /// </summary>
|
// /// </summary>
|
||||||
|
|||||||
20
tests/assets/kubeconfig.no-credentials.yml
Normal file
20
tests/assets/kubeconfig.no-credentials.yml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# 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
|
||||||
|
clusters:
|
||||||
|
- cluster:
|
||||||
|
certificate-authority-data: path/to/my/cafile
|
||||||
|
server: https://horse.org:4443
|
||||||
|
name: horse-cluster
|
||||||
|
contexts:
|
||||||
|
- context:
|
||||||
|
cluster: horse-cluster
|
||||||
|
namespace: chisel-ns
|
||||||
|
user: green-user
|
||||||
|
name: federal-context
|
||||||
|
kind: Config
|
||||||
|
users:
|
||||||
|
- name: green-user
|
||||||
|
user:
|
||||||
21
tests/assets/kubeconfig.no-server.yml
Normal file
21
tests/assets/kubeconfig.no-server.yml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# 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
|
||||||
|
clusters:
|
||||||
|
- cluster:
|
||||||
|
certificate-authority-data: path/to/my/cafile
|
||||||
|
name: horse-cluster
|
||||||
|
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
|
||||||
Reference in New Issue
Block a user