Removed the "app", "appTests", and "package" cases from the File enumeration in the library target.

This commit is contained in:
Javier Cicchelli 2025-02-05 00:16:09 +01:00
parent 91762b18cd
commit af73e6d1a2
6 changed files with 67 additions and 122 deletions

View File

@ -1,20 +0,0 @@
import AppLibrary
import ArgumentParser
@main
struct App: AsyncParsableCommand {
// MARK: Properties
@OptionGroup var options: Options
// MARK: Functions
mutating func run() async throws {
let builder = AppBuilder(name: "App")
let app = try await builder(options)
try await app.runService()
}
}

View File

@ -1,45 +0,0 @@
// swift-tools-version:6.0
import PackageDescription
let package = Package(
name: "App",
platforms: [
.macOS(.v14)
],
products: [
.executable(name: "App", targets: ["App"]),
.library(name: "AppLibrary", targets: ["AppLibrary"])
],
dependencies: [
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0"),
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.3.0")
],
targets: [
.executableTarget(
name: "App",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "Hummingbird", package: "hummingbird"),
.target(name: "AppLibrary")
],
path: "App"
),
.target(
name: "AppLibrary",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "Hummingbird", package: "hummingbird")
],
path: "Library"
),
.testTarget(
name: "AppTests",
dependencies: [
.product(name: "HummingbirdTesting", package: "hummingbird"),
.target(name: "AppLibrary")
],
path: "Test"
)
]
)

View File

@ -1,33 +0,0 @@
import AppLibrary
import Hummingbird
import HummingbirdTesting
import Testing
struct AppTests {
// MARK: Properties
private let arguments = TestArguments()
private let builder = AppBuilder(name: "App")
// MARK: Route tests
@Test(arguments: ["/"])
func routes(_ uri: String) async throws {
let app = try await builder(arguments)
try await app.test(.router) { client in
try await client.execute(uri: uri, method: .get) { response in
#expect(response.status == .ok)
#expect(response.body == .empty)
}
}
}
}
// MARK: ByteBuffer+Constants
private extension ByteBuffer {
static let empty = ByteBuffer(string: "")
}

View File

@ -1,16 +1,13 @@
enum File: String { enum File: String {
case app = "App"
case appArguments = "AppArguments" case appArguments = "AppArguments"
case appBuilder = "AppBuilder" case appBuilder = "AppBuilder"
case appOptions = "AppOptions" case appOptions = "AppOptions"
case appTests = "AppTests"
case dockerFile = "DockerFile" case dockerFile = "DockerFile"
case dockerIgnore = "DockerIgnore" case dockerIgnore = "DockerIgnore"
case environment = "Environment" case environment = "Environment"
case gitIgnore = "GitIgnore" case gitIgnore = "GitIgnore"
case license = "License" case license = "License"
case loggerLevel = "LoggerLevel" case loggerLevel = "LoggerLevel"
case package = "Package"
case readme = "Readme" case readme = "Readme"
case testArguments = "TestArguments" case testArguments = "TestArguments"
@ -24,11 +21,9 @@ extension File {
var fileName: String { var fileName: String {
switch self { switch self {
case .app: "App.swift"
case .appArguments: "AppArguments.swift" case .appArguments: "AppArguments.swift"
case .appBuilder: "AppBuilder.swift" case .appBuilder: "AppBuilder.swift"
case .appOptions: "AppOptions.swift" case .appOptions: "AppOptions.swift"
case .appTests: "AppTests.swift"
case .dockerFile: "Dockerfile" case .dockerFile: "Dockerfile"
case .dockerIgnore: ".dockerignore" case .dockerIgnore: ".dockerignore"
case .environment: "Environment+Properties.swift" case .environment: "Environment+Properties.swift"
@ -36,7 +31,6 @@ extension File {
case .license: "LICENSE" case .license: "LICENSE"
case .loggerLevel: "LoggerLevel+Conformances.swift" case .loggerLevel: "LoggerLevel+Conformances.swift"
case .readme: "README.md" case .readme: "README.md"
case .package: "Package.swift"
case .testArguments: "TestArguments.swift" case .testArguments: "TestArguments.swift"
} }
} }
@ -47,9 +41,8 @@ extension File {
var folder: Folder { var folder: Folder {
switch self { switch self {
case .app, .appOptions: .app case .appOptions: .app
case .appArguments, .appBuilder: .libraryPublic case .appArguments, .appBuilder: .libraryPublic
case .appTests: .testCasesPublic
case .environment, .loggerLevel: .libraryInternal case .environment, .loggerLevel: .libraryInternal
case .testArguments: .testHelpers case .testArguments: .testHelpers
default: .root default: .root
@ -60,9 +53,9 @@ extension File {
let basePath = "Resources/Files/Sources" let basePath = "Resources/Files/Sources"
return switch self { return switch self {
case .app, .appOptions: "\(basePath)/App" case .appOptions: "\(basePath)/App"
case .appArguments, .appBuilder, .environment, .loggerLevel: "\(basePath)/Library" case .appArguments, .appBuilder, .environment, .loggerLevel: "\(basePath)/Library"
case .appTests, .testArguments: "\(basePath)/Test" case .testArguments: "\(basePath)/Test"
default: basePath default: basePath
} }
} }

View File

@ -53,45 +53,37 @@ struct FileTests {
private extension FileTests { private extension FileTests {
enum Expectation { enum Expectation {
static let fileNames: [String] = [ static let fileNames: [String] = [
"App.swift",
"AppArguments.swift", "AppArguments.swift",
"AppBuilder.swift", "AppBuilder.swift",
"AppOptions.swift", "AppOptions.swift",
"AppTests.swift",
"Dockerfile", "Dockerfile",
".dockerignore", ".dockerignore",
"Environment+Properties.swift", "Environment+Properties.swift",
".gitignore", ".gitignore",
"LICENSE", "LICENSE",
"LoggerLevel+Conformances.swift", "LoggerLevel+Conformances.swift",
"Package.swift",
"README.md", "README.md",
"TestArguments.swift" "TestArguments.swift"
] ]
static let filePaths: [String] = [ static let filePaths: [String] = [
"App/Sources/App.swift",
"Library/Sources/Public/AppArguments.swift", "Library/Sources/Public/AppArguments.swift",
"Library/Sources/Public/AppBuilder.swift", "Library/Sources/Public/AppBuilder.swift",
"App/Sources/AppOptions.swift", "App/Sources/AppOptions.swift",
"Test/Sources/Cases/Public/AppTests.swift",
"Dockerfile", "Dockerfile",
".dockerignore", ".dockerignore",
"Library/Sources/Internal/Environment+Properties.swift", "Library/Sources/Internal/Environment+Properties.swift",
".gitignore", ".gitignore",
"LICENSE", "LICENSE",
"Library/Sources/Internal/LoggerLevel+Conformances.swift", "Library/Sources/Internal/LoggerLevel+Conformances.swift",
"Package.swift",
"README.md", "README.md",
"Test/Sources/Helpers/TestArguments.swift" "Test/Sources/Helpers/TestArguments.swift"
] ]
static let folders: [Folder] = [ static let folders: [Folder] = [
.app,
.libraryPublic, .libraryPublic,
.libraryPublic, .libraryPublic,
.app, .app,
.testCasesPublic,
.root, .root,
.root, .root,
.libraryInternal, .libraryInternal,
@ -99,17 +91,13 @@ private extension FileTests {
.root, .root,
.libraryInternal, .libraryInternal,
.root, .root,
.root,
.testHelpers .testHelpers
] ]
static let resourcePaths: [String] = [ static let resourcePaths: [String] = [
"Resources/Files/Sources/App",
"Resources/Files/Sources/Library", "Resources/Files/Sources/Library",
"Resources/Files/Sources/Library", "Resources/Files/Sources/Library",
"Resources/Files/Sources/App", "Resources/Files/Sources/App",
"Resources/Files/Sources/Test",
"Resources/Files/Sources", "Resources/Files/Sources",
"Resources/Files/Sources", "Resources/Files/Sources",
"Resources/Files/Sources/Library", "Resources/Files/Sources/Library",
@ -117,9 +105,7 @@ private extension FileTests {
"Resources/Files/Sources", "Resources/Files/Sources",
"Resources/Files/Sources/Library", "Resources/Files/Sources/Library",
"Resources/Files/Sources", "Resources/Files/Sources",
"Resources/Files/Sources",
"Resources/Files/Sources/Test" "Resources/Files/Sources/Test"
] ]
} }
} }

View File

@ -0,0 +1,64 @@
import Testing
@testable import ColibriLibrary
struct TemplateTests {
// MARK: Properties tests
@Test(arguments: zip(Template.allCases, Expectation.fileNames))
func fileName(for template: Template, expects fileName: String) async throws {
// GIVEN
// WHEN
let result = template.fileName
// THEN
#expect(result == fileName)
}
@Test(arguments: zip(Template.allCases, Expectation.filePaths))
func filePath(for template: Template, expects filePath: String) async throws {
// GIVEN
// WHEN
let result = template.filePath
// THEN
#expect(result == filePath)
}
@Test(arguments: zip(Template.allCases, Expectation.folders))
func folder(for template: Template, expects folder: Folder) async throws {
// GIVEN
// WHEN
let result = template.folder
// THEN
#expect(result == folder)
}
}
// MARK: - Expectations
private extension TemplateTests {
enum Expectation {
static let fileNames: [String] = [
"App.swift",
"AppTests.swift",
"Package.swift",
]
static let filePaths: [String] = [
"App/Sources/App.swift",
"Test/Sources/Cases/Public/AppTests.swift",
"Package.swift",
]
static let folders: [Folder] = [
.app,
.testCasesPublic,
.root,
]
}
}