Updated test to not rely on ReadByte()
This commit is contained in:
@@ -120,7 +120,7 @@ namespace Duplicati.UnitTest
|
||||
// Read second file
|
||||
using (var fd = z0.OpenRead(files[1]))
|
||||
{
|
||||
bool match = testset2.All(b => b == fd.ReadByte()) && fd.ReadByte() == -1;
|
||||
var match = CompareStreamToContent(fd, testset2);
|
||||
if (!match)
|
||||
throw new Exception("Decompressed file sample2 contents do not match the source file.");
|
||||
}
|
||||
@@ -128,7 +128,7 @@ namespace Duplicati.UnitTest
|
||||
// Read first file
|
||||
using (var fd = z0.OpenRead(files[0]))
|
||||
{
|
||||
bool match = testset1.All(b => b == fd.ReadByte()) && fd.ReadByte() == -1;
|
||||
var match = CompareStreamToContent(fd, testset1);
|
||||
if (!match)
|
||||
throw new Exception("Decompressed file sample1 contents do not match the source file.");
|
||||
}
|
||||
@@ -136,6 +136,20 @@ namespace Duplicati.UnitTest
|
||||
}
|
||||
}
|
||||
|
||||
private static bool CompareStreamToContent(Stream stream, IEnumerable<byte> content)
|
||||
{
|
||||
// Previous slower version relies on ReadByte() which is not representative of common use
|
||||
//return content.All(b => b == stream.ReadByte()) && stream.ReadByte() == -1;
|
||||
|
||||
using var ms = new MemoryStream();
|
||||
stream.CopyTo(ms);
|
||||
var result = ms.ToArray();
|
||||
var expected = content.ToArray();
|
||||
|
||||
return result.SequenceEqual(expected);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Despite archives being able to store multiple files with the same name, this should not leak into the application
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user