@@ -16,6 +16,12 @@ import XCTest
16
16
17
17
@testable import SwiftSDKGenerator
18
18
19
+ #if canImport(FoundationEssentials)
20
+ import FoundationEssentials
21
+ #else
22
+ import Foundation
23
+ #endif
24
+
19
25
final class SwiftSDKGeneratorMetadataTests : XCTestCase {
20
26
let logger = Logger ( label: " SwiftSDKGeneratorMetadataTests " )
21
27
@@ -54,19 +60,44 @@ final class SwiftSDKGeneratorMetadataTests: XCTestCase {
54
60
55
61
// Make sure the file exists
56
62
let sdkSettingsFile = sdkDirPath. appending ( " SDKSettings.json " )
57
- let fileExists = await sdk. doesFileExist ( at: sdkSettingsFile)
63
+ var fileExists = await sdk. doesFileExist ( at: sdkSettingsFile)
58
64
XCTAssertTrue ( fileExists)
59
65
60
66
// Read back file, make sure it contains the expected data
61
- let data = String ( data: try await sdk. readFile ( at: sdkSettingsFile) , encoding: . utf8)
62
- XCTAssertNotNil ( data )
63
- XCTAssertTrue ( data! . contains ( testCase. bundleVersion) )
64
- XCTAssertTrue ( data! . contains ( " ( \( testCase. targetTriple. archName) ) " ) )
65
- XCTAssertTrue ( data! . contains ( linuxDistribution. description) )
66
- XCTAssertTrue ( data! . contains ( testCase. expectedCanonicalName) )
67
+ let maybeString = String ( data: try await sdk. readFile ( at: sdkSettingsFile) , encoding: . utf8)
68
+ let string = try XCTUnwrap ( maybeString )
69
+ XCTAssertTrue ( string . contains ( testCase. bundleVersion) )
70
+ XCTAssertTrue ( string . contains ( " ( \( testCase. targetTriple. archName) ) " ) )
71
+ XCTAssertTrue ( string . contains ( linuxDistribution. description) )
72
+ XCTAssertTrue ( string . contains ( testCase. expectedCanonicalName) )
67
73
68
74
// Cleanup
69
75
try await sdk. removeFile ( at: sdkSettingsFile)
76
+
77
+ try await sdk. createDirectoryIfNeeded ( at: sdk. pathsConfiguration. artifactBundlePath)
78
+
79
+ // Generate bundle metadata
80
+ try await sdk. generateArtifactBundleManifest (
81
+ hostTriples: [ sdk. targetTriple] ,
82
+ artifacts: [ " foo " : sdk. pathsConfiguration. artifactBundlePath. appending ( " bar.json " ) ]
83
+ )
84
+
85
+ // Make sure the file exists
86
+ let archiveMetadataFile = await sdk. pathsConfiguration. artifactBundlePath. appending ( " info.json " )
87
+ fileExists = await sdk. doesFileExist ( at: archiveMetadataFile)
88
+ XCTAssertTrue ( fileExists)
89
+
90
+ // Read back file, make sure it contains the expected data
91
+ let data = try await sdk. readFile ( at: archiveMetadataFile)
92
+ let decodedMetadata = try JSONDecoder ( ) . decode ( ArtifactsArchiveMetadata . self, from: data)
93
+ XCTAssertEqual ( decodedMetadata. artifacts. count, 1 )
94
+ for (id, artifact) in decodedMetadata. artifacts {
95
+ XCTAssertEqual ( id, " foo " )
96
+ XCTAssertEqual ( artifact. variants, [ . init( path: " bar.json " , supportedTriples: [ testCase. targetTriple. triple] ) ] )
97
+ }
98
+
99
+ // Cleanup
100
+ try await sdk. removeFile ( at: archiveMetadataFile)
70
101
}
71
102
}
72
103
}
0 commit comments