Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/GeneralUpdate.Core/Download/Models/DownloadAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ public record DownloadAsset(
int? AppType = null,
string? AuthScheme = null,
string? AuthToken = null
);
)
{
public string? UpdateLog { get; init; }
}

/// <summary>Ordered download plan built from server response.</summary>
public record DownloadPlan(IReadOnlyList<DownloadAsset> Assets, bool IsForcibly)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ private static DownloadAsset MapVersionEntry(VersionEntry v)
AppType: v.AppType,
AuthScheme: v.AuthScheme,
AuthToken: v.AuthToken
);
)
{
UpdateLog = v.UpdateLog
};
}
}
1 change: 1 addition & 0 deletions src/GeneralUpdate.Core/Strategy/ClientStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ private async Task ExecuteStandardWorkflowAsync()
IsFreeze = a.IsFreeze,
AppType = a.AppType,
PackageType = a.PackageType,
UpdateLog = a.UpdateLog,
FallbackFullName = a.FallbackFullName,
FallbackFullUrl = a.FallbackFullUrl,
FallbackFullHash = a.FallbackFullHash
Expand Down
7 changes: 6 additions & 1 deletion tests/CoreTest/Download/DownloadModelsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public void DownloadAsset_Defaults_AreSensible()
Assert.Equal(DownloadPriority.Normal, asset.Priority);
Assert.Equal(0, asset.PackageType);
Assert.Null(asset.MinClientVersion);
Assert.Null(asset.UpdateLog);
Assert.False(asset.IsForcibly);
Assert.False(asset.IsFreeze);
}
Expand All @@ -39,7 +40,10 @@ public void DownloadAsset_FullySpecified_AllPropertiesSet()
FallbackFullUrl: "https://cdn/full.zip",
FallbackFullHash: "fullhash",
IsForcibly: true, IsFreeze: false
);
)
{
UpdateLog = "Release notes"
};

Assert.Equal("package.zip", asset.Name);
Assert.Equal("https://cdn/pkg.zip", asset.Url);
Expand All @@ -48,6 +52,7 @@ public void DownloadAsset_FullySpecified_AllPropertiesSet()
Assert.Equal("3.0.0", asset.Version);
Assert.Equal(DownloadPriority.High, asset.Priority);
Assert.Equal("2.0.0", asset.MinClientVersion);
Assert.Equal("Release notes", asset.UpdateLog);
Assert.Equal("full-pkg", asset.FallbackFullName);
Assert.Equal("https://cdn/full.zip", asset.FallbackFullUrl);
Assert.Equal("fullhash", asset.FallbackFullHash);
Expand Down
24 changes: 24 additions & 0 deletions tests/CoreTest/Download/Sources/HttpDownloadSourceTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Reflection;
using GeneralUpdate.Core.Configuration;
using GeneralUpdate.Core.Download.Abstractions;
using GeneralUpdate.Core.Download.Models;
using GeneralUpdate.Core.Download.Sources;
using GeneralUpdate.Core.Security;

Expand Down Expand Up @@ -103,4 +105,26 @@ public void Implements_IDownloadSource()
}

#endregion

#region Mapping

[Fact]
public void MapVersionEntry_PreservesUpdateLog()
{
var version = new VersionEntry
{
Name = "package.zip",
Url = "https://cdn.example.com/package.zip",
Version = "2.0.0",
UpdateLog = "# 2.0.0\n- Fixed startup issue"
};
var method = typeof(HttpDownloadSource).GetMethod("MapVersionEntry",
BindingFlags.NonPublic | BindingFlags.Static);

var asset = Assert.IsType<DownloadAsset>(method!.Invoke(null, new object[] { version }));

Assert.Equal(version.UpdateLog, asset.UpdateLog);
}

#endregion
}
61 changes: 61 additions & 0 deletions tests/CoreTest/Strategy/ClientStrategyUpdateLogTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using GeneralUpdate.Core;
using GeneralUpdate.Core.Configuration;
using GeneralUpdate.Core.Download;
using GeneralUpdate.Core.Download.Abstractions;
using GeneralUpdate.Core.Download.Models;
using GeneralUpdate.Core.Strategy;

namespace CoreTest.Strategy;

public class ClientStrategyUpdateLogTests
{
[Fact]
public async Task ExecuteAsync_PrecheckReceivesUpdateLog()
{
var updateLog = "# 2.0.0\n- Preserve release notes";
UpdateInfoEventArgs? captured = null;
var strategy = new ClientStrategy
{
DownloadSource = new StubDownloadSource(new DownloadAsset(
Name: "package.zip",
Url: "https://cdn.example.com/package.zip",
Size: 1024,
SHA256: "hash",
Version: "2.0.0",
AppType: (int)AppType.Client)
{
UpdateLog = updateLog
})
};

strategy.UseUpdatePrecheck(args =>
{
captured = args;
return true;
});
strategy.Create(new UpdateContext
{
UpdateUrl = "https://api.example.com/update",
ClientVersion = "1.0.0",
AppSecretKey = "key",
MainAppName = "MainApp",
InstallPath = Path.GetTempPath()
});

await strategy.ExecuteAsync();

Assert.NotNull(captured);
var version = Assert.Single(captured.Info!.Body!);
Assert.Equal(updateLog, version.UpdateLog);
}

private sealed class StubDownloadSource(DownloadAsset asset) : IDownloadSource
{
public Task<DownloadSourceResult> ListAsync(CancellationToken token = default)
=> Task.FromResult(new DownloadSourceResult
{
Assets = new[] { asset },
HasMainUpdate = true
});
}
}
Loading