From f7c0aa34d3067615717c1d2eeee22859461d4e24 Mon Sep 17 00:00:00 2001 From: Boshi Lian Date: Fri, 24 Nov 2017 12:19:44 +0800 Subject: [PATCH] fix tests and examples to use v1.8 model --- examples/namespace/Namespace.cs | 4 ++-- examples/simple/PodList.cs | 25 ++++++++++---------- examples/watch/Program.cs | 2 +- src/{IntOrString.cs => IntstrIntOrString.cs} | 18 +++++++------- tests/AuthTests.cs | 2 +- tests/IntOrStringTests.cs | 8 +++---- tests/V1StatusObjectViewTests.cs | 6 ++--- tests/WatchTests.cs | 18 +++++++------- 8 files changed, 42 insertions(+), 41 deletions(-) rename src/{IntOrString.cs => IntstrIntOrString.cs} (61%) diff --git a/examples/namespace/Namespace.cs b/examples/namespace/Namespace.cs index 1859ad5..92b85c7 100644 --- a/examples/namespace/Namespace.cs +++ b/examples/namespace/Namespace.cs @@ -54,7 +54,7 @@ namespace @namespace ListNamespaces(client); - var ns = new Corev1Namespace + var ns = new V1Namespace { Metadata = new V1ObjectMeta { @@ -71,7 +71,7 @@ namespace @namespace if (status.HasObject) { - var obj = status.ObjectView(); + var obj = status.ObjectView(); Console.WriteLine(obj.Status.Phase); Delete(client, ns.Metadata.Name, 3 * 1000); diff --git a/examples/simple/PodList.cs b/examples/simple/PodList.cs index 593c947..dd783c7 100755 --- a/examples/simple/PodList.cs +++ b/examples/simple/PodList.cs @@ -1,22 +1,23 @@ +using System; +using k8s; + namespace simple { - using System; - using System.IO; - using k8s; - - class PodList + internal class PodList { - static void Main(string[] args) + private static void Main(string[] args) { - var k8sClientConfig = KubernetesClientConfiguration.BuildConfigFromConfigFile(); - IKubernetes client = new Kubernetes(k8sClientConfig); + var config = KubernetesClientConfiguration.BuildConfigFromConfigFile(); + IKubernetes client = new Kubernetes(config); Console.WriteLine("Starting Request!"); - var listTask = client.ListNamespacedPodWithHttpMessagesAsync("default").Result; - var list = listTask.Body; - foreach (var item in list.Items) { + + var list = client.ListNamespacedPod("default"); + foreach (var item in list.Items) + { Console.WriteLine(item.Metadata.Name); } - if (list.Items.Count == 0) { + if (list.Items.Count == 0) + { Console.WriteLine("Empty!"); } } diff --git a/examples/watch/Program.cs b/examples/watch/Program.cs index 1868472..88514f7 100644 --- a/examples/watch/Program.cs +++ b/examples/watch/Program.cs @@ -14,7 +14,7 @@ namespace watch IKubernetes client = new Kubernetes(config); var podlistResp = client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).Result; - using (podlistResp.Watch((type, item) => + using (podlistResp.Watch((type, item) => { Console.WriteLine("==on watch event=="); Console.WriteLine(type); diff --git a/src/IntOrString.cs b/src/IntstrIntOrString.cs similarity index 61% rename from src/IntOrString.cs rename to src/IntstrIntOrString.cs index ae7ddbe..42be179 100644 --- a/src/IntOrString.cs +++ b/src/IntstrIntOrString.cs @@ -7,7 +7,7 @@ namespace k8s.Models { public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { - var s = (value as IntOrString)?.Value; + var s = (value as IntstrIntOrString)?.Value; if (int.TryParse(s, out var intv)) { @@ -21,7 +21,7 @@ namespace k8s.Models public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { - return (IntOrString) serializer.Deserialize(reader); + return (IntstrIntOrString) serializer.Deserialize(reader); } public override bool CanConvert(Type objectType) @@ -31,26 +31,26 @@ namespace k8s.Models } [JsonConverter(typeof(IntOrStringConverter))] - public partial class IntOrString + public partial class IntstrIntOrString { - public static implicit operator int(IntOrString v) + public static implicit operator int(IntstrIntOrString v) { return int.Parse(v.Value); } - public static implicit operator IntOrString(int v) + public static implicit operator IntstrIntOrString(int v) { - return new IntOrString(Convert.ToString(v)); + return new IntstrIntOrString(Convert.ToString(v)); } - public static implicit operator string(IntOrString v) + public static implicit operator string(IntstrIntOrString v) { return v.Value; } - public static implicit operator IntOrString(string v) + public static implicit operator IntstrIntOrString(string v) { - return new IntOrString(v); + return new IntstrIntOrString(v); } } } diff --git a/tests/AuthTests.cs b/tests/AuthTests.cs index a1e96b3..dccd672 100644 --- a/tests/AuthTests.cs +++ b/tests/AuthTests.cs @@ -17,7 +17,7 @@ namespace k8s.Tests { public class AuthTests { - private static HttpOperationResponse ExecuteListPods(IKubernetes client) + private static HttpOperationResponse ExecuteListPods(IKubernetes client) { return client.ListNamespacedPodWithHttpMessagesAsync("default").Result; } diff --git a/tests/IntOrStringTests.cs b/tests/IntOrStringTests.cs index 1a35ed1..ba5cbd5 100644 --- a/tests/IntOrStringTests.cs +++ b/tests/IntOrStringTests.cs @@ -11,13 +11,13 @@ namespace k8s.Tests { { var v = 123; - IntOrString intorstr = v; + IntstrIntOrString intorstr = v; Assert.Equal("123", JsonConvert.SerializeObject(intorstr)); } { - IntOrString intorstr = "12%"; + IntstrIntOrString intorstr = "12%"; Assert.Equal("\"12%\"", JsonConvert.SerializeObject(intorstr)); } } @@ -26,12 +26,12 @@ namespace k8s.Tests public void Deserialize() { { - var v = JsonConvert.DeserializeObject("1234"); + var v = JsonConvert.DeserializeObject("1234"); Assert.Equal("1234", v.Value); } { - var v = JsonConvert.DeserializeObject("\"12%\""); + var v = JsonConvert.DeserializeObject("\"12%\""); Assert.Equal("12%", v.Value); } } diff --git a/tests/V1StatusObjectViewTests.cs b/tests/V1StatusObjectViewTests.cs index 4b115b3..8a90fb7 100644 --- a/tests/V1StatusObjectViewTests.cs +++ b/tests/V1StatusObjectViewTests.cs @@ -34,13 +34,13 @@ namespace k8s.Tests [Fact] public void ReturnObject() { - var corev1Namespace = new Corev1Namespace() + var corev1Namespace = new V1Namespace() { Metadata = new V1ObjectMeta() { Name = "test name" }, - Status = new Corev1NamespaceStatus() + Status = new V1NamespaceStatus() { Phase = "test termating" } @@ -57,7 +57,7 @@ namespace k8s.Tests Assert.True(status.HasObject); - var obj = status.ObjectView(); + var obj = status.ObjectView(); Assert.Equal(obj.Metadata.Name, corev1Namespace.Metadata.Name); Assert.Equal(obj.Status.Phase, corev1Namespace.Status.Phase); diff --git a/tests/WatchTests.cs b/tests/WatchTests.cs index 976a2a4..094dd93 100644 --- a/tests/WatchTests.cs +++ b/tests/WatchTests.cs @@ -26,8 +26,8 @@ namespace k8s.Tests private static string BuildWatchEventStreamLine(WatchEventType eventType) { - var corev1PodList = JsonConvert.DeserializeObject(MockKubeApiServer.MockPodResponse); - return JsonConvert.SerializeObject(new Watcher.WatchEvent + var corev1PodList = JsonConvert.DeserializeObject(MockKubeApiServer.MockPodResponse); + return JsonConvert.SerializeObject(new Watcher.WatchEvent { Type = eventType, Object = corev1PodList.Items.First() @@ -57,7 +57,7 @@ namespace k8s.Tests var listTask = client.ListNamespacedPodWithHttpMessagesAsync("default").Result; Assert.ThrowsAny(() => { - listTask.Watch((type, item) => { }); + listTask.Watch((type, item) => { }); }); } @@ -113,7 +113,7 @@ namespace k8s.Tests var events = new HashSet(); var errors = 0; - var watcher = listTask.Watch( + var watcher = listTask.Watch( (type, item) => { events.Add(type); }, e => { errors += 1; } ); @@ -159,7 +159,7 @@ namespace k8s.Tests var events = new HashSet(); - var watcher = listTask.Watch( + var watcher = listTask.Watch( (type, item) => { events.Add(type); } ); @@ -217,7 +217,7 @@ namespace k8s.Tests var events = new HashSet(); var errors = 0; - var watcher = listTask.Watch( + var watcher = listTask.Watch( (type, item) => { events.Add(type); }, e => { errors += 1; } ); @@ -240,7 +240,7 @@ namespace k8s.Tests [Fact] public void WatchServerDisconnect() { - Watcher watcher; + Watcher watcher; Exception exceptionCatched = null; using (var server = new MockKubeApiServer(async httpContext => @@ -260,7 +260,7 @@ namespace k8s.Tests var listTask = client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true).Result; - watcher = listTask.Watch( + watcher = listTask.Watch( (type, item) => { }, e => { exceptionCatched = e; }); } @@ -315,7 +315,7 @@ namespace k8s.Tests var events = new HashSet(); - var watcher = listTask.Watch( + var watcher = listTask.Watch( (type, item) => { events.Add(type); } );