Skip to content

Commit

Permalink
Add failing test for bug in GetLatestMaskedVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
borland committed Dec 19, 2024
1 parent 4d3b9e5 commit 8d3746c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<NeutralLanguage>en-US</NeutralLanguage>
<Copyright>Copyright © Octopus Deploy 2017</Copyright>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<!-- nuget packages with security warnings should not break the build -->
<WarningsNotAsErrors>CS0618,NU1901,NU1902,NU1903</WarningsNotAsErrors>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Octopus.Versioning\Octopus.Versioning.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Octopus.Versioning.Octopus;
using Octopus.Versioning.Semver;
Expand Down Expand Up @@ -220,5 +221,34 @@ public void GetLatestVersionMask(string version, string latestVersion, string ex
Assert.AreEqual(expected, latestMaskedVersionNewImplementationPrefix?.ToString());
}
}

[Test]
public void GetLatestMaskedVersionShouldNotBeOrderDependent()
{
var mask = OctopusVersionMaskParser.Parse("0.0.7+branchA.c.c.i");
var versionParser = new OctopusVersionParser();

var versions = new[]
{
"0.0.7+branchA.1",
"0.0.7+branchA",
"0.0.6+branchA",
"0.0.5-beta.2",
"0.0.5-beta.1",
"0.0.4-beta",
"0.0.3",
"0.0.1",
"0.0.2"
}.Select(v => (IVersion)versionParser.Parse(v))
.ToList();

// This is the correct answer that we are looking for
Assert.AreEqual("0.0.7+branchA.1", mask.GetLatestMaskedVersion(versions)!.ToString());

// Now the real test; it should still return the same result even if the versions are not in the correct order
var reversedVersions = versions.ToList();
reversedVersions.Reverse();
Assert.AreEqual("0.0.7+branchA.1", mask.GetLatestMaskedVersion(reversedVersions)!.ToString());
}
}
}

0 comments on commit 8d3746c

Please sign in to comment.