-
Notifications
You must be signed in to change notification settings - Fork 33
/
KubeResultTests.cs
105 lines (94 loc) · 3.7 KB
/
KubeResultTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using Xunit;
using Xunit.Abstractions;
namespace KubeClient.Tests
{
using Models;
using TestCommon;
/// <summary>
/// Tests for <see cref="KubeResultV1"/> implementations.
/// </summary>
public class KubeResultTests
: TestBase
{
/// <summary>
/// Create a new <see cref="KubeResultTests"/> test suite.
/// </summary>
/// <param name="testOutput">
/// Output for the current test.
/// </param>
public KubeResultTests(ITestOutputHelper testOutput)
: base(testOutput)
{
}
/// <summary>
/// Verify that a PodV1 resource result, when constructed from a PodV1, can be implicitly cast to a PodV1.
/// </summary>
[Fact(DisplayName = "PodV1 resource result from PodV1 can be cast to PodV1")]
public void PodV1Result_From_PodV1_ImplicitCast_Resource()
{
PodV1 expected = new PodV1
{
Metadata = new ObjectMetaV1
{
Name = "my-pod",
Namespace = "my-namespace"
}
};
var result = new KubeResourceResultV1<PodV1>(expected);
PodV1 actual = result;
Assert.NotNull(actual);
Assert.Same(expected, actual);
}
/// <summary>
/// Verify that a PodV1 resource result, when constructed from a failing StatusV1 throws a KubeApiException when implicitly cast to a PodV1.
/// </summary>
[Fact(DisplayName = "PodV1 resource result from failing StatusV1 throws when cast to PodV1")]
public void PodV1Result_From_FailureStatus_ImplicitCast_Resource()
{
PodV1 pod = null;
KubeApiException exception = Assert.Throws<KubeApiException>(() =>
{
pod = new KubeResourceResultV1<PodV1>(new StatusV1
{
Status = "Failure",
Message = "Most definitely not a success."
});
});
Assert.Null(pod);
Assert.True(exception.HasStatus);
Assert.Equal("Failure", exception.Status.Status);
Assert.Equal("Most definitely not a success.", exception.Status.Message);
}
/// <summary>
/// Verify that a PodV1 resource result, when constructed from a successful StatusV1, can be implicitly cast to a StatusV1.
/// </summary>
[Fact(DisplayName = "PodV1 resource result from successful StatusV1 can be cast to PodV1")]
public void PodV1Result_From_SuccessStatus_ImplicitCast_Resource()
{
var result = new KubeResourceResultV1<PodV1>(new StatusV1
{
Status = "Success",
Message = "Most definitely a success."
});
PodV1 pod = result;
Assert.Null(pod);
}
/// <summary>
/// Verify that a PodV1 resource result, when constructed from a failing StatusV1, can be implicitly cast to a <see cref="StatusV1"/>.
/// </summary>
[Fact(DisplayName = "PodV1 resource result from failing StatusV1 can be cast to StatusV1")]
public void PodV1Result_From_FailureStatus_ImplicitCast_Status()
{
var result = new KubeResourceResultV1<PodV1>(new StatusV1
{
Status = "Failure",
Message = "Most definitely not a success."
});
StatusV1 status = result;
Assert.NotNull(status);
Assert.Equal("Failure", status.Status);
Assert.Equal("Most definitely not a success.", status.Message);
}
}
}