Skip to content

Commit 0896a8b

Browse files
committed
working on test fixes post-rebase
1 parent eb95de4 commit 0896a8b

File tree

5 files changed

+14
-64
lines changed

5 files changed

+14
-64
lines changed

Directory.Build.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
<ItemGroup>
33
<PackageReference Include="Nerdbank.GitVersioning" PrivateAssets="all" IncludeAssets="build; buildMultitargeting" />
44
<PackageReference Include="Microsoft.VisualStudioEng.MicroBuild.Core" PrivateAssets="all" />
5-
<PackageReference Include="Microsoft.Net.Compilers.Toolset" PrivateAssets="all" />
65
</ItemGroup>
76
</Project>

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ private static void Exec(string command, string args) {
2727
Assert.AreEqual(0, proc.ExitCode, message);
2828
}
2929

30-
public static void LocateMSBuild()
31-
{
32-
var instances = MSBuildLocator.QueryVisualStudioInstances(new() { DiscoveryTypes = DiscoveryType.DotNetSdk, WorkingDirectory = Environment.CurrentDirectory });
33-
MSBuildLocator.RegisterInstance(instances.First());
34-
}
35-
3630
[AssemblyInitialize]
3731
public static void StartAndPopulateDockerRegistry(TestContext context)
3832
{
@@ -57,7 +51,6 @@ public static void StartAndPopulateDockerRegistry(TestContext context)
5751
Exec("docker", $"pull {BaseImageSource}{BaseImage}:{BaseImageTag}");
5852
Exec("docker", $"tag {BaseImageSource}{BaseImage}:{BaseImageTag} {LocalRegistry}/{BaseImage}:{BaseImageTag}");
5953
Exec("docker", $"push {LocalRegistry}/{BaseImage}:{BaseImageTag}");
60-
LocateMSBuild();
6154
}
6255

6356
public static void ShutdownDockerRegistry()

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Diagnostics.CodeAnalysis;
2+
using System.Runtime.CompilerServices;
23
using Microsoft.Build.Evaluation;
34
using Microsoft.Build.Framework;
45
using Microsoft.Build.Locator;
@@ -35,7 +36,7 @@ public static void Cleanup()
3536
if (CombinedTargetsLocation != null) File.Delete(CombinedTargetsLocation);
3637
}
3738

38-
public static (Project, CapturingLogger?) InitProject(Dictionary<string, string> bonusProps, bool captureLogs = false)
39+
public static (Project, CapturingLogger) InitProject(Dictionary<string, string> bonusProps, bool captureLogs = false, [CallerMemberName]string projectName = "")
3940
{
4041
var props = new Dictionary<string, string>();
4142
// required parameters
@@ -44,22 +45,17 @@ public static (Project, CapturingLogger?) InitProject(Dictionary<string, string>
4445
props["_TargetFrameworkVersionWithoutV"] = "7.0";
4546
props["_NativeExecutableExtension"] = ".exe"; //TODO: windows/unix split here
4647
props["Version"] = "1.0.0"; // TODO: need to test non-compliant version strings here
47-
48+
props["NetCoreSdkVersion"] = "7.0.100"; // TODO: float this to current SDK?
4849
// test setup parameters so that we can load the props/targets/tasks
4950
props["ContainerCustomTasksAssembly"] = Path.GetFullPath(Path.Combine(".", "Microsoft.NET.Build.Containers.dll"));
5051
props["_IsTest"] = "true";
5152
var loggers = new List<ILogger>
5253
{
53-
// new Microsoft.Build.Logging.BinaryLogger() {CollectProjectImports = Microsoft.Build.Logging.BinaryLogger.ProjectImportsCollectionMode.Embed, Verbosity = LoggerVerbosity.Diagnostic, Parameters = "LogFile=blah.binlog" },
54+
new global::Microsoft.Build.Logging.BinaryLogger() {CollectProjectImports = global::Microsoft.Build.Logging.BinaryLogger.ProjectImportsCollectionMode.Embed, Verbosity = LoggerVerbosity.Diagnostic, Parameters = $"LogFile={projectName}.binlog" },
5455
new global::Microsoft.Build.Logging.ConsoleLogger(LoggerVerbosity.Detailed)
5556
};
56-
CapturingLogger? logs;
57-
if (captureLogs) {
58-
logs = new CapturingLogger();
59-
loggers.Add(logs);
60-
} else {
61-
logs = null;
62-
}
57+
CapturingLogger logs = new CapturingLogger();
58+
loggers.Add(logs);
6359

6460
var collection = new ProjectCollection(null, loggers, ToolsetDefinitionLocations.Default);
6561
foreach (var kvp in bonusProps)

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

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -22,46 +22,8 @@ public void Baseline()
2222
Assert.AreEqual("dotnet/runtime", instance.GetPropertyValue(ContainerBaseName));
2323
Assert.AreEqual("7.0", instance.GetPropertyValue(ContainerBaseTag));
2424

25-
Assert.AreEqual("dotnet/testimage", task.NewContainerImageName);
26-
CollectionAssert.AreEquivalent(new[] { "7.0", "latest" }, task.NewContainerTags);
27-
}
28-
29-
[TestMethod]
30-
public void BaseRegistriesWithNoSchemeGetHttps()
31-
{
32-
ParseContainerProperties task = new ParseContainerProperties();
33-
task.FullyQualifiedBaseImageName = "mcr.microsoft.com/dotnet/runtime:6.0";
34-
task.ContainerRegistry = "localhost:5010";
35-
task.ContainerImageName = "dotnet/testimage";
36-
task.ContainerImageTags = new[] { "5.0" };
37-
38-
Assert.IsTrue(task.Execute());
39-
Assert.AreEqual("mcr.microsoft.com", task.ParsedContainerRegistry);
40-
Assert.AreEqual("dotnet/runtime", task.ParsedContainerImage);
41-
Assert.AreEqual("6.0", task.ParsedContainerTag);
42-
43-
Assert.AreEqual("localhost:5010", task.NewContainerRegistry);
44-
Assert.AreEqual("dotnet/testimage", task.NewContainerImageName);
45-
CollectionAssert.AreEquivalent(new[] { "5.0" }, task.NewContainerTags);
46-
}
47-
48-
[TestMethod]
49-
public void UserRegistriesWithNoSchemeGetHttps()
50-
{
51-
ParseContainerProperties task = new ParseContainerProperties();
52-
task.FullyQualifiedBaseImageName = "mcr.microsoft.com/dotnet/runtime:6.0";
53-
task.ContainerRegistry = "localhost:5010";
54-
task.ContainerImageName = "dotnet/testimage";
55-
task.ContainerImageTags = new[] { "5.0" };
56-
57-
Assert.IsTrue(task.Execute());
58-
Assert.AreEqual("mcr.microsoft.com", task.ParsedContainerRegistry);
59-
Assert.AreEqual("dotnet/runtime", task.ParsedContainerImage);
60-
Assert.AreEqual("6.0", task.ParsedContainerTag);
61-
62-
Assert.AreEqual("localhost:5010", task.NewContainerRegistry);
63-
Assert.AreEqual("dotnet/testimage", task.NewContainerImageName);
64-
CollectionAssert.AreEquivalent(new[] { "5.0" }, task.NewContainerTags);
25+
Assert.AreEqual("dotnet/testimage", instance.GetPropertyValue(ContainerImageName));
26+
CollectionAssert.AreEquivalent(new[] { "7.0", "latest" }, instance.GetPropertyValue(ContainerImageTags).Split(':'));
6527
}
6628

6729
[TestMethod]
@@ -75,7 +37,7 @@ public void SpacesGetReplacedWithDashes()
7537
var instance = project.CreateProjectInstance(global::Microsoft.Build.Execution.ProjectInstanceSettings.None);
7638
Assert.IsTrue(instance.Build(new[]{ComputeContainerConfig}, null, null, out var outputs));
7739

78-
Assert.AreEqual("mcr-microsoft-com", instance.GetPropertyValue(ContainerBaseRegistry));
40+
Assert.AreEqual("mcr-microsoft-com",instance.GetPropertyValue(ContainerBaseRegistry));
7941
Assert.AreEqual("dotnet-runtime", instance.GetPropertyValue(ContainerBaseName));
8042
Assert.AreEqual("7.0", instance.GetPropertyValue(ContainerBaseTag));
8143
}
@@ -92,8 +54,8 @@ public void RegexCatchesInvalidContainerNames()
9254

9355
var instance = project.CreateProjectInstance(global::Microsoft.Build.Execution.ProjectInstanceSettings.None);
9456
Assert.IsTrue(instance.Build(new[]{ComputeContainerConfig}, new [] { logs }, null, out var outputs));
95-
Assert.IsTrue(logs.Warnings.Count > 0);
96-
Assert.AreEqual(logs.Warnings[0].Code, ErrorCodes.CONTAINER001);
57+
Assert.IsTrue(logs.Messages.Count > 0);
58+
Assert.AreEqual(ErrorCodes.CONTAINER001, logs.Messages[0].Code);
9759
}
9860

9961
[TestMethod]

packaging/build/Microsoft.NET.Build.Containers.targets

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
<!-- Note: spaces will be replaced with '-' in ContainerImageName and ContainerImageTag -->
6464
<ContainerImageName Condition="'$(ContainerImageName)' == ''">$(AssemblyName)</ContainerImageName>
6565
<!-- Only default a tag name if no tag names at all are provided -->
66-
<ContainerImageTag Condition="'$(ContainerImageTag)' == '' and '$(ContainerImageTags)' == ''">$(Version)</ContainerImageTag>
67-
<ContainerImageTag Condition="'$(AutoGenerateImageTag)' == 'true'">$([System.DateTime]::UtcNow.ToString('yyyyMMddhhmmss'))</ContainerImageTag>
66+
<ContainerImageTag Condition="'$(ContainerImageTag)' == '' and @(ContainerImageTags->Count()) == 0">$(Version)</ContainerImageTag>
67+
<ContainerImageTag Condition="'$(AutoGenerateImageTag)' == 'true' and @(ContainerImageTags->Count()) == 0">$([System.DateTime]::UtcNow.ToString('yyyyMMddhhmmss'))</ContainerImageTag>
6868
<ContainerWorkingDirectory Condition="'$(ContainerWorkingDirectory)' == ''">/app</ContainerWorkingDirectory>
6969
<!-- Could be semicolon-delimited -->
7070
</PropertyGroup>
@@ -92,7 +92,7 @@
9292
ContainerRegistry="$(ContainerRegistry)"
9393
ContainerImageName="$(ContainerImageName)"
9494
ContainerImageTag="$(ContainerImageTag)"
95-
ContainerImageTags="$(ContainerImageTags)"
95+
ContainerImageTags="@(ContainerImageTags)"
9696
ContainerEnvironmentVariables="@(ContainerEnvironmentVariable)">
9797

9898
<Output TaskParameter="ParsedContainerRegistry" PropertyName="ContainerBaseRegistry" />

0 commit comments

Comments
 (0)