99// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010//
1111//===----------------------------------------------------------------------===//
12+ import Foundation
1213
1314@testable import Basics
1415import _InternalTestSupport
1516import Workspace
16- import XCTest
17+ import Testing
1718
18- final class AuthorizationProviderTests : XCTestCase {
19- func testNetrcAuthorizationProviders( ) throws {
19+ struct AuthorizationProviderTests {
20+ @Test
21+ func netrcAuthorizationProviders( ) throws {
2022 let observability = ObservabilitySystem . makeForTesting ( )
2123
2224 // custom .netrc file
@@ -32,19 +34,20 @@ final class AuthorizationProviderTests: XCTestCase {
3234
3335 let configuration = Workspace . Configuration. Authorization ( netrc: . custom( customPath) , keychain: . disabled)
3436 let authorizationProvider = try configuration. makeAuthorizationProvider ( fileSystem: fileSystem, observabilityScope: observability. topScope) as? CompositeAuthorizationProvider
35- let netrcProviders = authorizationProvider? . providers. compactMap { $0 as? NetrcAuthorizationProvider }
37+ let netrcProviders = try #require ( authorizationProvider? . providers. compactMap { $0 as? NetrcAuthorizationProvider } )
3638
37- XCTAssertEqual ( netrcProviders? . count, 1 )
38- XCTAssertEqual ( try netrcProviders? . first. map { try resolveSymlinks ( $0. path) } , try resolveSymlinks ( customPath) )
39+ let expectedNetrcProvider = try resolveSymlinks ( customPath)
40+ #expect( netrcProviders. count == 1 )
41+ #expect( try netrcProviders. first. map { try resolveSymlinks ( $0. path) } == expectedNetrcProvider)
3942
40- let auth = authorizationProvider? . authentication ( for: " https://mymachine.labkey.org " )
41- XCTAssertEqual ( auth
? . user
, " [email protected] " ) 42- XCTAssertEqual ( auth? . password, " custom " )
43+ let auth = try #require ( authorizationProvider? . authentication ( for: " https://mymachine.labkey.org " ) )
44+ #expect ( auth
. user
== " [email protected] " ) 45+ #expect ( auth. password == " custom " )
4346
4447 // delete it
4548 try fileSystem. removeFileTree ( customPath)
46- XCTAssertThrowsError ( try configuration . makeAuthorizationProvider ( fileSystem : fileSystem , observabilityScope : observability . topScope ) , " error expected " ) { error in
47- XCTAssertEqual ( error as? StringError , StringError ( " Did not find netrc file at \( customPath ) . " ) )
49+ #expect ( throws : StringError ( " Did not find netrc file at \( customPath ) . " ) ) {
50+ try configuration . makeAuthorizationProvider ( fileSystem : fileSystem , observabilityScope : observability . topScope )
4851 }
4952 }
5053
@@ -61,25 +64,27 @@ final class AuthorizationProviderTests: XCTestCase {
6164
6265 let configuration = Workspace . Configuration. Authorization ( netrc: . user, keychain: . disabled)
6366 let authorizationProvider = try configuration. makeAuthorizationProvider ( fileSystem: fileSystem, observabilityScope: observability. topScope) as? CompositeAuthorizationProvider
64- let netrcProviders = authorizationProvider? . providers. compactMap { $0 as? NetrcAuthorizationProvider }
67+ let netrcProviders = try #require ( authorizationProvider? . providers. compactMap { $0 as? NetrcAuthorizationProvider } )
6568
66- XCTAssertEqual ( netrcProviders? . count, 1 )
67- XCTAssertEqual ( try netrcProviders? . first. map { try resolveSymlinks ( $0. path) } , try resolveSymlinks ( userPath) )
69+ let expectedNetrcProvider = try resolveSymlinks ( userPath)
70+ #expect( netrcProviders. count == 1 )
71+ #expect( try netrcProviders. first. map { try resolveSymlinks ( $0. path) } == expectedNetrcProvider)
6872
69- let auth = authorizationProvider? . authentication ( for: " https://mymachine.labkey.org " )
70- XCTAssertEqual ( auth
? . user
, " [email protected] " ) 71- XCTAssertEqual ( auth? . password, " user " )
73+ let auth = try #require ( authorizationProvider? . authentication ( for: " https://mymachine.labkey.org " ) )
74+ #expect ( auth
. user
== " [email protected] " ) 75+ #expect ( auth. password == " user " )
7276
7377 // delete it
7478 do {
7579 try fileSystem. removeFileTree ( userPath)
7680 let authorizationProvider = try configuration. makeAuthorizationProvider ( fileSystem: fileSystem, observabilityScope: observability. topScope) as? CompositeAuthorizationProvider
77- XCTAssertNil ( authorizationProvider)
81+ #expect ( authorizationProvider == nil )
7882 }
7983 }
8084 }
8185
82- func testRegistryNetrcAuthorizationProviders( ) throws {
86+ @Test
87+ func registryNetrcAuthorizationProviders( ) throws {
8388 let observability = ObservabilitySystem . makeForTesting ( )
8489
8590 // custom .netrc file
@@ -97,17 +102,18 @@ final class AuthorizationProviderTests: XCTestCase {
97102 let configuration = Workspace . Configuration. Authorization ( netrc: . custom( customPath) , keychain: . disabled)
98103 let netrcProvider = try configuration. makeRegistryAuthorizationProvider ( fileSystem: fileSystem, observabilityScope: observability. topScope) as? NetrcAuthorizationProvider
99104
100- XCTAssertNotNil ( netrcProvider)
101- XCTAssertEqual ( try netrcProvider. map { try resolveSymlinks ( $0. path) } , try resolveSymlinks ( customPath) )
105+ let expectedNetrcProvider = try resolveSymlinks ( customPath)
106+ #expect( netrcProvider != nil )
107+ #expect( try netrcProvider. map { try resolveSymlinks ( $0. path) } == expectedNetrcProvider)
102108
103- let auth = netrcProvider? . authentication ( for: " https://mymachine.labkey.org " )
104- XCTAssertEqual ( auth
? . user
, " [email protected] " ) 105- XCTAssertEqual ( auth? . password, " custom " )
109+ let auth = try #require ( netrcProvider? . authentication ( for: " https://mymachine.labkey.org " ) )
110+ #expect ( auth
. user
== " [email protected] " ) 111+ #expect ( auth. password == " custom " )
106112
107113 // delete it
108114 try fileSystem. removeFileTree ( customPath)
109- XCTAssertThrowsError ( try configuration . makeRegistryAuthorizationProvider ( fileSystem : fileSystem , observabilityScope : observability . topScope ) , " error expected " ) { error in
110- XCTAssertEqual ( error as? StringError , StringError ( " did not find netrc file at \( customPath ) " ) )
115+ #expect ( throws : StringError ( " did not find netrc file at \( customPath ) " ) ) {
116+ try configuration . makeRegistryAuthorizationProvider ( fileSystem : fileSystem , observabilityScope : observability . topScope )
111117 }
112118 }
113119
@@ -126,22 +132,24 @@ final class AuthorizationProviderTests: XCTestCase {
126132 let configuration = Workspace . Configuration. Authorization ( netrc: . user, keychain: . disabled)
127133 let netrcProvider = try configuration. makeRegistryAuthorizationProvider ( fileSystem: fileSystem, observabilityScope: observability. topScope) as? NetrcAuthorizationProvider
128134
129- XCTAssertNotNil ( netrcProvider)
130- XCTAssertEqual ( try netrcProvider. map { try resolveSymlinks ( $0. path) } , try resolveSymlinks ( userPath) )
135+ let expectedNetrcProvider = try resolveSymlinks ( userPath)
136+ #expect( netrcProvider != nil )
137+ #expect( try netrcProvider. map { try resolveSymlinks ( $0. path) } == expectedNetrcProvider)
131138
132- let auth = netrcProvider? . authentication ( for: " https://mymachine.labkey.org " )
133- XCTAssertEqual ( auth
? . user
, " [email protected] " ) 134- XCTAssertEqual ( auth? . password, " user " )
139+ let auth = try #require ( netrcProvider? . authentication ( for: " https://mymachine.labkey.org " ) )
140+ #expect ( auth
. user
== " [email protected] " ) 141+ #expect ( auth. password == " user " )
135142
136143 // delete it
137144 do {
138145 try fileSystem. removeFileTree ( userPath)
139146 let authorizationProvider = try configuration. makeRegistryAuthorizationProvider ( fileSystem: fileSystem, observabilityScope: observability. topScope) as? NetrcAuthorizationProvider
140147 // Even if user .netrc file doesn't exist, the provider will be non-nil but contain no data.
141- XCTAssertNotNil ( authorizationProvider)
142- XCTAssertEqual ( try authorizationProvider. map { try resolveSymlinks ( $0. path) } , try resolveSymlinks ( userPath) )
148+ let expectedAuthorizationProvider = try resolveSymlinks ( userPath)
149+ #expect( authorizationProvider != nil )
150+ #expect( try authorizationProvider. map { try resolveSymlinks ( $0. path) } == expectedAuthorizationProvider)
143151
144- XCTAssertTrue ( authorizationProvider!. machines. isEmpty)
152+ #expect ( authorizationProvider!. machines. isEmpty)
145153 }
146154 }
147155 }
0 commit comments