2018-04-28 05:51:02 +02:00
using k8s.Models ;
using System ;
using System.IO ;
using System.Text ;
using System.Threading ;
2019-10-22 16:02:13 -07:00
using System.Threading.Tasks ;
2018-04-28 05:51:02 +02:00
using Xunit ;
2018-07-09 23:52:17 +10:00
namespace k8s.Tests
2018-04-28 05:51:02 +02:00
{
public class WatcherTests
{
[Fact]
public void ReadError ( )
{
byte [ ] 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 ( MemoryStream stream = new MemoryStream ( data ) )
using ( StreamReader reader = new StreamReader ( stream ) )
{
Exception recordedException = null ;
ManualResetEvent mre = new ManualResetEvent ( false ) ;
Watcher < V1Pod > watcher = new Watcher < V1Pod > (
2019-10-22 16:02:13 -07:00
( ) = > Task . FromResult ( reader ) ,
2018-04-28 05:51:02 +02:00
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 ) ;
}
}
}
}