From 68e14b108305f3f74770718f37fc0a6d4fab8234 Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Wed, 4 Jan 2023 20:54:11 +0000 Subject: [PATCH] Fix tests that broke after the changes for the removal of IonicZip. Signed-off-by: Konstantina Chremmou --- .../ThirdPartyArchiveWriterTests.cs | 19 +++++++++++-------- XenAdminTests/XenAdminTests.csproj | 3 +++ XenCenterLib/Archive/TarArchiveIterator.cs | 7 +++++++ XenCenterLib/Archive/TarArchiveWriter.cs | 3 +++ XenCenterLib/Archive/ZipArchiveIterator.cs | 18 ++++++++++++++++-- XenCenterLib/Archive/ZipArchiveWriter.cs | 7 +++++++ XenCenterLib/Compression/GZipStreams.cs | 14 ++++++++++++++ 7 files changed, 61 insertions(+), 10 deletions(-) diff --git a/XenAdminTests/ArchiveTests/ThirdPartyArchiveWriterTests.cs b/XenAdminTests/ArchiveTests/ThirdPartyArchiveWriterTests.cs index 3af6721c4..66895f3c3 100644 --- a/XenAdminTests/ArchiveTests/ThirdPartyArchiveWriterTests.cs +++ b/XenAdminTests/ArchiveTests/ThirdPartyArchiveWriterTests.cs @@ -45,12 +45,12 @@ namespace XenAdminTests.ArchiveTests where TR : ArchiveIterator, new() where TW : ArchiveWriter, new() { - private string tempPath; + private string _tempPath; [SetUp] public void TestSetUp() { - tempPath = CreateTempFolder(); + _tempPath = CreateTempFolder(); } [TearDown] @@ -58,7 +58,7 @@ namespace XenAdminTests.ArchiveTests { try { - Directory.Delete(tempPath, true); + Directory.Delete(_tempPath, true); } catch { @@ -69,7 +69,7 @@ namespace XenAdminTests.ArchiveTests [Test] public void CreateAnArchiveAndRereadWhenPossible() { - string tarFileName = Path.Combine(tempPath, Path.GetRandomFileName()); + string tarFileName = Path.Combine(_tempPath, Path.GetRandomFileName()); CheckWriteArchive(tarFileName); CheckReadArchive(tarFileName); } @@ -86,12 +86,15 @@ namespace XenAdminTests.ArchiveTests reader.SetBaseStream(fs); while (reader.HasNext()) { - if (reader.IsDirectory() && expectedDirs.Contains(reader.CurrentFileName())) - expectedDirs.Remove(reader.CurrentFileName()); + var isDirectory = reader.IsDirectory(); + var name = reader.CurrentFileName(); - if (!reader.IsDirectory() && expectedFiles.Contains(reader.CurrentFileName())) + if (isDirectory && expectedDirs.Contains(name)) + expectedDirs.Remove(name); + + if (!isDirectory && expectedFiles.Contains(name)) { - expectedFiles.Remove(reader.CurrentFileName()); + expectedFiles.Remove(name); using (MemoryStream ms = new MemoryStream()) { reader.ExtractCurrentFile(ms, null); diff --git a/XenAdminTests/XenAdminTests.csproj b/XenAdminTests/XenAdminTests.csproj index c59539658..613d09d41 100644 --- a/XenAdminTests/XenAdminTests.csproj +++ b/XenAdminTests/XenAdminTests.csproj @@ -133,6 +133,9 @@ + + Always + PreserveNewest diff --git a/XenCenterLib/Archive/TarArchiveIterator.cs b/XenCenterLib/Archive/TarArchiveIterator.cs index 10c4bd9a5..babc2e7d3 100644 --- a/XenCenterLib/Archive/TarArchiveIterator.cs +++ b/XenCenterLib/Archive/TarArchiveIterator.cs @@ -44,6 +44,13 @@ namespace XenCenterLib.Archive private TarEntry tarEntry; private bool disposed; + /// + /// Parameterless constructor needed by tests + /// + public TarArchiveIterator() + { + } + public TarArchiveIterator(Stream compressedTarFile, CompressionFactory.Type compressionType) { if (compressionType == CompressionFactory.Type.Gz) diff --git a/XenCenterLib/Archive/TarArchiveWriter.cs b/XenCenterLib/Archive/TarArchiveWriter.cs index de462e663..faec71e19 100644 --- a/XenCenterLib/Archive/TarArchiveWriter.cs +++ b/XenCenterLib/Archive/TarArchiveWriter.cs @@ -45,6 +45,9 @@ namespace XenCenterLib.Archive private const long bufferSize = 32 * 1024; private bool disposed; + /// + /// Parameterless constructor needed by tests + /// public TarArchiveWriter() { } diff --git a/XenCenterLib/Archive/ZipArchiveIterator.cs b/XenCenterLib/Archive/ZipArchiveIterator.cs index 154c7042c..61acfae79 100644 --- a/XenCenterLib/Archive/ZipArchiveIterator.cs +++ b/XenCenterLib/Archive/ZipArchiveIterator.cs @@ -50,6 +50,13 @@ namespace XenCenterLib.Archive /// public event Action CurrentFileExtracted; + /// + /// Parameterless constructor needed by tests + /// + public ZipArchiveIterator() + { + } + public ZipArchiveIterator(Stream inputStream) { _zipArchive = new ZipArchive(inputStream, ZipArchiveMode.Read); @@ -97,8 +104,15 @@ namespace XenCenterLib.Archive public override bool IsDirectory() { - var attr = (FileAttributes)(_currentEntry.ExternalAttributes & 0xff); - return attr.HasFlag(FileAttributes.Directory); + if (_currentEntry.ExternalAttributes != 0) + { + var attr = (FileAttributes)(_currentEntry.ExternalAttributes & 0xff); + return attr.HasFlag(FileAttributes.Directory); + } + + var name = CurrentFileName(); + return !string.IsNullOrEmpty(name) && + (name[name.Length - 1] == '/' || name[name.Length - 1] == '\\'); } public override void ExtractCurrentFile(Stream extractedFileContents, Action cancellingDelegate) diff --git a/XenCenterLib/Archive/ZipArchiveWriter.cs b/XenCenterLib/Archive/ZipArchiveWriter.cs index c6f262925..bb563e708 100644 --- a/XenCenterLib/Archive/ZipArchiveWriter.cs +++ b/XenCenterLib/Archive/ZipArchiveWriter.cs @@ -41,6 +41,13 @@ namespace XenCenterLib.Archive private ZipArchive _zipArchive; private bool _disposed; + /// + /// Parameterless constructor needed by tests + /// + public ZipArchiveWriter() + { + } + public ZipArchiveWriter(Stream outputStream) { _zipArchive = new ZipArchive(outputStream, ZipArchiveMode.Create); diff --git a/XenCenterLib/Compression/GZipStreams.cs b/XenCenterLib/Compression/GZipStreams.cs index 96bd0546a..c00e72dce 100644 --- a/XenCenterLib/Compression/GZipStreams.cs +++ b/XenCenterLib/Compression/GZipStreams.cs @@ -39,6 +39,13 @@ namespace XenCenterLib.Compression /// class GZipOutputStream : CompressionStream { + /// + /// Parameterless constructor needed by tests + /// + public GZipOutputStream() + { + } + public GZipOutputStream(Stream outputStream) { zipStream = new GZipStream(outputStream, CompressionMode.Compress); @@ -55,6 +62,13 @@ namespace XenCenterLib.Compression /// class GZipInputStream : CompressionStream { + /// + /// Parameterless constructor needed by tests + /// + public GZipInputStream() + { + } + public GZipInputStream(Stream inputStream) { zipStream = new GZipStream(inputStream, CompressionMode.Decompress);