Skip to content

Commit ec08871

Browse files
authored
tests: Convert ReferenceTests to swift-testing parameterised tests (#47)
Motivation ---------- `ImageReference.testReferences` tests is a table-driven test which iterates over a list of test cases. Under `XCTest` it was implemented as a single test containing a loop, but with `swift-testing` the loop can be moved outside the test. This makes it easier to see that multiple test cases are being run and to diagnose problems. Modifications ------------- `ImageReference.testReferences` now uses `@Test(arguments: ...)` to iterate over the existing test list. Result ------ Test reports are more detailed. Test Plan --------- All tests continue to pass.
1 parent 9e707ef commit ec08871

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

Sources/ContainerRegistry/ImageReference.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func splitName(_ name: String) throws -> (String, String) {
4848
}
4949

5050
/// ImageReference points to an image stored on a container registry
51-
public struct ImageReference: Equatable, CustomStringConvertible, CustomDebugStringConvertible {
51+
public struct ImageReference: Sendable, Equatable, CustomStringConvertible, CustomDebugStringConvertible {
5252
/// The registry which contains this image
5353
public var registry: String
5454
/// The repository which contains this image

Tests/ContainerRegistryTests/ImageReferenceTests.swift

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,13 @@
1515
@testable import ContainerRegistry
1616
import Testing
1717

18-
struct ReferenceTest {
19-
var reference: String
20-
var registry: String
21-
var repository: String
22-
}
23-
24-
struct ReferenceTestCase {
18+
struct ReferenceTestCase: Sendable {
2519
var reference: String
2620
var expected: ImageReference?
2721
}
2822

2923
struct ReferenceTests {
30-
let tests = [
24+
static let tests = [
3125
// A reference which does not contain a '/' is always interpreted as a repository name
3226
// in the default registry.
3327
ReferenceTestCase(
@@ -106,14 +100,12 @@ struct ReferenceTests {
106100
),
107101
]
108102

109-
@Test func testReferences() throws {
110-
for test in tests {
111-
let parsed = try! ImageReference(fromString: test.reference, defaultRegistry: "default")
112-
#expect(
113-
parsed == test.expected,
114-
"\(String(reflecting: parsed)) is not equal to \(String(reflecting: test.expected))"
115-
)
116-
}
103+
@Test(arguments: tests) func testReferences(test: ReferenceTestCase) throws {
104+
let parsed = try! ImageReference(fromString: test.reference, defaultRegistry: "default")
105+
#expect(
106+
parsed == test.expected,
107+
"\(String(reflecting: parsed)) is not equal to \(String(reflecting: test.expected))"
108+
)
117109
}
118110

119111
@Test func testLibraryReferences() throws {

0 commit comments

Comments
 (0)