9
9
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10
10
//
11
11
//===----------------------------------------------------------------------===//
12
+ import Foundation
12
13
13
14
@testable import Basics
14
15
import _InternalTestSupport
15
16
import Workspace
16
- import XCTest
17
+ import Testing
17
18
18
- final class AuthorizationProviderTests : XCTestCase {
19
- func testNetrcAuthorizationProviders( ) throws {
19
+ struct AuthorizationProviderTests {
20
+ @Test
21
+ func netrcAuthorizationProviders( ) throws {
20
22
let observability = ObservabilitySystem . makeForTesting ( )
21
23
22
24
// custom .netrc file
@@ -32,19 +34,20 @@ final class AuthorizationProviderTests: XCTestCase {
32
34
33
35
let configuration = Workspace . Configuration. Authorization ( netrc: . custom( customPath) , keychain: . disabled)
34
36
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 } )
36
38
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)
39
42
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 " )
43
46
44
47
// delete it
45
48
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 )
48
51
}
49
52
}
50
53
@@ -61,25 +64,27 @@ final class AuthorizationProviderTests: XCTestCase {
61
64
62
65
let configuration = Workspace . Configuration. Authorization ( netrc: . user, keychain: . disabled)
63
66
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 } )
65
68
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)
68
72
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 " )
72
76
73
77
// delete it
74
78
do {
75
79
try fileSystem. removeFileTree ( userPath)
76
80
let authorizationProvider = try configuration. makeAuthorizationProvider ( fileSystem: fileSystem, observabilityScope: observability. topScope) as? CompositeAuthorizationProvider
77
- XCTAssertNil ( authorizationProvider)
81
+ #expect ( authorizationProvider == nil )
78
82
}
79
83
}
80
84
}
81
85
82
- func testRegistryNetrcAuthorizationProviders( ) throws {
86
+ @Test
87
+ func registryNetrcAuthorizationProviders( ) throws {
83
88
let observability = ObservabilitySystem . makeForTesting ( )
84
89
85
90
// custom .netrc file
@@ -97,17 +102,18 @@ final class AuthorizationProviderTests: XCTestCase {
97
102
let configuration = Workspace . Configuration. Authorization ( netrc: . custom( customPath) , keychain: . disabled)
98
103
let netrcProvider = try configuration. makeRegistryAuthorizationProvider ( fileSystem: fileSystem, observabilityScope: observability. topScope) as? NetrcAuthorizationProvider
99
104
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)
102
108
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 " )
106
112
107
113
// delete it
108
114
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 )
111
117
}
112
118
}
113
119
@@ -126,22 +132,24 @@ final class AuthorizationProviderTests: XCTestCase {
126
132
let configuration = Workspace . Configuration. Authorization ( netrc: . user, keychain: . disabled)
127
133
let netrcProvider = try configuration. makeRegistryAuthorizationProvider ( fileSystem: fileSystem, observabilityScope: observability. topScope) as? NetrcAuthorizationProvider
128
134
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)
131
138
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 " )
135
142
136
143
// delete it
137
144
do {
138
145
try fileSystem. removeFileTree ( userPath)
139
146
let authorizationProvider = try configuration. makeRegistryAuthorizationProvider ( fileSystem: fileSystem, observabilityScope: observability. topScope) as? NetrcAuthorizationProvider
140
147
// 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)
143
151
144
- XCTAssertTrue ( authorizationProvider!. machines. isEmpty)
152
+ #expect ( authorizationProvider!. machines. isEmpty)
145
153
}
146
154
}
147
155
}
0 commit comments