Skip to content

Commit b148c3c

Browse files
Support tags passed into ParseContainerProperties (#239)
A logic error caused ParseContainerProperties to fail if multi-valued tags were passed into ContainerImageTags. A test error made that non- obvious. Fix the tests to use CollectionAssert methods, and invert the check on TryValidateTags so that when the tags are valid we respect them. Fixes #236.
1 parent 554a385 commit b148c3c

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

Microsoft.NET.Build.Containers/ParseContainerProperties.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public override bool Execute()
118118
Log.LogError(null, "CONTAINER003", "Container.InvalidTag", null, 0, 0, 0, 0, $"Invalid {nameof(ContainerImageTag)} provided: {{0}}. Image tags must be alphanumeric, underscore, hyphen, or period.", ContainerImageTag);
119119
}
120120
}
121-
else if (ContainerImageTags.Length != 0 && !TryValidateTags(ContainerImageTags, out var valids, out var invalids))
121+
else if (ContainerImageTags.Length != 0 && TryValidateTags(ContainerImageTags, out var valids, out var invalids))
122122
{
123123
validTags = valids;
124124
if (invalids.Any())

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ public void Baseline()
1515
task.FullyQualifiedBaseImageName = "mcr.microsoft.com/dotnet/runtime:6.0";
1616
task.ContainerRegistry = "localhost:5010";
1717
task.ContainerImageName = "dotnet/testimage";
18-
task.ContainerImageTags = new[] { "5.0" };
18+
task.ContainerImageTags = new[] { "5.0", "latest" };
1919

2020
Assert.IsTrue(task.Execute());
2121
Assert.AreEqual("mcr.microsoft.com", task.ParsedContainerRegistry);
2222
Assert.AreEqual("dotnet/runtime", task.ParsedContainerImage);
2323
Assert.AreEqual("6.0", task.ParsedContainerTag);
2424

2525
Assert.AreEqual("dotnet/testimage", task.NewContainerImageName);
26-
new[] { "5.0" }.SequenceEqual(task.NewContainerTags);
26+
CollectionAssert.AreEquivalent(new[] { "5.0", "latest" }, task.NewContainerTags);
2727
}
2828

2929
[TestMethod]
@@ -42,7 +42,7 @@ public void BaseRegistriesWithNoSchemeGetHttps()
4242

4343
Assert.AreEqual("localhost:5010", task.NewContainerRegistry);
4444
Assert.AreEqual("dotnet/testimage", task.NewContainerImageName);
45-
new[] { "5.0" }.SequenceEqual(task.NewContainerTags);
45+
CollectionAssert.AreEquivalent(new[] { "5.0" }, task.NewContainerTags);
4646
}
4747

4848
[TestMethod]
@@ -61,7 +61,7 @@ public void UserRegistriesWithNoSchemeGetHttps()
6161

6262
Assert.AreEqual("localhost:5010", task.NewContainerRegistry);
6363
Assert.AreEqual("dotnet/testimage", task.NewContainerImageName);
64-
new[] { "5.0" }.SequenceEqual(task.NewContainerTags);
64+
CollectionAssert.AreEquivalent(new[] { "5.0" }, task.NewContainerTags);
6565
}
6666

6767
[TestMethod]
@@ -81,7 +81,7 @@ public void SpacesGetReplacedWithDashes()
8181
Assert.AreEqual("6-0", task.ParsedContainerTag);
8282

8383
Assert.AreEqual("dotnet/testimage", task.NewContainerImageName);
84-
new[] { "5.0" }.SequenceEqual(task.NewContainerTags);
84+
CollectionAssert.AreEquivalent(new[] { "5.0" }, task.NewContainerTags);
8585
}
8686

8787
[TestMethod]

0 commit comments

Comments
 (0)