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