Skip to content

Commit

Permalink
Reset ReleaseDate in update flow (microsoft#545)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdanish-kh authored Sep 5, 2024
1 parent d758023 commit 817aa36
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/WingetCreateCLI/Commands/UpdateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -656,9 +656,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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");
}
Expand All @@ -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");
}
Expand All @@ -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");
}

/// <summary>
/// Ensures that version specific fields are reset after an update.
/// Ensures that version specific fields are reset after an update when using YAML manifests.
/// </summary>
/// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
[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);
Expand All @@ -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.");
}

/// <summary>
/// Ensures that version specific fields are reset after an update when using JSON manifests.
/// </summary>
/// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
[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.");
}
Expand Down Expand Up @@ -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<string> InitialManifestContent) GetUpdateCommandAndManifestData(string id, string version, string outputDir, IEnumerable<string> installerUrls, bool isMultifile = false, string fileExtension = ".yaml")
private static (UpdateCommand UpdateCommand, List<string> InitialManifestContent) GetUpdateCommandAndManifestData(string id, string version, string outputDir, IEnumerable<string> 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)
Expand Down

0 comments on commit 817aa36

Please sign in to comment.