SystemDeserializationTests.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using RackPeek.Domain.Resources.SystemResources;
  2. using RackPeek.Yaml;
  3. namespace Tests.Yaml;
  4. public class SystemDeserializationTests
  5. {
  6. public static ISystemRepository CreateSut(string yaml)
  7. {
  8. var tempDir = Path.Combine(
  9. Path.GetTempPath(),
  10. "RackPeekTests",
  11. Guid.NewGuid().ToString("N"));
  12. Directory.CreateDirectory(tempDir);
  13. var filePath = Path.Combine(tempDir, "config.yaml");
  14. File.WriteAllText(filePath, yaml);
  15. var yamlResourceCollection = new YamlResourceCollection(filePath);
  16. return new YamlSystemRepository(yamlResourceCollection);
  17. }
  18. [Fact]
  19. public async Task deserialize_yaml_kind_System()
  20. {
  21. // type: Hypervisor | Baremetal | VM | Container
  22. // Given
  23. var yaml = @"
  24. resources:
  25. - kind: System
  26. type: Hypervisor
  27. name: home-virtualization-host
  28. os: proxmox
  29. cores: 2
  30. ram: 12gb
  31. drives:
  32. - size: 2Tb
  33. - size: 1tb
  34. runsOn: dell-c6400-node-01
  35. ";
  36. var sut = CreateSut(yaml);
  37. // When
  38. var resources = await sut.GetAllAsync();
  39. // Then
  40. var resource = Assert.Single(resources);
  41. Assert.IsType<SystemResource>(resource);
  42. var system = resource;
  43. Assert.NotNull(system);
  44. Assert.Equal("Hypervisor", system.Type);
  45. Assert.Equal("home-virtualization-host", system.Name);
  46. Assert.Equal("proxmox", system.Os);
  47. Assert.Equal(2, system.Cores);
  48. Assert.Equal(12, system.Ram);
  49. // Drives
  50. Assert.NotNull(system.Drives);
  51. Assert.Equal(2048, system.Drives[0].Size);
  52. Assert.Equal(1024, system.Drives[1].Size);
  53. Assert.Equal("dell-c6400-node-01", system.RunsOn);
  54. }
  55. }