Skip to content

Commit

Permalink
Test: fix ZIP entry LastWriteTime tests to support running locally (w…
Browse files Browse the repository at this point in the history
…hen system clock is not UTC) (#5949)

Resolve NuGet/Home#11312
  • Loading branch information
dtivel committed Aug 6, 2024
1 parent c6b57e4 commit a06319d
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Commands.Test

public class NugetPackageUtilsTests
{
private readonly int DefaultTimeOut = (int)TimeSpan.FromMinutes(5).TotalMilliseconds;
private static readonly int DefaultTimeOut = (int)TimeSpan.FromMinutes(5).TotalMilliseconds;

[Fact]
public async Task PackageExpander_ExpandsPackage()
Expand Down Expand Up @@ -620,7 +620,9 @@ public async Task Test_ExtractionHonorsFileTimestamp()
{
// Arrange
var packageIdentity = new PackageIdentity("packageA", new NuGetVersion("2.0.3"));
var entryModifiedTime = new DateTimeOffset(1985, 11, 20, 12, 0, 0, TimeSpan.FromHours(-7.0)).DateTime;
var entryModifiedTime = new DateTimeOffset(1985, 11, 20, 12, 0, 0, TimeSpan.FromHours(-7.0));
DateTime expectedLastWriteTime = entryModifiedTime.DateTime.ToLocalTime();

using (var packagesDirectory = TestDirectory.Create())
{
var pathResolver = new VersionFolderPathResolver(packagesDirectory);
Expand All @@ -641,7 +643,7 @@ public async Task Test_ExtractionHonorsFileTimestamp()

// Act
using (var packageDownloader = new LocalPackageArchiveDownloader(
null,
source: null,
packageFileInfo.FullName,
packageIdentity,
NullLogger.Instance))
Expand All @@ -661,7 +663,7 @@ await PackageExtractor.InstallFromSourceAsync(
var dllPath = Path.Combine(packageVersionDirectory, "lib", "net45", "A.dll");
var dllFileInfo = new FileInfo(dllPath);
AssertFileExists(dllFileInfo.FullName);
Assert.Equal(entryModifiedTime, dllFileInfo.LastWriteTime);
Assert.Equal(expectedLastWriteTime, dllFileInfo.LastWriteTime);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
using System.IO;
using System.IO.Compression;
using System.Linq;
#if IS_SIGNING_SUPPORTED
using System.Text;
#endif
using System.Threading;
using System.Threading.Tasks;
using Moq;
Expand All @@ -15,7 +17,9 @@
using NuGet.Packaging.Signing;
using NuGet.Test.Utility;
using NuGet.Versioning;
#if IS_SIGNING_SUPPORTED
using Test.Utility.Signing;
#endif
using Xunit;

namespace NuGet.Packaging.Test
Expand Down Expand Up @@ -899,7 +903,7 @@ public async Task CopyFiles_ContainsInvalidEntry_Fail()
root,
identity.Id,
identity.Version.ToString(),
DateTimeOffset.UtcNow.LocalDateTime,
entryModifiedTime: DateTimeOffset.Now,
"../../A.dll",
"content/net40/B.nuspec");

Expand Down Expand Up @@ -931,7 +935,7 @@ public async Task CopyFiles_ContainsRootEntry_Fail()
root,
identity.Id,
identity.Version.ToString(),
DateTimeOffset.UtcNow.LocalDateTime,
entryModifiedTime: DateTimeOffset.Now,
$"{rootPath}/A.dll",
"content/net40/B.nuspec");

Expand Down Expand Up @@ -962,7 +966,7 @@ public async Task CopyFiles_ContainsCurrentEntry_Fail()
root,
identity.Id,
identity.Version.ToString(),
DateTimeOffset.UtcNow.LocalDateTime,
entryModifiedTime: DateTimeOffset.Now,
".",
"content/net40/B.nuspec");

Expand Down Expand Up @@ -1016,7 +1020,7 @@ public async Task CopyFilesAsync_PathWithDifferentCasingOnWindowsAndMac_Succeeds
root,
identity.Id,
identity.Version.ToString(),
DateTimeOffset.UtcNow.LocalDateTime,
entryModifiedTime: DateTimeOffset.Now,
@"readme~.txt");

using (var packageStream = File.OpenRead(packageFileInfo.FullName))
Expand Down Expand Up @@ -1055,7 +1059,7 @@ public async Task CopyFilesAsync_PathWithDifferentCasingOnLinux_Fails()
root,
identity.Id,
identity.Version.ToString(),
DateTimeOffset.UtcNow.LocalDateTime,
entryModifiedTime: DateTimeOffset.Now,
@"readme~.txt");

using (var packageStream = File.OpenRead(packageFileInfo.FullName))
Expand Down Expand Up @@ -1701,7 +1705,7 @@ public async Task ValidatePackageEntriesAsync_InvalidPackageFiles_Fails()
root,
identity.Id,
identity.Version.ToString(),
DateTimeOffset.UtcNow.LocalDateTime,
entryModifiedTime: DateTimeOffset.Now,
"../../A.dll",
"content/net40/B.nuspec");

Expand All @@ -1728,7 +1732,7 @@ public async Task ValidatePackageEntriesAsync_InvalidPackageFilesContainsRootPat
root,
identity.Id,
identity.Version.ToString(),
DateTimeOffset.UtcNow.LocalDateTime,
entryModifiedTime: DateTimeOffset.Now,
$"{rootPath}/A.dll",
"content/net40/B.nuspec");

Expand All @@ -1755,7 +1759,7 @@ public async Task ValidatePackageEntriesAsync_InvalidPackageFilesContainsCurrent
root,
identity.Id,
identity.Version.ToString(),
DateTimeOffset.UtcNow.LocalDateTime,
entryModifiedTime: DateTimeOffset.Now,
".",
"content/net40/B.nuspec");

Expand All @@ -1780,7 +1784,7 @@ public async Task ValidatePackageEntriesAsync_PackageFilesWithSpecialCharacters_
root,
identity.Id,
identity.Version.ToString(),
DateTimeOffset.UtcNow.LocalDateTime,
entryModifiedTime: DateTimeOffset.Now,
"C++.dll",
"content/net40/B&#A.txt",
"content/net40/B.nuspec");
Expand All @@ -1807,7 +1811,7 @@ public async Task ValidatePackageEntriesAsync_ValidPackageFiles_Succeeds()
root,
identity.Id,
identity.Version.ToString(),
DateTimeOffset.UtcNow.LocalDateTime,
entryModifiedTime: DateTimeOffset.Now,
"lib/net40/A.dll",
"content/net40/B.nuspec");

Expand Down
Loading

0 comments on commit a06319d

Please sign in to comment.