SystemDeserializationTests.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 = new YamlResourceCollection(filePath, new PhysicalTextFileStore(), new ResourceCollection());
  17. await yamlResourceCollection.LoadAsync();
  18. return yamlResourceCollection;
  19. }
  20. [Fact]
  21. public async Task deserialize_yaml_kind_System()
  22. {
  23. // type: Hypervisor | Baremetal | VM | Container
  24. // Given
  25. var yaml = @"
  26. resources:
  27. - kind: System
  28. type: Hypervisor
  29. name: home-virtualization-host
  30. os: proxmox
  31. cores: 2
  32. ram: 12gb
  33. drives:
  34. - size: 2Tb
  35. - size: 1tb
  36. runsOn: dell-c6400-node-01
  37. ";
  38. var sut = await CreateSut(yaml);
  39. // When
  40. var resources = await sut.GetAllOfTypeAsync<SystemResource>();
  41. // Then
  42. var resource = Assert.Single(resources);
  43. Assert.IsType<SystemResource>(resource);
  44. var system = resource;
  45. Assert.NotNull(system);
  46. Assert.Equal("Hypervisor", system.Type);
  47. Assert.Equal("home-virtualization-host", system.Name);
  48. Assert.Equal("proxmox", system.Os);
  49. Assert.Equal(2, system.Cores);
  50. Assert.Equal(12, system.Ram);
  51. // Drives
  52. Assert.NotNull(system.Drives);
  53. Assert.Equal(2048, system.Drives[0].Size);
  54. Assert.Equal(1024, system.Drives[1].Size);
  55. Assert.Equal("dell-c6400-node-01", system.RunsOn);
  56. }
  57. }