Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--overwrite-old-items flag is failing because of equality comparison on semVerLikeVersion and instead duplicates are left in the feed #630

Merged
Merged
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
111 changes: 110 additions & 1 deletion src/NetSparkle.Tests.AppCastGenerator/AppCastMakerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,7 @@ public void ChangelogNameInAppcastMatchesFilesystem(AppCastMakerType appCastMake
var signatureManager = _fixture.GetSignatureManager();
Assert.True(signatureManager.KeysExist());

AppCastMaker maker = appCastMakerType == AppCastMakerType.Xml
AppCastMaker maker = appCastMakerType == AppCastMakerType.Xml
? new XMLAppCastMaker(signatureManager, opts)
: new JsonAppCastMaker(signatureManager, opts);
var appCastFileName = maker.GetPathToAppCastOutput(opts.OutputDirectory, opts.SourceBinaryDirectory);
Expand All @@ -1405,6 +1405,115 @@ public void ChangelogNameInAppcastMatchesFilesystem(AppCastMakerType appCastMake
}
}

[Theory]
[InlineData(AppCastMakerType.Xml)]
[InlineData(AppCastMakerType.Json)]
public void OverwriteExistingEntry(AppCastMakerType appCastMakerType)
{
// setup test dir
var tempDir = GetCleanTempDir();
// create dummy files
var dummyFilePath = Path.Combine(tempDir, "hello 1.0.txt");
const int fileSizeBytes = 57;
var tempData = RandomString(fileSizeBytes);
File.WriteAllText(dummyFilePath, tempData);

var appCastData = @"";
// now create something with some actual data!
if (appCastMakerType == AppCastMakerType.Xml)
{
appCastData = @"
<?xml version=""1.0"" encoding=""UTF-8""?>
<rss xmlns:dc=""http://purl.org/dc/elements/1.1/"" xmlns:sparkle=""http://www.andymatuschak.org/xml-namespaces/sparkle"" version=""2.0"">
<channel>
<title>NetSparkle Test App</title>
<link>https://netsparkleupdater.github.io/NetSparkle/files/sample-app/appcast.xml</link>
<description>Most recent changes with links to updates.</description>
<language>en</language>
<item>
<title>Version 1.0 Alpha 1</title>
<sparkle:releaseNotesLink>
https://netsparkleupdater.github.io/NetSparkle/files/sample-app/2.0-release-notes.md
</sparkle:releaseNotesLink>
<pubDate>Fri, 28 Oct 2016 10:30:00 +0000</pubDate>
<enclosure url=""https://netsparkleupdater.github.io/NetSparkle/files/sample-app/NetSparkleUpdate.exe""
sparkle:version=""1.0""
sparkle:shortVersionString=""1.0""
sparkle:os=""windows""
length=""2337""
type=""application/octet-stream""
sparkle:signature=""bar"" />
</item>
</channel>
</rss>
".Trim();
}
else
{
appCastData = @"
{
""title"": ""NetSparkle Test App"",
""langauge"": ""en"",
""description"": ""Most recent changes with links to updates."",
""link"": ""https://netsparkleupdater.github.io/NetSparkle/files/sample-app/appcast.json"",
""items"": [
{
""title"": ""Version 1.0 Beta 1"",
""release_notes_link"": ""https://netsparkleupdater.github.io/NetSparkle/files/sample-app/2.0-release-notes.md"",
""publication_date"": ""2016-10-28T10:30:00"",
""url"": ""https://netsparkleupdater.github.io/NetSparkle/files/sample-app/NetSparkleUpdate.exe"",
""version"": ""1.0"",
""short_version"": ""1.0"",
""os"": ""windows"",
""size"": 1337,
""type"": ""application/octet-stream"",
""signature"": ""foo""
}
]
}".Trim();
}
var fakeAppCastFilePath = Path.Combine(tempDir, Guid.NewGuid().ToString() + (appCastMakerType == AppCastMakerType.Xml ? ".xml" : ".json"));
File.WriteAllText(fakeAppCastFilePath, appCastData);
var dummyChangelogFilePath = Path.Combine(tempDir, "change_log_1.0.md");
tempData = RandomString(fileSizeBytes);
File.WriteAllText(dummyChangelogFilePath, tempData);
var opts = new Options()
{
FileExtractVersion = true,
SearchBinarySubDirectories = true,
SourceBinaryDirectory = tempDir,
ChangeLogPath = tempDir,
Extensions = "txt",
OutputDirectory = tempDir,
OperatingSystem = "windows",
ProductName = "ProductName",
BaseUrl = "https://example.com/downloads",
ChangeLogUrl = "http://baseURL/appname/changelogs/",
ChangeLogFileNamePrefix = "change_log_",
OverwriteOldItemsInAppcast = true,
ReparseExistingAppCast = true,
HumanReadableOutput = true
};

try
{
var signatureManager = _fixture.GetSignatureManager();
Assert.True(signatureManager.KeysExist());

AppCastMaker maker = appCastMakerType == AppCastMakerType.Xml
? new XMLAppCastMaker(signatureManager, opts)
: new JsonAppCastMaker(signatureManager, opts);
var (items, productName) = maker.LoadAppCastItemsAndProductName(opts.SourceBinaryDirectory, opts.ReparseExistingAppCast, fakeAppCastFilePath);
Assert.Single(items);
Assert.EndsWith("change_log_1.0.md", items[0].ReleaseNotesLink);
}
finally
{
// make sure tempDir always cleaned up
CleanUpDir(tempDir);
}
}

[Theory]
[InlineData(AppCastMakerType.Xml)]
[InlineData(AppCastMakerType.Json)]
Expand Down
2 changes: 1 addition & 1 deletion src/NetSparkle.Tools.AppCastGenerator/AppCastMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ public string GetPathToAppCastOutput(string desiredOutputDirectory, string sourc
}
var semVerLikeVersion = SemVerLike.Parse(productVersion);

var itemFoundInAppcast = items.Where(x => x.SemVerLikeVersion != null && x.SemVerLikeVersion == semVerLikeVersion).FirstOrDefault();
var itemFoundInAppcast = items.Where(x => x.SemVerLikeVersion != null && x.SemVerLikeVersion.Equals(semVerLikeVersion)).FirstOrDefault();
if (itemFoundInAppcast != null && _opts.OverwriteOldItemsInAppcast)
{
Console.WriteLine($"Removing existing app cast item with version {semVerLikeVersion} so we can add the version on disk to the app cast...");
Expand Down
Loading