Skip to content

Commit eb95de4

Browse files
committed
wip cleanup
1 parent 1c3c7b5 commit eb95de4

File tree

5 files changed

+53
-43
lines changed

5 files changed

+53
-43
lines changed

Microsoft.NET.Build.Containers/Microsoft.NET.Build.Containers.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
3030
<Compile Remove="*.*" />
3131
<Compile Include="ReferenceParser.cs" />
32+
<Compile Include="KnownStrings.cs" />
3233
<Compile Include="ParseContainerProperties.cs" />
3334
<Compile Include="CreateNewImage.Interface.cs" />
3435
<Compile Include="CreateNewImageToolTask.cs" />

Test.Microsoft.NET.Build.Containers.Filesystem/CreateNewImageTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void CreateNewImage_Baseline()
4444
CreateNewImage task = new CreateNewImage();
4545
task.BaseRegistry = "mcr.microsoft.com";
4646
task.BaseImageName = "dotnet/runtime";
47-
task.BaseImageTag = "6.0";
47+
task.BaseImageTag = "7.0";
4848

4949
task.OutputRegistry = "localhost:5010";
5050
task.PublishDirectory = Path.Combine(newProjectDir.FullName, "bin", "release", "net7.0");
@@ -91,15 +91,15 @@ public void ParseContainerProperties_EndToEnd()
9191
Assert.AreEqual(0, dotnetPublish.ExitCode);
9292

9393
ParseContainerProperties pcp = new ParseContainerProperties();
94-
pcp.FullyQualifiedBaseImageName = "mcr.microsoft.com/dotnet/runtime:6.0";
94+
pcp.FullyQualifiedBaseImageName = "mcr.microsoft.com/dotnet/runtime:7.0";
9595
pcp.ContainerRegistry = "localhost:5010";
9696
pcp.ContainerImageName = "dotnet/testimage";
9797
pcp.ContainerImageTags = new [] {"5.0", "latest"};
9898

9999
Assert.IsTrue(pcp.Execute());
100100
Assert.AreEqual("mcr.microsoft.com", pcp.ParsedContainerRegistry);
101101
Assert.AreEqual("dotnet/runtime", pcp.ParsedContainerImage);
102-
Assert.AreEqual("6.0", pcp.ParsedContainerTag);
102+
Assert.AreEqual("7.0", pcp.ParsedContainerTag);
103103

104104
Assert.AreEqual("dotnet/testimage", pcp.NewContainerImageName);
105105
CollectionAssert.AreEquivalent(new []{ "5.0", "latest"}, pcp.NewContainerTags);

Test.Microsoft.NET.Build.Containers.Filesystem/DockerRegistryManager.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@ public class DockerRegistryManager
77
{
88
public const string BaseImage = "dotnet/runtime";
99
public const string BaseImageSource = "mcr.microsoft.com/";
10-
public const string BaseImageTag = "6.0";
10+
public const string BaseImageTag = "7.0";
1111
public const string LocalRegistry = "localhost:5010";
1212
public const string FullyQualifiedBaseImageDefault = $"{BaseImageSource}{BaseImage}:{BaseImageTag}";
1313
private static string s_registryContainerId;
1414

1515
private static void Exec(string command, string args) {
16-
var startInfo = new ProcessStartInfo(command, args){
16+
var psi = new ProcessStartInfo(command, args)
17+
{
18+
RedirectStandardOutput = true,
1719
RedirectStandardError = true,
18-
RedirectStandardOutput = true
1920
};
20-
Process cmd = Process.Start(startInfo);
21-
Assert.IsNotNull(cmd);
22-
cmd.WaitForExit();
23-
Assert.AreEqual(0, cmd.ExitCode, cmd.StandardOutput.ReadToEnd());
21+
var proc = Process.Start(psi);
22+
Assert.IsNotNull(proc);
23+
proc.WaitForExit();
24+
var stdout = proc.StandardOutput.ReadToEnd();
25+
var stderr = proc.StandardError.ReadToEnd();
26+
var message = $"StdOut:\n{stdout}\nStdErr:\n{stderr}";
27+
Assert.AreEqual(0, proc.ExitCode, message);
2428
}
2529

2630
public static void LocateMSBuild()

Test.Microsoft.NET.Build.Containers.Filesystem/EndToEnd.cs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,23 @@ public static string NewImageName([CallerMemberName] string callerMemberName = "
2222
return callerMemberName;
2323
}
2424

25+
public static async Task Execute(string command, string args)
26+
{
27+
var psi = new ProcessStartInfo(command, args)
28+
{
29+
RedirectStandardOutput = true,
30+
RedirectStandardError = true,
31+
};
32+
var proc = Process.Start(psi);
33+
Assert.IsNotNull(proc);
34+
await proc.WaitForExitAsync();
35+
var stdout = proc.StandardOutput.ReadToEnd();
36+
var stderr = proc.StandardError.ReadToEnd();
37+
var message = $"StdOut:\n{stdout}\nStdErr:\n{stderr}";
38+
Assert.AreEqual(0, proc.ExitCode, message);
39+
40+
}
41+
2542
[TestMethod]
2643
public async Task ApiEndToEndWithRegistryPushAndPull()
2744
{
@@ -99,26 +116,12 @@ private static async Task<string> BuildLocalApp()
99116
d.Delete(recursive: true);
100117
}
101118

102-
ProcessStartInfo psi = new("dotnet", "new console -f net6.0 -o MinimalTestApp")
103-
{
104-
RedirectStandardOutput = true,
105-
RedirectStandardError = true,
106-
};
107-
108-
Process dotnetNew = Process.Start(psi);
109-
110-
Assert.IsNotNull(dotnetNew);
111-
await dotnetNew.WaitForExitAsync();
112-
Assert.AreEqual(0, dotnetNew.ExitCode, await dotnetNew.StandardOutput.ReadToEndAsync() + await dotnetNew.StandardError.ReadToEndAsync());
113-
119+
await Execute("dotnet", "new console -f net7.0 -o MinimalTestApp");
114120
// Build project
115121

116-
Process publish = Process.Start("dotnet", "publish -bl MinimalTestApp -r linux-x64");
117-
Assert.IsNotNull(publish);
118-
await publish.WaitForExitAsync();
119-
Assert.AreEqual(0, publish.ExitCode);
120-
121-
string publishDirectory = Path.Join("MinimalTestApp", "bin", "Debug", "net6.0", "linux-x64", "publish");
122+
await Execute("dotnet", "publish -bl MinimalTestApp -r linux-x64");
123+
124+
string publishDirectory = Path.Join("MinimalTestApp", "bin", "Debug", "net7.0", "linux-x64", "publish");
122125
return publishDirectory;
123126
}
124127

Test.Microsoft.NET.Build.Containers.Filesystem/ParseContainerPropertiesTests.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@ public class ParseContainerPropertiesTests
99
[TestMethod]
1010
public void Baseline()
1111
{
12-
ParseContainerProperties task = new ParseContainerProperties();
13-
task.FullyQualifiedBaseImageName = "mcr.microsoft.com/dotnet/runtime:6.0";
14-
task.ContainerRegistry = "localhost:5010";
15-
task.ContainerImageName = "dotnet/testimage";
16-
task.ContainerImageTags = new[] { "5.0", "latest" };
12+
var (project, _) = Evaluator.InitProject(new () {
13+
[ContainerBaseImage] = "mcr.microsoft.com/dotnet/runtime:7.0",
14+
[ContainerRegistry] = "localhost:5010",
15+
[ContainerImageName] = "dotnet/testimage",
16+
[ContainerImageTags] = "7.0;latest"
17+
});
18+
var instance = project.CreateProjectInstance(global::Microsoft.Build.Execution.ProjectInstanceSettings.None);
19+
Assert.IsTrue(instance.Build(new[]{ComputeContainerConfig}, null, null, out var outputs));
1720

18-
Assert.IsTrue(task.Execute());
19-
Assert.AreEqual("mcr.microsoft.com", task.ParsedContainerRegistry);
20-
Assert.AreEqual("dotnet/runtime", task.ParsedContainerImage);
21-
Assert.AreEqual("6.0", task.ParsedContainerTag);
21+
Assert.AreEqual("mcr.microsoft.com", instance.GetPropertyValue(ContainerBaseRegistry));
22+
Assert.AreEqual("dotnet/runtime", instance.GetPropertyValue(ContainerBaseName));
23+
Assert.AreEqual("7.0", instance.GetPropertyValue(ContainerBaseTag));
2224

2325
Assert.AreEqual("dotnet/testimage", task.NewContainerImageName);
24-
CollectionAssert.AreEquivalent(new[] { "5.0", "latest" }, task.NewContainerTags);
26+
CollectionAssert.AreEquivalent(new[] { "7.0", "latest" }, task.NewContainerTags);
2527
}
2628

2729
[TestMethod]
@@ -66,7 +68,7 @@ public void UserRegistriesWithNoSchemeGetHttps()
6668
public void SpacesGetReplacedWithDashes()
6769
{
6870
var (project, _) = Evaluator.InitProject(new () {
69-
[ContainerBaseImage] = "mcr microsoft com/dotnet runtime:6.0",
71+
[ContainerBaseImage] = "mcr microsoft com/dotnet runtime:7.0",
7072
[ContainerRegistry] = "localhost:5010"
7173
});
7274

@@ -75,14 +77,14 @@ public void SpacesGetReplacedWithDashes()
7577

7678
Assert.AreEqual("mcr-microsoft-com", instance.GetPropertyValue(ContainerBaseRegistry));
7779
Assert.AreEqual("dotnet-runtime", instance.GetPropertyValue(ContainerBaseName));
78-
Assert.AreEqual("6.0", instance.GetPropertyValue(ContainerBaseTag));
80+
Assert.AreEqual("7.0", instance.GetPropertyValue(ContainerBaseTag));
7981
}
8082

8183
[TestMethod]
8284
public void RegexCatchesInvalidContainerNames()
8385
{
8486
var (project, logs) = Evaluator.InitProject(new () {
85-
[ContainerBaseImage] = "mcr.microsoft.com/dotnet/runtime:6.0",
87+
[ContainerBaseImage] = "mcr.microsoft.com/dotnet/runtime:7.0",
8688
[ContainerRegistry] = "localhost:5010",
8789
[ContainerImageName] = "dotnet testimage",
8890
[ContainerImageTag] = "5.0"
@@ -98,7 +100,7 @@ public void RegexCatchesInvalidContainerNames()
98100
public void RegexCatchesInvalidContainerTags()
99101
{
100102
var (project, logs) = Evaluator.InitProject(new () {
101-
[ContainerBaseImage] = "mcr.microsoft.com/dotnet/runtime:6.0",
103+
[ContainerBaseImage] = "mcr.microsoft.com/dotnet/runtime:7.0",
102104
[ContainerRegistry] = "localhost:5010",
103105
[ContainerImageName] = "dotnet/testimage",
104106
[ContainerImageTag] = "5 0"
@@ -115,7 +117,7 @@ public void RegexCatchesInvalidContainerTags()
115117
public void CanOnlySupplyOneOfTagAndTags()
116118
{
117119
var (project, logs) = Evaluator.InitProject(new () {
118-
[ContainerBaseImage] = "mcr.microsoft.com/dotnet/runtime:6.0",
120+
[ContainerBaseImage] = "mcr.microsoft.com/dotnet/runtime:7.0",
119121
[ContainerRegistry] = "localhost:5010",
120122
[ContainerImageName] = "dotnet/testimage",
121123
[ContainerImageTag] = "5.0",

0 commit comments

Comments
 (0)