Renamed the ResourceFile enumeration in the library target as File and also, implemented its "filePath" and "resourcePath" properties.
This commit is contained in:
parent
720ad687fb
commit
f558465b62
41
Library/Sources/Internal/Enumerations/File.swift
Normal file
41
Library/Sources/Internal/Enumerations/File.swift
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
enum File: String {
|
||||||
|
case dockerIgnore = "docker_ignore"
|
||||||
|
case gitIgnore = "git_ignore"
|
||||||
|
case license
|
||||||
|
case package
|
||||||
|
case readme
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Properties
|
||||||
|
|
||||||
|
extension File {
|
||||||
|
|
||||||
|
// MARK: Computed
|
||||||
|
|
||||||
|
var fileName: String {
|
||||||
|
switch self {
|
||||||
|
case .dockerIgnore: ".dockerignore"
|
||||||
|
case .gitIgnore: ".gitignore"
|
||||||
|
case .license: "LICENSE"
|
||||||
|
case .readme: "README.md"
|
||||||
|
case .package: "Package.swift"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var filePath: String {
|
||||||
|
switch self {
|
||||||
|
default: fileName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var resourcePath: String {
|
||||||
|
switch self {
|
||||||
|
default: "Resources/Files"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - CaseIterable
|
||||||
|
|
||||||
|
extension File: CaseIterable {}
|
@ -1,29 +0,0 @@
|
|||||||
enum ResourceFile: String {
|
|
||||||
case dockerIgnore = "docker_ignore"
|
|
||||||
case gitIgnore = "git_ignore"
|
|
||||||
case license
|
|
||||||
case package
|
|
||||||
case readme
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Properties
|
|
||||||
|
|
||||||
extension ResourceFile {
|
|
||||||
|
|
||||||
// MARK: Computed
|
|
||||||
|
|
||||||
var fileName: String {
|
|
||||||
switch self {
|
|
||||||
case .dockerIgnore: return ".dockerignore"
|
|
||||||
case .gitIgnore: return ".gitignore"
|
|
||||||
case .license: return "LICENSE"
|
|
||||||
case .readme: return "README.md"
|
|
||||||
case .package: return "Package.swift"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - CaseIterable
|
|
||||||
|
|
||||||
extension ResourceFile: CaseIterable {}
|
|
@ -20,17 +20,17 @@ public struct CopyFilesTask {
|
|||||||
// MARK: Functions
|
// MARK: Functions
|
||||||
|
|
||||||
public func callAsFunction(to rootFolder: URL) async throws (FileServiceError) {
|
public func callAsFunction(to rootFolder: URL) async throws (FileServiceError) {
|
||||||
for resource in ResourceFile.allCases {
|
for resource in File.allCases {
|
||||||
guard let source = bundleService.url(
|
guard let source = bundleService.url(
|
||||||
forResource: resource.rawValue,
|
forResource: resource.rawValue,
|
||||||
withExtension: nil,
|
withExtension: nil,
|
||||||
subdirectory: "Resources/Files"
|
subdirectory: resource.resourcePath
|
||||||
) else {
|
) else {
|
||||||
assertionFailure("URL should have been initialized.")
|
assertionFailure("URL should have been initialized.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let destination = rootFolder.appendingPath(resource.fileName)
|
let destination = rootFolder.appendingPath(resource.filePath)
|
||||||
|
|
||||||
try await fileService.copyFile(from: source, to: destination)
|
try await fileService.copyFile(from: source, to: destination)
|
||||||
}
|
}
|
||||||
|
70
Test/Sources/Cases/Internal/Enumerations/FileTests.swift
Normal file
70
Test/Sources/Cases/Internal/Enumerations/FileTests.swift
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
import Testing
|
||||||
|
|
||||||
|
@testable import ColibriLibrary
|
||||||
|
|
||||||
|
struct FileTests {
|
||||||
|
|
||||||
|
// MARK: Properties tests
|
||||||
|
|
||||||
|
@Test(arguments: zip(File.allCases, Expectation.fileNames))
|
||||||
|
func fileName(for file: File, expects fileName: String) async throws {
|
||||||
|
// GIVEN
|
||||||
|
// WHEN
|
||||||
|
let result = file.fileName
|
||||||
|
|
||||||
|
// THEN
|
||||||
|
#expect(result == fileName)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(arguments: zip(File.allCases, Expectation.filePaths))
|
||||||
|
func filePath(for file: File, expects filePath: String) async throws {
|
||||||
|
// GIVEN
|
||||||
|
// WHEN
|
||||||
|
let result = file.filePath
|
||||||
|
|
||||||
|
// THEN
|
||||||
|
#expect(result == filePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(arguments: zip(File.allCases, Expectation.resourcePaths))
|
||||||
|
func resourcePath(for file: File, expects resourcePath: String) async throws {
|
||||||
|
// GIVEN
|
||||||
|
// WHEN
|
||||||
|
let result = file.resourcePath
|
||||||
|
|
||||||
|
// THEN
|
||||||
|
#expect(result == resourcePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Expectations
|
||||||
|
|
||||||
|
private extension FileTests {
|
||||||
|
enum Expectation {
|
||||||
|
static let fileNames: [String] = [
|
||||||
|
".dockerignore",
|
||||||
|
".gitignore",
|
||||||
|
"LICENSE",
|
||||||
|
"Package.swift",
|
||||||
|
"README.md"
|
||||||
|
]
|
||||||
|
|
||||||
|
static let filePaths: [String] = [
|
||||||
|
".dockerignore",
|
||||||
|
".gitignore",
|
||||||
|
"LICENSE",
|
||||||
|
"Package.swift",
|
||||||
|
"README.md"
|
||||||
|
]
|
||||||
|
|
||||||
|
static let resourcePaths: [String] = [
|
||||||
|
"Resources/Files",
|
||||||
|
"Resources/Files",
|
||||||
|
"Resources/Files",
|
||||||
|
"Resources/Files",
|
||||||
|
"Resources/Files"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,20 +0,0 @@
|
|||||||
import Testing
|
|
||||||
|
|
||||||
@testable import ColibriLibrary
|
|
||||||
|
|
||||||
struct ResourceFileTests {
|
|
||||||
|
|
||||||
// MARK: Properties tests
|
|
||||||
|
|
||||||
@Test(arguments: zip(ResourceFile.allCases,
|
|
||||||
[".dockerignore", ".gitignore", "LICENSE", "Package.swift", "README.md"]))
|
|
||||||
func fileName(for resource: ResourceFile, expects fileName: String) async throws {
|
|
||||||
// GIVEN
|
|
||||||
// WHEN
|
|
||||||
let result = resource.fileName
|
|
||||||
|
|
||||||
// THEN
|
|
||||||
#expect(result == fileName)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -16,7 +16,7 @@ struct CopyFilesTaskTests {
|
|||||||
|
|
||||||
@Test func copyFiles() async throws {
|
@Test func copyFiles() async throws {
|
||||||
// GIVEN
|
// GIVEN
|
||||||
let files = files(of: ResourceFile.allCases)
|
let files = files(of: File.allCases)
|
||||||
let actions = files.map { FileServiceMock.Action.copyFile($0.source, $0.destination) }
|
let actions = files.map { FileServiceMock.Action.copyFile($0.source, $0.destination) }
|
||||||
|
|
||||||
let copyFiles = task(actions: actions)
|
let copyFiles = task(actions: actions)
|
||||||
@ -35,7 +35,7 @@ struct CopyFilesTaskTests {
|
|||||||
@Test(arguments: [FileServiceError.itemAlreadyExists, .itemEmptyData, .itemNotCopied])
|
@Test(arguments: [FileServiceError.itemAlreadyExists, .itemEmptyData, .itemNotCopied])
|
||||||
func copyFiles(throws error: FileServiceError) async throws {
|
func copyFiles(throws error: FileServiceError) async throws {
|
||||||
// GIVEN
|
// GIVEN
|
||||||
let files = files(of: Array(ResourceFile.allCases[0...2]))
|
let files = files(of: Array(File.allCases[0...2]))
|
||||||
let actions = files.map { FileServiceMock.Action.copyFile($0.source, $0.destination) }
|
let actions = files.map { FileServiceMock.Action.copyFile($0.source, $0.destination) }
|
||||||
|
|
||||||
let copyFiles = task(actions: actions + [.error(error)])
|
let copyFiles = task(actions: actions + [.error(error)])
|
||||||
@ -61,11 +61,11 @@ private extension CopyFilesTaskTests {
|
|||||||
|
|
||||||
// MARK: Type aliases
|
// MARK: Type aliases
|
||||||
|
|
||||||
typealias File = (source: URL, destination: URL)
|
typealias FileURL = (source: URL, destination: URL)
|
||||||
|
|
||||||
// MARK: Functions
|
// MARK: Functions
|
||||||
|
|
||||||
func files(of resourceFiles: [ResourceFile]) -> [File] {
|
func files(of resourceFiles: [File]) -> [FileURL] {
|
||||||
resourceFiles.map { (resourceFolder.appendingPath($0.rawValue), rootFolder.appendingPath($0.fileName)) }
|
resourceFiles.map { (resourceFolder.appendingPath($0.rawValue), rootFolder.appendingPath($0.fileName)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user