Skip to content

Commit d549576

Browse files
authored
updating the bundle version resolution to pick the maximum version allowed by the version range (#4333)
* updating the bundle version resolution to pick the maximum version allowed by the version range * Updating version resolution logic to use FirstorDefualt()
1 parent 190e3f6 commit d549576

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,14 @@ private static string FindBestVersionMatch(VersionRange versionRange, IEnumerabl
187187
{
188188
var dirName = Path.GetFileName(p);
189189
NuGetVersion.TryParse(dirName, out NuGetVersion version);
190+
if (version != null)
191+
{
192+
version = versionRange.Satisfies(version) ? version : null;
193+
}
190194
return version;
191195
}).Where(v => v != null);
192196

193-
return versionRange.FindBestMatch(bundleVersions)?.ToString();
197+
return bundleVersions.OrderByDescending(version => version.Version).FirstOrDefault()?.ToString();
194198
}
195199
}
196200
}

test/WebJobs.Script.Tests/ExtensionBundle/ExtensionBundleManagerTests.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ public void TryLocateExtensionBundle_BundleNotPersent_ReturnsFalse()
7171
Assert.Null(path);
7272
}
7373

74-
[Fact]
75-
public async Task GetExtensionBundle_BundlePresentAtProbingLocation_ReturnsTrue()
74+
[Theory]
75+
[InlineData("[2.*, 3.0.0)")]
76+
[InlineData("[2.0.0, 3.0.0)")]
77+
public async Task GetExtensionBundle_BundlePresentAtProbingLocation_ReturnsTrue(string versionRange)
7678
{
77-
var options = GetTestExtensionBundleOptions(BundleId, "[2.*, 3.0.0)");
79+
var options = GetTestExtensionBundleOptions(BundleId, versionRange);
7880
var fileSystemTuple = CreateFileSystem();
7981
var directoryBase = fileSystemTuple.Item2;
8082
var fileBase = fileSystemTuple.Item3;
@@ -87,11 +89,13 @@ public async Task GetExtensionBundle_BundlePresentAtProbingLocation_ReturnsTrue(
8789
{
8890
Path.Combine(firstDefaultProbingPath, "1.0.0"),
8991
Path.Combine(firstDefaultProbingPath, "2.0.0"),
92+
Path.Combine(firstDefaultProbingPath, "2.0.1"),
93+
Path.Combine(firstDefaultProbingPath, "2.0.2"),
9094
Path.Combine(firstDefaultProbingPath, "3.0.2"),
9195
Path.Combine(firstDefaultProbingPath, "invalidVersion")
9296
});
9397

94-
string defaultPath = Path.Combine(firstDefaultProbingPath, "2.0.0");
98+
string defaultPath = Path.Combine(firstDefaultProbingPath, "2.0.2");
9599
fileBase.Setup(f => f.Exists(Path.Combine(defaultPath, "bundle.json"))).Returns(true);
96100

97101
FileUtility.Instance = fileSystemTuple.Item1.Object;

0 commit comments

Comments
 (0)