Skip to content

Commit

Permalink
Fix issue where global.json which didn't specify workload version wou…
Browse files Browse the repository at this point in the history
…ld prevent workload install state from being used
  • Loading branch information
dsplaisted committed Jul 4, 2023
1 parent 8ce7dca commit 3cf4bbe
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,12 @@ internal SdkDirectoryWorkloadManifestProvider(string sdkRootPath, string sdkVers

var availableWorkloadSets = GetAvailableWorkloadSets();

if (globalJsonPath != null)
string? globalJsonWorkloadSetVersion = GlobalJsonReader.GetWorkloadVersionFromGlobalJson(globalJsonPath);
if (globalJsonWorkloadSetVersion != null)
{
string? globalJsonWorkloadSetVersion = GlobalJsonReader.GetWorkloadVersionFromGlobalJson(globalJsonPath);
if (globalJsonWorkloadSetVersion != null)
if (!availableWorkloadSets.TryGetValue(globalJsonWorkloadSetVersion, out _workloadSet))
{
if (!availableWorkloadSets.TryGetValue(globalJsonWorkloadSetVersion, out _workloadSet))
{
throw new FileNotFoundException(string.Format(Strings.WorkloadVersionFromGlobalJsonNotFound, globalJsonWorkloadSetVersion, globalJsonPath));
}
throw new FileNotFoundException(string.Format(Strings.WorkloadVersionFromGlobalJsonNotFound, globalJsonWorkloadSetVersion, globalJsonPath));
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,51 @@ var sdkDirectoryWorkloadManifestProvider
.BeEquivalentTo("ios: 11.0.2/8.0.100");
}

[Fact]
public void GlobalJsonWithoutWorkloadVersionDoesNotOverrideInstallState()
{
Initialize("8.0.200");

string? globalJsonPath = Path.Combine(_testDirectory, "global.json");
File.WriteAllText(globalJsonPath, "{}");

CreateMockInstallState("8.0.200",
"""
{
"workloadVersion": "8.0.200",
}
""");

CreateMockManifest(_manifestRoot, "8.0.100", "ios", "11.0.1", true);
CreateMockManifest(_manifestRoot, "8.0.100", "ios", "11.0.2", true);
CreateMockManifest(_manifestRoot, "8.0.200", "ios", "12.0.1", true);

CreateMockWorkloadSet(_manifestRoot, "8.0.200", "8.0.200", """
{
"ios": "11.0.1/8.0.100"
}
""");

CreateMockWorkloadSet(_manifestRoot, "8.0.200", "8.0.201", """
{
"ios": "11.0.2/8.0.100"
}
""");

CreateMockWorkloadSet(_manifestRoot, "8.0.200", "8.0.202", """
{
"ios": "12.0.1/8.0.200"
}
""");

var sdkDirectoryWorkloadManifestProvider
= new SdkDirectoryWorkloadManifestProvider(sdkRootPath: _fakeDotnetRootDirectory, sdkVersion: "8.0.200", userProfileDir: null, globalJsonPath: globalJsonPath);

GetManifestContents(sdkDirectoryWorkloadManifestProvider)
.Should()
.BeEquivalentTo("ios: 11.0.1/8.0.100");
}

[Fact]
public void ItShouldReturnManifestsFromTestHook()
{
Expand Down

0 comments on commit 3cf4bbe

Please sign in to comment.