-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDefaultNamespaceManagerTests.cs
More file actions
56 lines (46 loc) · 1.86 KB
/
Copy pathDefaultNamespaceManagerTests.cs
File metadata and controls
56 lines (46 loc) · 1.86 KB
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
using k8s.Models;
using KubeOps.KubernetesClient;
using Microsoft.Extensions.Logging;
using Moq;
using Vecc.K8s.MultiCluster.Api.Services.Default;
namespace Vecc.K8s.MultiCluster.Api.Tests.Services.Default
{
public class DefaultNamespaceManagerTests
{
private readonly Mock<ILogger<DefaultNamespaceManager>> _loggerMock;
private readonly Mock<IKubernetesClient> _clientMock;
public DefaultNamespaceManagerTests()
{
_loggerMock = new Mock<ILogger<DefaultNamespaceManager>>();
_clientMock = new Mock<IKubernetesClient>();
}
[Fact]
public async Task GetNamsepacesAsync_ReturnsList()
{
// Arrange
var ns1 = new V1Namespace { Metadata = new V1ObjectMeta { Name = "default" } };
var ns2 = new V1Namespace { Metadata = new V1ObjectMeta { Name = "kube-system" } };
_clientMock.Setup(x => x.ListAsync<V1Namespace>(null))
.ReturnsAsync(new List<V1Namespace> { ns1, ns2 });
var manager = new DefaultNamespaceManager(_loggerMock.Object, _clientMock.Object);
// Act
var result = await manager.GetNamsepacesAsync();
// Assert
Assert.Equal(2, result.Count);
Assert.Equal("default", result[0].Metadata.Name);
Assert.Equal("kube-system", result[1].Metadata.Name);
}
[Fact]
public async Task GetNamsepacesAsync_EmptyList_ReturnsEmpty()
{
// Arrange
_clientMock.Setup(x => x.ListAsync<V1Namespace>(null))
.ReturnsAsync(new List<V1Namespace>());
var manager = new DefaultNamespaceManager(_loggerMock.Object, _clientMock.Object);
// Act
var result = await manager.GetNamsepacesAsync();
// Assert
Assert.Empty(result);
}
}
}