Allow contents for read only filesystem test to be in JSON, in-code or external with the test image.

This commit is contained in:
2021-05-31 19:15:07 +01:00
parent 3bce412c00
commit e09e61d0cf

View File

@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
using Aaru.Checksums;
using Aaru.CommonTypes;
using Aaru.CommonTypes.Interfaces;
@@ -99,7 +101,6 @@ namespace Aaru.Tests.Filesystems
if(!found)
continue;
var fs = Activator.CreateInstance(Plugin.GetType()) as IReadOnlyFilesystem;
Assert.NotNull(fs, $"Could not instantiate filesystem for {testFile}");
@@ -114,6 +115,30 @@ namespace Aaru.Tests.Filesystems
stat.Should().BeEquivalentTo(test.Info, $"Incorrect filesystem stats for {testFile}");
if(File.Exists($"{testFile}.contents.json"))
{
var sr = new StreamReader($"{testFile}.contents.json");
test.ContentsJson = sr.ReadToEnd();
}
if(test.ContentsJson != null)
{
test.Contents = JsonSerializer.Deserialize<Dictionary<string, FileData>>(test.ContentsJson,
new JsonSerializerOptions
{
IgnoreNullValues = true,
MaxDepth = 2048,
AllowTrailingCommas = true,
ReadCommentHandling = JsonCommentHandling.Skip,
Converters =
{
new JsonStringEnumConverter(JsonNamingPolicy.CamelCase)
}
});
test.ContentsJson = null;
}
if(test.Contents is null)
continue;