Files
csharp/tests/KubernetesClient.Tests/WatcherTests.cs
Boshi Lian 5be3cff425 Style fix final (#523)
* all net5

* var

* SA1310

* SA1310

* allow 1031

* SA1805

* fix SA1642

* remove unused code

* allow sa1405

* isempty

* fix CA1714

* fix CA1806

* remove always false if

* fix format

* fix CA1062

* allow SA0001

* fix CA1062

* allow ca1034 and temp allow ca1835

* fix 16XX doc related warnings

* elm SA16XX

* elm SA16XX

* fix CA2213

* revert to pass all test

* move unclear rule to ruleset

* follow up of moving ruleset

* remove this

* fix test flaky
2020-11-22 14:52:09 -08:00

48 lines
1.5 KiB
C#

using k8s.Models;
using System;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
namespace k8s.Tests
{
public class WatcherTests
{
[Fact]
public void ReadError()
{
var data = Encoding.UTF8.GetBytes(
"{\"type\":\"ERROR\",\"object\":{\"kind\":\"Status\",\"apiVersion\":\"v1\",\"metadata\":{},\"status\":\"Failure\",\"message\":\"too old resource version: 44982(53593)\",\"reason\":\"Gone\",\"code\":410}}");
using (var stream = new MemoryStream(data))
using (var reader = new StreamReader(stream))
{
Exception recordedException = null;
var mre = new ManualResetEvent(false);
var watcher = new Watcher<V1Pod>(
() => Task.FromResult(reader),
null,
(exception) =>
{
recordedException = exception;
mre.Set();
});
mre.WaitOne();
Assert.NotNull(recordedException);
var k8sException = recordedException as KubernetesException;
Assert.NotNull(k8sException);
Assert.NotNull(k8sException.Status);
Assert.Equal("too old resource version: 44982(53593)", k8sException.Message);
Assert.Equal("too old resource version: 44982(53593)", k8sException.Status.Message);
}
}
}
}