cleanup unused code and functions and fix unittest naming style

This commit is contained in:
Boshi Lian
2017-11-08 14:22:10 +08:00
parent d89293b00c
commit 950479d8a1
10 changed files with 29 additions and 95 deletions

View File

@@ -1,9 +1,10 @@
using System;
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http.Headers;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using k8s.Models;
using k8s.Tests.Mock;
@@ -22,7 +23,7 @@ namespace k8s.Tests
}
[Fact]
public void TestAnonymous()
public void Anonymous()
{
using (var server = new MockKubeApiServer())
{
@@ -55,7 +56,7 @@ namespace k8s.Tests
}
[Fact]
public void TestBasicAuth()
public void BasicAuth()
{
const string testName = "test_name";
const string testPassword = "test_password";
@@ -64,7 +65,7 @@ namespace k8s.Tests
{
var header = cxt.Request.Headers["Authorization"].FirstOrDefault();
var expect = new AuthenticationHeaderValue("Basic", Utils.Base64Encode($"{testName}:{testPassword}"))
var expect = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes($"{testName}:{testPassword}")))
.ToString();
if (header != expect)
@@ -154,7 +155,7 @@ namespace k8s.Tests
}
[Fact]
public void TestCert()
public void Cert()
{
var serverCertificateData = File.ReadAllText("assets/apiserver-pfx-data.txt");
@@ -244,7 +245,7 @@ namespace k8s.Tests
}
[Fact]
public void TestToken()
public void Token()
{
const string token = "testingtoken";
@@ -314,4 +315,4 @@ namespace k8s.Tests
}
}
}
}
}

View File

@@ -5,7 +5,7 @@ using System.IO;
namespace k8s.Tests
{
public class UtilsTests
public class CertUtilsTests
{
/// <summary>
/// This file contains a sample kubeconfig file
@@ -22,7 +22,7 @@ namespace k8s.Tests
var cfg = new KubernetesClientConfiguration(fi, "federal-context");
// Just validate that this doesn't throw and private key is non-null
var cert = Utils.GeneratePfx(cfg);
var cert = CertUtils.GeneratePfx(cfg);
Assert.NotNull(cert.PrivateKey);
}
@@ -36,8 +36,8 @@ namespace k8s.Tests
var cfg = new KubernetesClientConfiguration(fi, "victorian-context");
// Just validate that this doesn't throw and private key is non-null
var cert = Utils.GeneratePfx(cfg);
var cert = CertUtils.GeneratePfx(cfg);
Assert.NotNull(cert.PrivateKey);
}
}
}
}

View File

@@ -83,7 +83,7 @@ namespace k8s.Tests
[Theory]
[InlineData("federal-context", "https://horse.org:4443")]
[InlineData("queen-anne-context", "https://pig.org:443")]
public void ContextHostTest(string context, string host)
public void ContextHost(string context, string host)
{
var fi = new FileInfo(kubeConfigFileName);
var cfg = new KubernetesClientConfiguration(fi, context);
@@ -94,11 +94,10 @@ namespace k8s.Tests
/// Checks if user-based token is loaded properly from the config file, per context
/// </summary>
/// <param name="context"></param>
/// <param name="username"></param>
/// <param name="token"></param>
[Theory]
[InlineData("queen-anne-context", "black-token")]
public void ContextUserTokenTest(string context, string token)
public void ContextUserToken(string context, string token)
{
var fi = new FileInfo(kubeConfigFileName);
var cfg = new KubernetesClientConfiguration(fi, context);
@@ -145,7 +144,7 @@ namespace k8s.Tests
/// Test that an Exception is thrown when initializating a KubernetClientConfiguration whose config file Context is not present
/// </summary>
[Fact]
public void ContextNotFoundTest()
public void ContextNotFound()
{
var fi = new FileInfo(kubeConfigFileName);
Assert.Throws<k8s.Exceptions.KubeConfigException>(() => new KubernetesClientConfiguration(fi, "context-not-found"));

View File

@@ -42,7 +42,7 @@ namespace k8s.Tests
}
[Fact]
public void TestCannotWatch()
public void CannotWatch()
{
using (var server = new MockKubeApiServer())
{
@@ -74,7 +74,7 @@ namespace k8s.Tests
}
[Fact]
public void TestSuriveBadLine()
public void SuriveBadLine()
{
using (var server = new MockKubeApiServer(async httpContext =>
{
@@ -133,7 +133,7 @@ namespace k8s.Tests
}
[Fact]
public void TestDisposeWatch()
public void DisposeWatch()
{
using (var server = new MockKubeApiServer(async httpContext =>
{
@@ -181,7 +181,7 @@ namespace k8s.Tests
}
[Fact]
public void TestWatchAllEvents()
public void WatchAllEvents()
{
using (var server = new MockKubeApiServer(async httpContext =>
{
@@ -237,7 +237,7 @@ namespace k8s.Tests
}
[Fact]
public void TestWatchServerDisconnect()
public void WatchServerDisconnect()
{
Watcher<Corev1Pod> watcher;
Exception exceptionCatched = null;
@@ -271,4 +271,4 @@ namespace k8s.Tests
Assert.IsType<IOException>(exceptionCatched);
}
}
}
}