From 10c48a626271c2bfa8e565bef52e4f2591eb9b78 Mon Sep 17 00:00:00 2001
From: Muhammad Danish <88161975+mdanish-kh@users.noreply.github.com>
Date: Wed, 7 Aug 2024 18:58:41 +0500
Subject: [PATCH] Reset ReleaseDate in update flow
---
src/WingetCreateCLI/Commands/UpdateCommand.cs | 2 +
.../UnitTests/UpdateCommandTests.cs | 46 +++++++++++++++----
2 files changed, 39 insertions(+), 9 deletions(-)
diff --git a/src/WingetCreateCLI/Commands/UpdateCommand.cs b/src/WingetCreateCLI/Commands/UpdateCommand.cs
index d81bfbe7..7fb6cbc1 100644
--- a/src/WingetCreateCLI/Commands/UpdateCommand.cs
+++ b/src/WingetCreateCLI/Commands/UpdateCommand.cs
@@ -654,9 +654,11 @@ private static void ResetVersionSpecificFields(Manifests manifests)
defaultLocaleManifest.ReleaseNotesUrl = null;
installerManifest.ReleaseDateTime = null;
+ installerManifest.ReleaseDate = null;
foreach (var installer in installerManifest.Installers)
{
installer.ReleaseDateTime = null;
+ installer.ReleaseDate = null;
}
foreach (LocaleManifest localeManifest in localeManifests)
diff --git a/src/WingetCreateTests/WingetCreateTests/UnitTests/UpdateCommandTests.cs b/src/WingetCreateTests/WingetCreateTests/UnitTests/UpdateCommandTests.cs
index 216b8e60..9946de5f 100644
--- a/src/WingetCreateTests/WingetCreateTests/UnitTests/UpdateCommandTests.cs
+++ b/src/WingetCreateTests/WingetCreateTests/UnitTests/UpdateCommandTests.cs
@@ -929,7 +929,7 @@ public async Task UpdateFullYamlSingletonVersion1_5()
public async Task UpdateFullJsonSingletonVersion1_1()
{
TestUtils.InitializeMockDownloads(TestConstants.TestExeInstaller);
- (UpdateCommand command, var initialManifestContent) = GetUpdateCommandAndManifestData("TestPublisher.FullJsonSingleton1_1", null, this.tempPath, null, fileExtension: ".json");
+ (UpdateCommand command, var initialManifestContent) = GetUpdateCommandAndManifestData("TestPublisher.FullJsonSingleton1_1", null, this.tempPath, null, manifestFormat: ManifestFormat.Json);
var updatedManifests = await RunUpdateCommand(command, initialManifestContent);
ClassicAssert.IsNotNull(updatedManifests, "Command should have succeeded");
}
@@ -942,7 +942,7 @@ public async Task UpdateFullJsonSingletonVersion1_1()
public async Task UpdateFullJsonSingletonVersion1_2()
{
TestUtils.InitializeMockDownloads(TestConstants.TestExeInstaller);
- (UpdateCommand command, var initialManifestContent) = GetUpdateCommandAndManifestData("TestPublisher.FullJsonSingleton1_2", null, this.tempPath, null, fileExtension: ".json");
+ (UpdateCommand command, var initialManifestContent) = GetUpdateCommandAndManifestData("TestPublisher.FullJsonSingleton1_2", null, this.tempPath, null, manifestFormat: ManifestFormat.Json);
var updatedManifests = await RunUpdateCommand(command, initialManifestContent);
ClassicAssert.IsNotNull(updatedManifests, "Command should have succeeded");
}
@@ -955,7 +955,7 @@ public async Task UpdateFullJsonSingletonVersion1_2()
public async Task UpdateFullJsonSingletonVersion1_4()
{
TestUtils.InitializeMockDownloads(TestConstants.TestExeInstaller);
- (UpdateCommand command, var initialManifestContent) = GetUpdateCommandAndManifestData("TestPublisher.FullJsonSingleton1_4", null, this.tempPath, null, fileExtension: ".json");
+ (UpdateCommand command, var initialManifestContent) = GetUpdateCommandAndManifestData("TestPublisher.FullJsonSingleton1_4", null, this.tempPath, null, manifestFormat: ManifestFormat.Json);
var updatedManifests = await RunUpdateCommand(command, initialManifestContent);
ClassicAssert.IsNotNull(updatedManifests, "Command should have succeeded");
}
@@ -968,17 +968,17 @@ public async Task UpdateFullJsonSingletonVersion1_4()
public async Task UpdateFullJsonSingletonVersion1_5()
{
TestUtils.InitializeMockDownloads(TestConstants.TestExeInstaller);
- (UpdateCommand command, var initialManifestContent) = GetUpdateCommandAndManifestData("TestPublisher.FullJsonSingleton1_5", null, this.tempPath, null, fileExtension: ".json");
+ (UpdateCommand command, var initialManifestContent) = GetUpdateCommandAndManifestData("TestPublisher.FullJsonSingleton1_5", null, this.tempPath, null, manifestFormat: ManifestFormat.Json);
var updatedManifests = await RunUpdateCommand(command, initialManifestContent);
ClassicAssert.IsNotNull(updatedManifests, "Command should have succeeded");
}
///
- /// Ensures that version specific fields are reset after an update.
+ /// Ensures that version specific fields are reset after an update when using YAML manifests.
///
/// A representing the result of the asynchronous operation.
[Test]
- public async Task UpdateResetsVersionSpecificFields()
+ public async Task UpdateResetsVersionSpecificFields_Yaml()
{
TestUtils.InitializeMockDownloads(TestConstants.TestExeInstaller);
(UpdateCommand command, var initialManifestContent) = GetUpdateCommandAndManifestData("TestPublisher.FullYamlSingleton1_1", null, this.tempPath, null);
@@ -989,8 +989,34 @@ public async Task UpdateResetsVersionSpecificFields()
DefaultLocaleManifest updatedDefaultLocaleManifest = updatedManifests.DefaultLocaleManifest;
var updatedInstaller = updatedInstallerManifest.Installers.First();
- ClassicAssert.IsNull(updatedInstaller.ReleaseDateTime, "ReleaseDate should be null.");
- ClassicAssert.IsNull(updatedInstallerManifest.ReleaseDateTime, "ReleaseDate should be null.");
+ ClassicAssert.IsNull(updatedInstaller.ReleaseDateTime, "ReleaseDateTime at installer level should be null.");
+ ClassicAssert.IsNull(updatedInstaller.ReleaseDate, "ReleaseDate at installer level should be null.");
+ ClassicAssert.IsNull(updatedInstallerManifest.ReleaseDateTime, "ReleaseDateTime at root level should be null.");
+ ClassicAssert.IsNull(updatedInstallerManifest.ReleaseDate, "ReleaseDate at root level should be null.");
+ ClassicAssert.IsNull(updatedDefaultLocaleManifest.ReleaseNotes, "ReleaseNotes should be null.");
+ ClassicAssert.IsNull(updatedDefaultLocaleManifest.ReleaseNotesUrl, "ReleaseNotesUrl should be null.");
+ }
+
+ ///
+ /// Ensures that version specific fields are reset after an update when using JSON manifests.
+ ///
+ /// A representing the result of the asynchronous operation.
+ [Test]
+ public async Task UpdateResetsVersionSpecificFields_Json()
+ {
+ TestUtils.InitializeMockDownloads(TestConstants.TestExeInstaller);
+ (UpdateCommand command, var initialManifestContent) = GetUpdateCommandAndManifestData("TestPublisher.FullJsonSingleton1_1", null, this.tempPath, null, manifestFormat: ManifestFormat.Json);
+ var updatedManifests = await RunUpdateCommand(command, initialManifestContent);
+ ClassicAssert.IsNotNull(updatedManifests, "Command should have succeeded");
+
+ InstallerManifest updatedInstallerManifest = updatedManifests.InstallerManifest;
+ DefaultLocaleManifest updatedDefaultLocaleManifest = updatedManifests.DefaultLocaleManifest;
+ var updatedInstaller = updatedInstallerManifest.Installers.First();
+
+ ClassicAssert.IsNull(updatedInstaller.ReleaseDateTime, "ReleaseDateTime at installer level should be null.");
+ ClassicAssert.IsNull(updatedInstaller.ReleaseDate, "ReleaseDate at installer level should be null.");
+ ClassicAssert.IsNull(updatedInstallerManifest.ReleaseDateTime, "ReleaseDateTime at root level should be null.");
+ ClassicAssert.IsNull(updatedInstallerManifest.ReleaseDate, "ReleaseDate at root level should be null.");
ClassicAssert.IsNull(updatedDefaultLocaleManifest.ReleaseNotes, "ReleaseNotes should be null.");
ClassicAssert.IsNull(updatedDefaultLocaleManifest.ReleaseNotesUrl, "ReleaseNotesUrl should be null.");
}
@@ -1646,13 +1672,15 @@ public async Task UpdateZipInvalidRelativeFilePath()
Assert.That(result, Does.Contain(string.Format(Resources.NestedInstallerFileNotFound_Error, "fakeRelativeFilePath.exe")), "Failed to show warning for invalid relative file path.");
}
- private static (UpdateCommand UpdateCommand, List InitialManifestContent) GetUpdateCommandAndManifestData(string id, string version, string outputDir, IEnumerable installerUrls, bool isMultifile = false, string fileExtension = ".yaml")
+ private static (UpdateCommand UpdateCommand, List InitialManifestContent) GetUpdateCommandAndManifestData(string id, string version, string outputDir, IEnumerable installerUrls, bool isMultifile = false, ManifestFormat manifestFormat = ManifestFormat.Yaml)
{
+ string fileExtension = (manifestFormat == ManifestFormat.Yaml) ? ".yaml" : ".json";
var updateCommand = new UpdateCommand
{
Id = id,
Version = version,
OutputDir = outputDir,
+ Format = manifestFormat,
};
if (installerUrls != null)