Skip to content

Commit 4da3be6

Browse files
author
Eldi Cano
committed
updated test resource files
1 parent 4d1bf69 commit 4da3be6

16 files changed

Lines changed: 937 additions & 1065 deletions

File tree

Package.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ let package = Package(
2727
],
2828
dependencies: [
2929
// Dependencies declare other packages that this package depends on.
30-
// .package(url: /* package url */, from: "1.0.0"),
3130
.package(url: "https://github.com/Apodini/ApodiniTypeInformation.git", .upToNextMinor(from: "0.2.0")),
3231
.package(url: "https://github.com/kylef/PathKit.git", .exact("0.9.2")),
3332
.package(url: "https://github.com/apple/swift-argument-parser", from: "0.3.0"),

Sources/ApodiniMigrator/Migrator/Migrator.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,14 @@ public struct Migrator {
4747
private let objectJSONs: [String: JSONValue]
4848
/// Encoder configuration of the new version as calculated by the `networkingMigrator`
4949
private let encoderConfiguration: EncoderConfiguration
50-
/// A flag to indicate whether the template empty test file should be used, or the one that handles encoding and decodin of the models (not configurable, for dev only)
5150

5251
/// Initializes a new Migrator instance
5352
/// - Parameters:
5453
/// - packageName: name of the package
5554
/// - packagePath: path of the package
5655
/// - documentPath: path where the document is located
5756
/// - migrationGuide: migration guide
58-
public init(packageName: String, packagePath: String, documentPath: String, migrationGuide: MigrationGuide) throws {
57+
public init(packageName: String, packagePath: String, documentPath: String, migrationGuide: MigrationGuide = .empty) throws {
5958
self.packageName = packageName.trimmingCharacters(in: .whitespaces).without("/").upperFirst
6059
self.packagePath = packagePath.asPath
6160
document = try Document.decode(from: documentPath.asPath)
@@ -101,7 +100,7 @@ public struct Migrator {
101100
}
102101

103102
/// Triggeres the rendering of migrated content of the library and persists changes
104-
public func migrate() throws {
103+
public func run() throws {
105104
logger.info("Preparing project directories...")
106105
try directories.build()
107106

Sources/ApodiniMigrator/Templates/Package.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let package = Package(
1212
.library(name: "___PACKAGE_NAME___", targets: ["___PACKAGE_NAME___"])
1313
],
1414
dependencies: [
15-
.package(url: "https://github.com/Apodini/ApodiniMigrator.git", .branch("develop"))
15+
.package(url: "https://github.com/Apodini/ApodiniMigrator.git", .upToNextMinor(from: "0.1.0"))
1616
],
1717
targets: [
1818
.target(

Sources/ApodiniMigratorCLI/Generate.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ struct Generate: ParsableCommand {
3434
let generator = try migrator.init(
3535
packageName: packageName,
3636
packagePath: targetDirectory,
37-
documentPath: documentPath,
38-
migrationGuide: .empty
37+
documentPath: documentPath
3938
)
40-
try generator.migrate()
39+
try generator.run()
4140
logger.info("Package \(packageName) was generated successfully. You can open the package via \(packageName)/Package.swift")
4241
} catch {
4342
logger.error("Package generation failed with error: \(error)")

Sources/ApodiniMigratorCLI/Migrate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct Migrate: ParsableCommand {
4141
documentPath: documentPath,
4242
migrationGuide: migrationGuide
4343
)
44-
try migrator.migrate()
44+
try migrator.run()
4545
logger.info("Package \(packageName) was migrated successfully. You can open the package via \(packageName)/Package.swift")
4646
} catch {
4747
logger.error("Package migration failed with error: \(error)")

Sources/ApodiniMigratorCore/WebService/Endpoint.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public struct Endpoint: Value, DeltaIdentifiable {
4444
response: TypeInformation,
4545
errors: [ErrorCode]
4646
) {
47-
self.handlerName = handlerName
47+
self.handlerName = handlerName.without(strings: ">", "<", ",")
4848
var identifier = deltaIdentifier
4949
if !identifier.split(string: ".").compactMap({ Int($0) }).isEmpty {
5050
identifier = handlerName.lowerFirst

Sources/ApodiniMigratorShared/Extensions/String+Extensions.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ public extension String {
9999
with("", insteadOf: string)
100100
}
101101

102+
/// Replaces occurrencies of `strings` with an empty string
103+
func without(strings: String...) -> String {
104+
var result = self
105+
strings.forEach { result = result.without($0) }
106+
return result
107+
}
108+
102109
/// Replaces occurrencies of `target` with `replacement`
103110
func with(_ replacement: String, insteadOf target: String) -> String {
104111
replacingOccurrences(of: target, with: replacement)
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
//
2+
// This source file is part of the Apodini open source project
3+
//
4+
// SPDX-FileCopyrightText: 2019-2021 Paul Schmiedmayer and the Apodini project authors (see CONTRIBUTORS.md) <paul.schmiedmayer@tum.de>
5+
//
6+
// SPDX-License-Identifier: MIT
7+
//
8+
9+
import XCTest
10+
@testable import ApodiniMigrator
11+
12+
final class ClientLibraryGenerationMigrationTests: ApodiniMigratorXCTestCase {
13+
func testV1LibraryGeneration() throws {
14+
let document = try Documents.v1.instance() as Document
15+
let migrator = XCTAssertNoThrowWithResult(try Migrator(
16+
packageName: "QONECTIQ",
17+
packagePath: testDirectory,
18+
documentPath: Documents.v1.path.string
19+
))
20+
21+
XCTAssertNoThrow(try migrator.run())
22+
23+
let swiftFiles = try testDirectoryPath.recursiveSwiftFiles().map { $0.lastComponent }
24+
25+
let modelNames = document.allModels().map { $0.typeString + .swift }
26+
27+
modelNames.forEach { XCTAssert(swiftFiles.contains($0)) }
28+
29+
let endpointFileNames = document.endpoints.map { $0.response.nestedTypeString + "+Endpoint" + .swift }.unique()
30+
31+
endpointFileNames.forEach { XCTAssert(swiftFiles.contains($0)) }
32+
33+
XCTAssert(swiftFiles.contains("Handler.swift"))
34+
XCTAssert(swiftFiles.contains("NetworkingService.swift"))
35+
XCTAssert(swiftFiles.contains("QONECTIQTests.swift"))
36+
}
37+
38+
func testV2LibraryGeneration() throws {
39+
let document = try Documents.v2.instance() as Document
40+
let migrator = XCTAssertNoThrowWithResult(try Migrator(
41+
packageName: "QONECTIQ",
42+
packagePath: testDirectory,
43+
documentPath: Documents.v2.path.string
44+
))
45+
46+
XCTAssertNoThrow(try migrator.run())
47+
48+
let swiftFiles = try testDirectoryPath.recursiveSwiftFiles().map { $0.lastComponent }
49+
50+
let modelNames = document.allModels().map { $0.typeString + .swift }
51+
52+
modelNames.forEach { XCTAssert(swiftFiles.contains($0)) }
53+
54+
let endpointFileNames = document.endpoints.map { $0.response.nestedTypeString + "+Endpoint" + .swift }.unique()
55+
56+
endpointFileNames.forEach { XCTAssert(swiftFiles.contains($0)) }
57+
58+
XCTAssert(swiftFiles.contains("Handler.swift"))
59+
XCTAssert(swiftFiles.contains("NetworkingService.swift"))
60+
XCTAssert(swiftFiles.contains("QONECTIQTests.swift"))
61+
}
62+
63+
func testMigratorThrowIncompatibleMigrationGuide() throws {
64+
let migrationGuide = try Documents.migrationGuide.instance() as MigrationGuide
65+
XCTAssertThrows(try Migrator(packageName: "Test", packagePath: testDirectory, documentPath: Documents.v2.path.string, migrationGuide: migrationGuide))
66+
}
67+
68+
func testPackageMigration() throws {
69+
let migrationGuide = try MigrationGuide.decode(from: try Documents.migrationGuide.data())
70+
let migrator = XCTAssertNoThrowWithResult(try Migrator(
71+
packageName: "TestMigPackage",
72+
packagePath: testDirectory,
73+
documentPath: Documents.v1.path.string,
74+
migrationGuide: migrationGuide
75+
))
76+
77+
XCTAssertNoThrow(try migrator.run())
78+
XCTAssert(try testDirectoryPath.recursiveSwiftFiles().isNotEmpty)
79+
}
80+
81+
func testMigrationGuideThrowing() throws {
82+
XCTAssertThrows(try MigrationGuide.from(Path(#file), .init(.endpoints)))
83+
XCTAssertThrows(try MigrationGuide.from("", ""))
84+
}
85+
86+
func testMigrationGuideGeneration() throws {
87+
let doc1 = try Documents.v1.instance() as Document
88+
let doc2 = try Documents.v2.instance() as Document
89+
90+
let migrationGuide = MigrationGuide(for: doc1, rhs: doc2)
91+
try (testDirectoryPath + "migration_guide.yaml").write(migrationGuide.yaml)
92+
93+
let decoded = try MigrationGuide.decode(from: testDirectoryPath + "migration_guide.yaml")
94+
XCTAssertEqual(decoded, migrationGuide)
95+
XCTAssertNotEqual(decoded, .empty)
96+
}
97+
}

Tests/ApodiniMigratorTests/MigrationGuideTests.swift

Lines changed: 0 additions & 77 deletions
This file was deleted.

Tests/ApodiniMigratorTests/ProjectFilesUpdater.swift

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)