SystemDeserializationTests.cs 1.9 KB

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