Skip to content

Commit 392ebcf

Browse files
authored
Override ToString on V1Status (#424)
1 parent f2e1c4b commit 392ebcf

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Net;
2+
3+
namespace k8s.Models
4+
{
5+
public partial class V1Status
6+
{
7+
/// <summary>Converts a <see cref="V1Status"/> object into a short description of the status.</summary>
8+
public override string ToString()
9+
{
10+
string reason = Reason;
11+
if (string.IsNullOrEmpty(reason) && Code.GetValueOrDefault() != 0)
12+
{
13+
reason = ((HttpStatusCode)Code.Value).ToString();
14+
}
15+
return string.IsNullOrEmpty(Message) ? string.IsNullOrEmpty(reason) ? Status : reason :
16+
string.IsNullOrEmpty(reason) ? Message : $"{reason} - {Message}";
17+
}
18+
}
19+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using k8s.Models;
2+
using Xunit;
3+
4+
namespace k8s.Tests
5+
{
6+
public class ModelExtensionTests
7+
{
8+
[Fact]
9+
public void TestV1Status()
10+
{
11+
var s = new V1Status() { Status = "Success" };
12+
Assert.Equal("Success", s.ToString());
13+
14+
s = new V1Status() { Status = "Failure" };
15+
Assert.Equal("Failure", s.ToString());
16+
17+
s = new V1Status() { Status = "Failure", Reason = "BombExploded" };
18+
Assert.Equal("BombExploded", s.ToString());
19+
20+
s = new V1Status() { Status = "Failure", Message = "Something bad happened." };
21+
Assert.Equal("Something bad happened.", s.ToString());
22+
23+
s = new V1Status() { Status = "Failure", Code = 400 };
24+
Assert.Equal("BadRequest", s.ToString());
25+
26+
s = new V1Status() { Status = "Failure", Code = 911 };
27+
Assert.Equal("911", s.ToString());
28+
29+
s = new V1Status() { Status = "Failure", Code = 400, Message = "It's all messed up." };
30+
Assert.Equal("BadRequest - It's all messed up.", s.ToString());
31+
32+
s = new V1Status() { Status = "Failure", Code = 400, Reason = "IllegalValue", Message = "You're breaking the LAW!", };
33+
Assert.Equal("IllegalValue - You're breaking the LAW!", s.ToString());
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)