Skip to content

Commit eae9cdd

Browse files
authored
Add testing trait to indicate a CI environment that has restricted network access (#8406)
In some testing environments, network access is limited not allowing for hosts to access the public internet. Add a testing condition trait that can be used to determine if the test has unrestricted network access. Environments that have this constraint can set `SWIFTCI_RESTRICTED_NETWORK_ACCESS=1` to affect this condition.
1 parent 00dc44a commit eae9cdd

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

IntegrationTests/Sources/IntegrationTestSupport/SkippedTestSupport.swift

+7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ extension Trait where Self == Testing.ConditionTrait {
4040
}
4141
}
4242

43+
/// Skip test if the test environment has a restricted network access, i.e. cannot get to internet.
44+
public static func requireUnrestrictedNetworkAccess(_ comment: Comment? = nil) -> Self {
45+
disabled(comment ?? "CI Environment has restricted network access") {
46+
ProcessInfo.processInfo.environment["SWIFTCI_RESTRICTED_NETWORK_ACCESS"] != nil
47+
}
48+
}
49+
4350
/// Skip test if built by XCode.
4451
public static func skipIfXcodeBuilt() -> Self {
4552
disabled("Tests built by Xcode") {

IntegrationTests/Tests/IntegrationTests/BasicTests.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ private struct BasicTests {
2222
@Test(
2323
.skipSwiftCISelfHosted(
2424
"These packages don't use the latest runtime library, which doesn't work with self-hosted builds."
25-
)
25+
),
26+
.requireUnrestrictedNetworkAccess("Test requires access to https://github.com")
2627
)
2728
func testExamplePackageDealer() throws {
2829
try withTemporaryDirectory { tempDir in

0 commit comments

Comments
 (0)