[UnitTests] Add code to generate extended attributes list and MD5s when building contents JSON for ReadOnlyFilesystemTest.

This commit is contained in:
2022-12-08 14:16:35 +00:00
parent a450f0ca32
commit f9ace7b7d9

View File

@@ -296,6 +296,10 @@ public abstract class ReadOnlyFilesystemTest : FilesystemTest
else
data.Md5 = BuildFile(fs, childPath, stat.Length);
if(fs.ListXAttr(childPath, out List<string> xattrs) == ErrorNumber.NoError &&
xattrs.Count > 0)
data.XattrsWithMd5 = BuildFileXattrs(fs, childPath);
children[child] = data;
}
@@ -310,6 +314,30 @@ public abstract class ReadOnlyFilesystemTest : FilesystemTest
return Md5Context.Data(buffer, out _);
}
static Dictionary<string, string> BuildFileXattrs(IReadOnlyFilesystem fs, string path)
{
fs.ListXAttr(path, out List<string> contents);
if(contents.Count == 0)
return null;
Dictionary<string, string> xattrs = new();
foreach(string xattr in contents)
{
byte[] buffer = Array.Empty<byte>();
ErrorNumber ret = fs.GetXattr(path, xattr, ref buffer);
string data;
data = ret != ErrorNumber.NoError ? Md5Context.Data(Array.Empty<byte>(), out _)
: Md5Context.Data(buffer, out _);
xattrs[xattr] = data;
}
return xattrs;
}
internal static void TestDirectory(IReadOnlyFilesystem fs, string path, Dictionary<string, FileData> children,
string testFile, bool testXattr, out List<NextLevel> nextLevels,
int currentDepth)