Skip to content

Commit

Permalink
Enable tests following the net10 transition (#44931)
Browse files Browse the repository at this point in the history
  • Loading branch information
surayya-MS authored Dec 2, 2024
2 parents 830cf11 + 9592c8a commit 3540e95
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public CreateNewImageTests(ITestOutputHelper testOutput)
_testOutput = testOutput;
}

[DockerAvailableFact(Skip = "https://github.com/dotnet/sdk/issues/42850")]
[DockerAvailableFact]
public void CreateNewImage_Baseline()
{
DirectoryInfo newProjectDir = new(GetTestDirectoryName());
Expand Down Expand Up @@ -70,7 +70,7 @@ private static ImageConfig GetImageConfigFromTask(CreateNewImage task)
return new(task.GeneratedContainerConfiguration);
}

[DockerAvailableFact(Skip = "https://github.com/dotnet/sdk/issues/42850")]
[DockerAvailableFact]
public void ParseContainerProperties_EndToEnd()
{
DirectoryInfo newProjectDir = new(GetTestDirectoryName());
Expand Down Expand Up @@ -133,7 +133,7 @@ public void ParseContainerProperties_EndToEnd()
/// <summary>
/// Creates a console app that outputs the environment variable added to the image.
/// </summary>
[DockerAvailableFact(Skip = "https://github.com/dotnet/sdk/issues/42850")]
[DockerAvailableFact]
public void Tasks_EndToEnd_With_EnvironmentVariable_Validation()
{
DirectoryInfo newProjectDir = new(GetTestDirectoryName());
Expand All @@ -151,6 +151,8 @@ public void Tasks_EndToEnd_With_EnvironmentVariable_Validation()
.Execute()
.Should().Pass();

EndToEndTests.ChangeTargetFrameworkAfterAppCreation(newProjectDir.FullName);

File.WriteAllText(Path.Combine(newProjectDir.FullName, "Program.cs"), $"Console.Write(Environment.GetEnvironmentVariable(\"GoodEnvVar\"));");

new DotnetCommand(_testOutput, "build", "--configuration", "release", "/p:runtimeidentifier=linux-x64", $"/p:RuntimeFrameworkVersion={DockerRegistryManager.RuntimeFrameworkVersion}")
Expand Down Expand Up @@ -191,7 +193,7 @@ public void Tasks_EndToEnd_With_EnvironmentVariable_Validation()
cni.BaseImageTag = pcp.ParsedContainerTag;
cni.Repository = pcp.NewContainerRepository;
cni.OutputRegistry = pcp.NewContainerRegistry;
cni.PublishDirectory = Path.Combine(newProjectDir.FullName, "bin", "release", ToolsetInfo.CurrentTargetFramework, "linux-x64");
cni.PublishDirectory = Path.Combine(newProjectDir.FullName, "bin", "release", EndToEndTests._oldFramework, "linux-x64");
cni.WorkingDirectory = "/app";
cni.Entrypoint = new TaskItem[] { new($"/app/{newProjectDir.Name}") };
cni.ImageTags = pcp.NewContainerTags;
Expand All @@ -216,7 +218,7 @@ public void Tasks_EndToEnd_With_EnvironmentVariable_Validation()
.And.HaveStdOut("Foo");
}

[DockerAvailableFact(Skip = "https://github.com/dotnet/sdk/issues/42850")]
[DockerAvailableFact]
public async System.Threading.Tasks.Task CreateNewImage_RootlessBaseImage()
{
const string RootlessBase = "dotnet/rootlessbase";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,20 @@ public void Dispose()
_loggerFactory.Dispose();
}

[DockerAvailableFact(Skip = "https://github.com/dotnet/sdk/issues/42850")]
internal static readonly string _oldFramework = "net9.0";
// CLI will not let us to target net9.0 anymore but we still need it because images for net10.0 aren't ready yet.
// so we let it create net10.0 app, then change the target. Since we're building just small sample applications, it works.
internal static void ChangeTargetFrameworkAfterAppCreation(string path)
{
DirectoryInfo d = new DirectoryInfo(path);
FileInfo[] Files = d.GetFiles("*.csproj"); //Getting .csproj files
string csprojFilename = Files[0].Name; // There is only one
string text = File.ReadAllText(Path.Combine(path, csprojFilename));
text = text.Replace("net10.0", _oldFramework);
File.WriteAllText(Path.Combine(path, csprojFilename), text);
}

[DockerAvailableFact]
public async Task ApiEndToEndWithRegistryPushAndPull()
{
ILogger logger = _loggerFactory.CreateLogger(nameof(ApiEndToEndWithRegistryPushAndPull));
Expand Down Expand Up @@ -85,7 +98,7 @@ public async Task ApiEndToEndWithRegistryPushAndPull()
}
}

[DockerAvailableFact(Skip = "https://github.com/dotnet/sdk/issues/42850")]
[DockerAvailableFact]
public async Task ApiEndToEndWithLocalLoad()
{
ILogger logger = _loggerFactory.CreateLogger(nameof(ApiEndToEndWithLocalLoad));
Expand Down Expand Up @@ -126,7 +139,7 @@ public async Task ApiEndToEndWithLocalLoad()
}
}

[DockerAvailableFact(Skip = "https://github.com/dotnet/sdk/issues/42850")]
[DockerAvailableFact]
public async Task ApiEndToEndWithArchiveWritingAndLoad()
{
ILogger logger = _loggerFactory.CreateLogger(nameof(ApiEndToEndWithArchiveWritingAndLoad));
Expand Down Expand Up @@ -193,8 +206,11 @@ private string BuildLocalApp([CallerMemberName] string testName = "TestName", st
.Execute()
.Should().Pass();

ChangeTargetFrameworkAfterAppCreation(Path.Combine(TestSettings.TestArtifactsDirectory, testName, "MinimalTestApp"));


var publishCommand =
new DotnetCommand(_testOutput, "publish", "-bl", "MinimalTestApp", "-r", rid, "-f", tfm, "-c", "Debug")
new DotnetCommand(_testOutput, "publish", "-bl", "MinimalTestApp", "-r", rid, "-f", _oldFramework, "-c", "Debug")
.WithWorkingDirectory(workingDirectory);

if (tfm == ToolsetInfo.CurrentTargetFramework)
Expand All @@ -205,11 +221,11 @@ private string BuildLocalApp([CallerMemberName] string testName = "TestName", st
publishCommand.Execute()
.Should().Pass();

string publishDirectory = Path.Join(workingDirectory, "MinimalTestApp", "bin", "Debug", tfm, rid, "publish");
string publishDirectory = Path.Join(workingDirectory, "MinimalTestApp", "bin", "Debug", _oldFramework, rid, "publish");
return publishDirectory;
}

[DockerAvailableFact(Skip = "https://github.com/dotnet/sdk/issues/42850")]
[DockerAvailableFact]
public async Task EndToEnd_MultiProjectSolution()
{
ILogger logger = _loggerFactory.CreateLogger(nameof(EndToEnd_MultiProjectSolution));
Expand Down Expand Up @@ -262,7 +278,7 @@ public async Task EndToEnd_MultiProjectSolution()
document
.Descendants()
.First(e => e.Name.LocalName == "TargetFramework")
.Value = ToolsetInfo.CurrentTargetFramework;
.Value = _oldFramework;

stream.SetLength(0);
await document.SaveAsync(stream, SaveOptions.None, CancellationToken.None);
Expand All @@ -275,7 +291,7 @@ public async Task EndToEnd_MultiProjectSolution()
document
.Descendants()
.First(e => e.Name.LocalName == "TargetFramework")
.Value = ToolsetInfo.CurrentTargetFramework;
.Value = _oldFramework;

stream.SetLength(0);
await document.SaveAsync(stream, SaveOptions.None, CancellationToken.None);
Expand All @@ -291,7 +307,7 @@ public async Task EndToEnd_MultiProjectSolution()
commandResult.Should().HaveStdOutContaining("Pushed image 'consoleapp:latest'");
}

[DockerAvailableTheory(Skip = "https://github.com/dotnet/sdk/issues/42850")]
[DockerAvailableTheory(Skip = "https://github.com/dotnet/sdk/issues/45181")]
[InlineData("webapi", false)]
[InlineData("webapi", true)]
[InlineData("worker", false)]
Expand All @@ -313,7 +329,6 @@ public async Task EndToEnd_NoAPI_ProjectType(string projectType, bool addPackage

newProjectDir.Create();
privateNuGetAssets.Create();

new DotnetNewCommand(_testOutput, projectType, "-f", ToolsetInfo.CurrentTargetFramework)
.WithVirtualHive()
.WithWorkingDirectory(newProjectDir.FullName)
Expand Down Expand Up @@ -399,7 +414,6 @@ public async Task EndToEnd_NoAPI_ProjectType(string projectType, bool addPackage
processResult.Should().Pass();
Assert.NotNull(processResult.StdOut);
string appContainerId = processResult.StdOut.Trim();

bool everSucceeded = false;


Expand Down Expand Up @@ -468,7 +482,7 @@ public async Task EndToEnd_NoAPI_ProjectType(string projectType, bool addPackage
privateNuGetAssets.Delete(true);
}

[DockerAvailableFact(Skip = "https://github.com/dotnet/sdk/issues/42850")]
[DockerAvailableFact]
public void EndToEnd_NoAPI_Console()
{
DirectoryInfo newProjectDir = new(Path.Combine(TestSettings.TestArtifactsDirectory, "CreateNewImageTest"));
Expand All @@ -494,6 +508,7 @@ public void EndToEnd_NoAPI_Console()
.WithEnvironmentVariable("NUGET_PACKAGES", privateNuGetAssets.FullName)
.Execute()
.Should().Pass();
ChangeTargetFrameworkAfterAppCreation(newProjectDir.FullName);

File.Copy(Path.Combine(TestContext.Current.TestExecutionDirectory, "NuGet.config"), Path.Combine(newProjectDir.FullName, "NuGet.config"));

Expand All @@ -506,7 +521,7 @@ public void EndToEnd_NoAPI_Console()
.Should().Pass();

// Add package to the project
new DotnetCommand(_testOutput, "add", "package", "Microsoft.NET.Build.Containers", "-f", ToolsetInfo.CurrentTargetFramework, "-v", packageVersion)
new DotnetCommand(_testOutput, "add", "package", "Microsoft.NET.Build.Containers", "-f", _oldFramework , "-v", packageVersion)
.WithEnvironmentVariable("NUGET_PACKAGES", privateNuGetAssets.FullName)
.WithWorkingDirectory(newProjectDir.FullName)
.Execute()
Expand Down Expand Up @@ -555,7 +570,7 @@ public void EndToEnd_NoAPI_Console()
[DockerSupportsArchInlineData("linux/386", "linux-x86", "/app", Skip = "There's no apphost for linux-x86 so we can't execute self-contained, and there's no .NET runtime base image for linux-x86 so we can't execute framework-dependent.")]
[DockerSupportsArchInlineData("windows/amd64", "win-x64", "C:\\app")]
[DockerSupportsArchInlineData("linux/amd64", "linux-x64", "/app")]
[DockerAvailableTheory(Skip = "https://github.com/dotnet/sdk/issues/42850")]
[DockerAvailableTheory]
public async Task CanPackageForAllSupportedContainerRIDs(string dockerPlatform, string rid, string workingDir)
{
ILogger logger = _loggerFactory.CreateLogger(nameof(CanPackageForAllSupportedContainerRIDs));
Expand Down
8 changes: 4 additions & 4 deletions test/dotnet-watch.Tests/HotReload/ApplyDeltaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Microsoft.DotNet.Watcher.Tests
{
public class ApplyDeltaTests(ITestOutputHelper logger) : DotNetWatchTestBase(logger)
{
[Fact(Skip = "https://github.com/dotnet/sdk/issues/42850")]
[Fact]
public async Task AddSourceFile()
{
Logger.WriteLine("AddSourceFile started");
Expand Down Expand Up @@ -43,7 +43,7 @@ public static void Print()
await App.AssertOutputLineStartsWith("Changed!");
}

[Fact(Skip = "https://github.com/dotnet/sdk/issues/42850")]
[Fact]
public async Task ChangeFileInDependency()
{
var testAsset = TestAssets.CopyTestAsset("WatchAppWithProjectDeps")
Expand All @@ -69,7 +69,7 @@ public static void Print()
}

// Test is timing out on .NET Framework: https://github.com/dotnet/sdk/issues/41669
[CoreMSBuildOnlyFact(Skip = "https://github.com/dotnet/sdk/issues/42850")]
[CoreMSBuildOnlyFact]
public async Task HandleTypeLoadFailure()
{
var testAsset = TestAssets.CopyTestAsset("WatchAppTypeLoadFailure")
Expand Down Expand Up @@ -206,7 +206,7 @@ public async Task BlazorWasm()
//await App.AssertOutputLineStartsWith(MessageDescriptor.HotReloadSucceeded);
}

[Fact(Skip = "https://github.com/dotnet/sdk/issues/42850")]
[Fact]
public async Task BlazorWasm_MSBuildWarning()
{
var testAsset = TestAssets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Microsoft.DotNet.Watcher.Tests;

public class CompilationHandlerTests(ITestOutputHelper logger) : DotNetWatchTestBase(logger)
{
[Fact(Skip = "https://github.com/dotnet/sdk/issues/42850")]
[Fact]
public async Task ReferenceOutputAssembly_False()
{
var testAsset = TestAssets.CopyTestAsset("WatchAppMultiProc")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ async Task MakeRudeEditChange()
}
}

[Theory(Skip = "https://github.com/dotnet/sdk/issues/42850")]
[Theory]
[CombinatorialData]
public async Task UpdateAppliedToNewProcesses(bool sharedOutput)
{
Expand Down

0 comments on commit 3540e95

Please sign in to comment.