@@ -17,51 +17,90 @@ import XCTest
17
17
18
18
import struct TSCBasic. AbsolutePath
19
19
import struct TSCBasic. ByteString
20
+ import protocol TSCBasic. FileSystem
20
21
import class TSCBasic. InMemoryFileSystem
21
22
22
23
private let testArtifactID = " test-artifact "
23
24
24
- private let infoJSON = ByteString ( stringLiteral: """
25
- {
26
- " artifacts " : {
27
- " \( testArtifactID) " : {
28
- " type " : " swiftSDK " ,
29
- " version " : " 0.0.1 " ,
30
- " variants " : [
31
- {
32
- " path " : " \( testArtifactID) /aarch64-unknown-linux " ,
33
- " supportedTriples " : [
34
- " arm64-apple-macosx13.0 "
35
- ]
36
- }
37
- ]
25
+ private func generateInfoJSON( artifacts: [ MockArtifact ] ) -> String {
26
+ """
27
+ {
28
+ " artifacts " : {
29
+ \( artifacts. map {
30
+ """
31
+ " \( $0. id) " : {
32
+ " type " : " swiftSDK " ,
33
+ " version " : " 0.0.1 " ,
34
+ " variants " : [
35
+ {
36
+ " path " : " \( $0. id) /aarch64-unknown-linux " ,
37
+ " supportedTriples " : \( $0. supportedTriples. map ( \. tripleString) )
38
+ }
39
+ ]
40
+ }
41
+ """
42
+ } . joined ( separator: " , \n " )
43
+ )
44
+ },
45
+ " schemaVersion " : " 1.0 "
46
+ }
47
+ """
48
+ }
49
+
50
+ private struct MockBundle {
51
+ let name : String
52
+ let path : String
53
+ let artifacts : [ MockArtifact ]
54
+ }
55
+
56
+ private struct MockArtifact {
57
+ let id : String
58
+ let supportedTriples : [ Triple ]
59
+ }
60
+
61
+ private func generateTestFileSystem( bundleArtifacts: [ MockArtifact ] ) throws -> ( some FileSystem , [ MockBundle ] , AbsolutePath ) {
62
+ let bundles = bundleArtifacts. enumerated ( ) . map { ( i, artifacts) in
63
+ let bundleName = " test \( i) .artifactbundle "
64
+ return MockBundle ( name: " test \( i) .artifactbundle " , path: " / \( bundleName) " , artifacts: [ artifacts] )
38
65
}
39
- },
40
- " schemaVersion " : " 1.0 "
66
+
67
+ let fileSystem = InMemoryFileSystem (
68
+ files: Dictionary ( uniqueKeysWithValues: bundles. map {
69
+ (
70
+ " \( $0. path) /info.json " ,
71
+ ByteString (
72
+ encodingAsUTF8: generateInfoJSON ( artifacts: $0. artifacts)
73
+ )
74
+ )
75
+ } )
76
+ )
77
+
78
+ let swiftSDKsDirectory = try AbsolutePath ( validating: " /sdks " )
79
+ try fileSystem. createDirectory ( fileSystem. tempDirectory)
80
+ try fileSystem. createDirectory ( swiftSDKsDirectory)
81
+
82
+ return ( fileSystem, bundles, swiftSDKsDirectory)
41
83
}
42
- """ )
84
+
85
+ private let arm64Triple = try ! Triple ( " arm64-apple-macosx13.0 " )
86
+ let i686Triple = try ! Triple ( " i686-apple-macosx13.0 " )
43
87
44
88
final class SwiftSDKBundleTests : XCTestCase {
45
89
func testInstall( ) async throws {
46
90
let system = ObservabilitySystem . makeForTesting ( )
47
91
48
- let bundleName1 = " test1.artifactbundle "
49
- let bundleName2 = " test2.artifactbundle "
50
- let bundlePath1 = " / \( bundleName1) "
51
- let bundlePath2 = " / \( bundleName2) "
52
- let destinationsDirectory = try AbsolutePath ( validating: " /destinations " )
53
- let fileSystem = InMemoryFileSystem ( files: [
54
- " \( bundlePath1) /info.json " : infoJSON,
55
- " \( bundlePath2) /info.json " : infoJSON,
56
- ] )
57
- try fileSystem. createDirectory ( fileSystem. tempDirectory)
58
- try fileSystem. createDirectory ( destinationsDirectory)
92
+ let ( fileSystem, bundles, swiftSDKsDirectory) = try generateTestFileSystem (
93
+ bundleArtifacts: [
94
+ . init( id: testArtifactID, supportedTriples: [ arm64Triple] ) ,
95
+ . init( id: testArtifactID, supportedTriples: [ arm64Triple] )
96
+ ]
97
+ )
59
98
60
99
let archiver = MockArchiver ( )
61
100
62
101
try SwiftSDKBundle . install (
63
- bundlePathOrURL: bundlePath1 ,
64
- destinationsDirectory : destinationsDirectory ,
102
+ bundlePathOrURL: bundles [ 0 ] . path ,
103
+ swiftSDKsDirectory : swiftSDKsDirectory ,
65
104
fileSystem,
66
105
archiver,
67
106
system. topScope
@@ -70,8 +109,8 @@ final class SwiftSDKBundleTests: XCTestCase {
70
109
let invalidPath = " foobar "
71
110
do {
72
111
try SwiftSDKBundle . install (
73
- bundlePathOrURL: invalidPath ,
74
- destinationsDirectory : destinationsDirectory ,
112
+ bundlePathOrURL: " foobar " ,
113
+ swiftSDKsDirectory : swiftSDKsDirectory ,
75
114
fileSystem,
76
115
archiver,
77
116
system. topScope
@@ -84,7 +123,6 @@ final class SwiftSDKBundleTests: XCTestCase {
84
123
return
85
124
}
86
125
87
- print ( error)
88
126
switch error {
89
127
case . invalidBundleName( let bundleName) :
90
128
XCTAssertEqual ( bundleName, invalidPath)
@@ -95,8 +133,8 @@ final class SwiftSDKBundleTests: XCTestCase {
95
133
96
134
do {
97
135
try SwiftSDKBundle . install (
98
- bundlePathOrURL: bundlePath1 ,
99
- destinationsDirectory : destinationsDirectory ,
136
+ bundlePathOrURL: bundles [ 0 ] . path ,
137
+ swiftSDKsDirectory : swiftSDKsDirectory ,
100
138
fileSystem,
101
139
archiver,
102
140
system. topScope
@@ -111,16 +149,16 @@ final class SwiftSDKBundleTests: XCTestCase {
111
149
112
150
switch error {
113
151
case . destinationBundleAlreadyInstalled( let installedBundleName) :
114
- XCTAssertEqual ( bundleName1 , installedBundleName)
152
+ XCTAssertEqual ( bundles [ 0 ] . name , installedBundleName)
115
153
default :
116
154
XCTFail ( " Unexpected error value " )
117
155
}
118
156
}
119
157
120
158
do {
121
159
try SwiftSDKBundle . install (
122
- bundlePathOrURL: bundlePath2 ,
123
- destinationsDirectory : destinationsDirectory ,
160
+ bundlePathOrURL: bundles [ 1 ] . path ,
161
+ swiftSDKsDirectory : swiftSDKsDirectory ,
124
162
fileSystem,
125
163
archiver,
126
164
system. topScope
@@ -135,12 +173,40 @@ final class SwiftSDKBundleTests: XCTestCase {
135
173
136
174
switch error {
137
175
case . destinationArtifactAlreadyInstalled( let installedBundleName, let newBundleName, let artifactID) :
138
- XCTAssertEqual ( bundleName1 , installedBundleName)
139
- XCTAssertEqual ( bundleName2 , newBundleName)
176
+ XCTAssertEqual ( bundles [ 0 ] . name , installedBundleName)
177
+ XCTAssertEqual ( bundles [ 1 ] . name , newBundleName)
140
178
XCTAssertEqual ( artifactID, testArtifactID)
141
179
default :
142
180
XCTFail ( " Unexpected error value " )
143
181
}
144
182
}
145
183
}
184
+
185
+ func testList( ) async throws {
186
+ let ( fileSystem, bundles, swiftSDKsDirectory) = try generateTestFileSystem (
187
+ bundleArtifacts: [
188
+ . init( id: " \( testArtifactID) 1 " , supportedTriples: [ arm64Triple] ) ,
189
+ . init( id: " \( testArtifactID) 2 " , supportedTriples: [ i686Triple] )
190
+ ]
191
+ )
192
+ let system = ObservabilitySystem . makeForTesting ( )
193
+
194
+ for bundle in bundles {
195
+ try SwiftSDKBundle . install (
196
+ bundlePathOrURL: bundle. path,
197
+ swiftSDKsDirectory: swiftSDKsDirectory,
198
+ fileSystem,
199
+ MockArchiver ( ) ,
200
+ system. topScope
201
+ )
202
+ }
203
+
204
+ let validBundles = try SwiftSDKBundle . getAllValidBundles (
205
+ swiftSDKsDirectory: swiftSDKsDirectory,
206
+ fileSystem: fileSystem,
207
+ observabilityScope: system. topScope
208
+ )
209
+
210
+ XCTAssertEqual ( validBundles. count, bundles. count)
211
+ }
146
212
}
0 commit comments