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
@@ -34,17 +36,21 @@ final class AuthorizationProviderTests: XCTestCase {
34
36
let authorizationProvider = try configuration. makeAuthorizationProvider ( fileSystem: fileSystem, observabilityScope: observability. topScope) as? CompositeAuthorizationProvider
35
37
let netrcProviders = 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
43
let auth = authorizationProvider? . authentication ( for: " https://mymachine.labkey.org " )
41
- XCTAssertEqual ( auth
? . user
, " [email protected] " )
42
- XCTAssertEqual ( auth? . password, " custom " )
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 {
50
+ try configuration. makeAuthorizationProvider ( fileSystem: fileSystem, observabilityScope: observability. topScope)
51
+ } throws: { error in
52
+ let error = try #require( error as? StringError , " Error is wrong type " )
53
+ return error == StringError ( " Did not find netrc file at \( customPath) . " )
48
54
}
49
55
}
50
56
@@ -63,23 +69,25 @@ final class AuthorizationProviderTests: XCTestCase {
63
69
let authorizationProvider = try configuration. makeAuthorizationProvider ( fileSystem: fileSystem, observabilityScope: observability. topScope) as? CompositeAuthorizationProvider
64
70
let netrcProviders = authorizationProvider? . providers. compactMap { $0 as? NetrcAuthorizationProvider }
65
71
66
- XCTAssertEqual ( netrcProviders? . count, 1 )
67
- XCTAssertEqual ( try netrcProviders? . first. map { try resolveSymlinks ( $0. path) } , try resolveSymlinks ( userPath) )
72
+ let expectedNetrcProvider = try resolveSymlinks ( userPath)
73
+ #expect( netrcProviders? . count == 1 )
74
+ #expect( try netrcProviders? . first. map { try resolveSymlinks ( $0. path) } == expectedNetrcProvider)
68
75
69
76
let auth = authorizationProvider? . authentication ( for: " https://mymachine.labkey.org " )
70
- XCTAssertEqual ( auth
? . user
, " [email protected] " )
71
- XCTAssertEqual ( auth? . password, " user " )
77
+ #expect ( auth
? . user
== " [email protected] " )
78
+ #expect ( auth? . password == " user " )
72
79
73
80
// delete it
74
81
do {
75
82
try fileSystem. removeFileTree ( userPath)
76
83
let authorizationProvider = try configuration. makeAuthorizationProvider ( fileSystem: fileSystem, observabilityScope: observability. topScope) as? CompositeAuthorizationProvider
77
- XCTAssertNil ( authorizationProvider)
84
+ #expect ( authorizationProvider == nil )
78
85
}
79
86
}
80
87
}
81
88
82
- func testRegistryNetrcAuthorizationProviders( ) throws {
89
+ @Test
90
+ func registryNetrcAuthorizationProviders( ) throws {
83
91
let observability = ObservabilitySystem . makeForTesting ( )
84
92
85
93
// custom .netrc file
@@ -97,17 +105,21 @@ final class AuthorizationProviderTests: XCTestCase {
97
105
let configuration = Workspace . Configuration. Authorization ( netrc: . custom( customPath) , keychain: . disabled)
98
106
let netrcProvider = try configuration. makeRegistryAuthorizationProvider ( fileSystem: fileSystem, observabilityScope: observability. topScope) as? NetrcAuthorizationProvider
99
107
100
- XCTAssertNotNil ( netrcProvider)
101
- XCTAssertEqual ( try netrcProvider. map { try resolveSymlinks ( $0. path) } , try resolveSymlinks ( customPath) )
108
+ let expectedNetrcProvider = try resolveSymlinks ( customPath)
109
+ #expect( netrcProvider != nil )
110
+ #expect( try netrcProvider. map { try resolveSymlinks ( $0. path) } == expectedNetrcProvider)
102
111
103
112
let auth = netrcProvider? . authentication ( for: " https://mymachine.labkey.org " )
104
- XCTAssertEqual ( auth
? . user
, " [email protected] " )
105
- XCTAssertEqual ( auth? . password, " custom " )
113
+ #expect ( auth
? . user
== " [email protected] " )
114
+ #expect ( auth? . password == " custom " )
106
115
107
116
// delete it
108
117
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) " ) )
118
+ #expect {
119
+ try configuration. makeRegistryAuthorizationProvider ( fileSystem: fileSystem, observabilityScope: observability. topScope)
120
+ } throws: { error in
121
+ let error = try #require( error as? StringError , " Error is wrong type " )
122
+ return error == StringError ( " did not find netrc file at \( customPath) " )
111
123
}
112
124
}
113
125
@@ -126,22 +138,24 @@ final class AuthorizationProviderTests: XCTestCase {
126
138
let configuration = Workspace . Configuration. Authorization ( netrc: . user, keychain: . disabled)
127
139
let netrcProvider = try configuration. makeRegistryAuthorizationProvider ( fileSystem: fileSystem, observabilityScope: observability. topScope) as? NetrcAuthorizationProvider
128
140
129
- XCTAssertNotNil ( netrcProvider)
130
- XCTAssertEqual ( try netrcProvider. map { try resolveSymlinks ( $0. path) } , try resolveSymlinks ( userPath) )
141
+ let expectedNetrcProvider = try resolveSymlinks ( userPath)
142
+ #expect( netrcProvider != nil )
143
+ #expect( try netrcProvider. map { try resolveSymlinks ( $0. path) } == expectedNetrcProvider)
131
144
132
145
let auth = netrcProvider? . authentication ( for: " https://mymachine.labkey.org " )
133
- XCTAssertEqual ( auth
? . user
, " [email protected] " )
134
- XCTAssertEqual ( auth? . password, " user " )
146
+ #expect ( auth
? . user
== " [email protected] " )
147
+ #expect ( auth? . password == " user " )
135
148
136
149
// delete it
137
150
do {
138
151
try fileSystem. removeFileTree ( userPath)
139
152
let authorizationProvider = try configuration. makeRegistryAuthorizationProvider ( fileSystem: fileSystem, observabilityScope: observability. topScope) as? NetrcAuthorizationProvider
140
153
// 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) )
154
+ let expectedAuthorizationProvider = try resolveSymlinks ( userPath)
155
+ #expect( authorizationProvider != nil )
156
+ #expect( try authorizationProvider. map { try resolveSymlinks ( $0. path) } == expectedAuthorizationProvider)
143
157
144
- XCTAssertTrue ( authorizationProvider!. machines. isEmpty)
158
+ #expect ( authorizationProvider!. machines. isEmpty)
145
159
}
146
160
}
147
161
}
0 commit comments