Fix tests that broke after the changes for the removal of IonicZip.

Signed-off-by: Konstantina Chremmou <Konstantina.Chremmou@cloud.com>
This commit is contained in:
Konstantina Chremmou 2023-01-04 20:54:11 +00:00
parent 2e07ff5b98
commit 68e14b1083
7 changed files with 61 additions and 10 deletions

View File

@ -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);

View File

@ -133,6 +133,9 @@
<Compile Include="XenOvf\FileDigestTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="TestResources\emptyfile.gz">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="TestResources\PluginResources\PowerShellTest.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

View File

@ -44,6 +44,13 @@ namespace XenCenterLib.Archive
private TarEntry tarEntry;
private bool disposed;
/// <summary>
/// Parameterless constructor needed by tests
/// </summary>
public TarArchiveIterator()
{
}
public TarArchiveIterator(Stream compressedTarFile, CompressionFactory.Type compressionType)
{
if (compressionType == CompressionFactory.Type.Gz)

View File

@ -45,6 +45,9 @@ namespace XenCenterLib.Archive
private const long bufferSize = 32 * 1024;
private bool disposed;
/// <summary>
/// Parameterless constructor needed by tests
/// </summary>
public TarArchiveWriter()
{
}

View File

@ -50,6 +50,13 @@ namespace XenCenterLib.Archive
/// </summary>
public event Action<int, int> CurrentFileExtracted;
/// <summary>
/// Parameterless constructor needed by tests
/// </summary>
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)

View File

@ -41,6 +41,13 @@ namespace XenCenterLib.Archive
private ZipArchive _zipArchive;
private bool _disposed;
/// <summary>
/// Parameterless constructor needed by tests
/// </summary>
public ZipArchiveWriter()
{
}
public ZipArchiveWriter(Stream outputStream)
{
_zipArchive = new ZipArchive(outputStream, ZipArchiveMode.Create);

View File

@ -39,6 +39,13 @@ namespace XenCenterLib.Compression
/// </summary>
class GZipOutputStream : CompressionStream
{
/// <summary>
/// Parameterless constructor needed by tests
/// </summary>
public GZipOutputStream()
{
}
public GZipOutputStream(Stream outputStream)
{
zipStream = new GZipStream(outputStream, CompressionMode.Compress);
@ -55,6 +62,13 @@ namespace XenCenterLib.Compression
/// </summary>
class GZipInputStream : CompressionStream
{
/// <summary>
/// Parameterless constructor needed by tests
/// </summary>
public GZipInputStream()
{
}
public GZipInputStream(Stream inputStream)
{
zipStream = new GZipStream(inputStream, CompressionMode.Decompress);