add sb test for runtime packs in self-contained publish (#16783)
This commit is contained in:
parent
de811d8fdb
commit
a7815af504
3 changed files with 35 additions and 5 deletions
|
@ -14,7 +14,8 @@ public enum DotNetActions
|
|||
Run = 2,
|
||||
RunWeb = 4,
|
||||
Publish = 8,
|
||||
PublishComplex = 16,
|
||||
PublishR2R = 32,
|
||||
Test = 64,
|
||||
PublishSelfContained = 16,
|
||||
PublishComplex = 32,
|
||||
PublishR2R = 64,
|
||||
Test = 128,
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Microsoft.DotNet.SourceBuild.SmokeTests;
|
||||
|
||||
public class TestScenario
|
||||
|
@ -11,13 +14,15 @@ public class TestScenario
|
|||
public bool NoHttps { get; set; } = Config.TargetRid.Contains("osx");
|
||||
public string ScenarioName { get; }
|
||||
public DotNetTemplate Template { get; }
|
||||
public Action<string>? Validate { get; }
|
||||
|
||||
public TestScenario(string scenarioName, DotNetLanguage language, DotNetTemplate template, DotNetActions commands = DotNetActions.None)
|
||||
public TestScenario(string scenarioName, DotNetLanguage language, DotNetTemplate template, DotNetActions commands = DotNetActions.None, Action<string>? validate = null)
|
||||
{
|
||||
ScenarioName = scenarioName;
|
||||
Template = template;
|
||||
Language = language;
|
||||
Commands = commands;
|
||||
Validate = validate;
|
||||
}
|
||||
|
||||
internal void Execute(DotNetHelper dotNetHelper)
|
||||
|
@ -46,6 +51,10 @@ public class TestScenario
|
|||
{
|
||||
dotNetHelper.ExecutePublish(projectName, Template);
|
||||
}
|
||||
if (Commands.HasFlag(DotNetActions.PublishSelfContained))
|
||||
{
|
||||
dotNetHelper.ExecutePublish(projectName, Template, selfContained: true, rid: Config.TargetRid);
|
||||
}
|
||||
if (Commands.HasFlag(DotNetActions.PublishComplex))
|
||||
{
|
||||
dotNetHelper.ExecutePublish(projectName, Template, selfContained: false);
|
||||
|
@ -60,5 +69,8 @@ public class TestScenario
|
|||
{
|
||||
dotNetHelper.ExecuteTest(projectName);
|
||||
}
|
||||
|
||||
string projectPath = Path.Combine(DotNetHelper.ProjectsDirectory, projectName);
|
||||
Validate?.Invoke(projectPath);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Nodes;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
|
@ -41,7 +43,22 @@ public class WebScenarioTests : SmokeTests
|
|||
|
||||
yield return new(nameof(WebScenarioTests), DotNetLanguage.CSharp, DotNetTemplate.Razor, DotNetActions.Build | DotNetActions.Run | DotNetActions.Publish);
|
||||
yield return new(nameof(WebScenarioTests), DotNetLanguage.CSharp, DotNetTemplate.BlazorWasm, DotNetActions.Build | DotNetActions.Run | DotNetActions.Publish);
|
||||
yield return new(nameof(WebScenarioTests), DotNetLanguage.CSharp, DotNetTemplate.WebApp, DotNetActions.PublishSelfContained, VerifyRuntimePacksForSelfContained);
|
||||
yield return new(nameof(WebScenarioTests), DotNetLanguage.CSharp, DotNetTemplate.Worker);
|
||||
yield return new(nameof(WebScenarioTests), DotNetLanguage.CSharp, DotNetTemplate.Angular);
|
||||
}
|
||||
|
||||
private static void VerifyRuntimePacksForSelfContained(string projectPath)
|
||||
{
|
||||
// 'expectedPackageFiles' key in project.nuget.cache' will contain paths to restored packages
|
||||
// Since we are publishing an emtpy template, the only packages that could end up there are the ref packs we are after
|
||||
|
||||
string projNugetCachePath = Path.Combine(projectPath, "obj", "project.nuget.cache");
|
||||
|
||||
JsonNode? projNugetCache = JsonNode.Parse(File.ReadAllText(projNugetCachePath));
|
||||
string? restoredPackageFiles = projNugetCache?["expectedPackageFiles"]?.ToString();
|
||||
|
||||
Assert.True(restoredPackageFiles is not null, "Failed to parse project.nuget.cache");
|
||||
Assert.True("[]" == restoredPackageFiles, "Runtime packs were retrieved from NuGet instead of the SDK");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue