feat: Adds file-client tests.
This commit is contained in:
67
Tests/FileClientTests/FileClientTests.swift
Normal file
67
Tests/FileClientTests/FileClientTests.swift
Normal file
@@ -0,0 +1,67 @@
|
||||
import FileClient
|
||||
import Foundation
|
||||
import Testing
|
||||
import TestSupport
|
||||
|
||||
@Suite("FileClientTests")
|
||||
struct FileClientTests {
|
||||
|
||||
@Test
|
||||
func createDirectory() async throws {
|
||||
try await withTemporaryDirectory { url in
|
||||
let fileClient = FileClient.liveValue
|
||||
let tempDir = url.appending(path: "temp")
|
||||
try await fileClient.createDirectory(tempDir)
|
||||
let isDirectory = try await fileClient.isDirectory(tempDir)
|
||||
#expect(isDirectory)
|
||||
}
|
||||
}
|
||||
|
||||
@Test(arguments: ["vault.yml", "vault.yaml"])
|
||||
func findVaultFile(fileName: String) async throws {
|
||||
try await withTemporaryDirectory { url in
|
||||
let fileClient = FileClient.liveValue
|
||||
|
||||
let vaultFilePath = url.appending(path: fileName)
|
||||
try FileManager.default.createFile(atPath: vaultFilePath.cleanFilePath, contents: nil)
|
||||
let output = try await fileClient.findVaultFile(url)!
|
||||
|
||||
#expect(output.cleanFilePath == vaultFilePath.cleanFilePath)
|
||||
|
||||
let nilWhenFileNotDirectory = try await fileClient.findVaultFile(vaultFilePath)
|
||||
#expect(nilWhenFileNotDirectory == nil)
|
||||
}
|
||||
}
|
||||
|
||||
@Test(arguments: ["vault.yml", "vault.yaml"])
|
||||
func findVaultFileNestedInSubfolder(fileName: String) async throws {
|
||||
try await withTemporaryDirectory { url in
|
||||
|
||||
let fileClient = FileClient.liveValue
|
||||
let subDir = url.appending(path: "sub")
|
||||
|
||||
try await fileClient.createDirectory(subDir)
|
||||
|
||||
let vaultFilePath = subDir.appending(path: fileName)
|
||||
try FileManager.default.createFile(atPath: vaultFilePath.cleanFilePath, contents: nil)
|
||||
let output = try await fileClient.findVaultFile(url)!
|
||||
|
||||
#expect(output.cleanFilePath == vaultFilePath.cleanFilePath)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
func findVaultFileReturnsNil() async throws {
|
||||
try await withTemporaryDirectory { url in
|
||||
|
||||
let fileClient = FileClient.liveValue
|
||||
let subDir = url.appending(path: "sub")
|
||||
|
||||
try await fileClient.createDirectory(subDir)
|
||||
|
||||
let output = try await fileClient.findVaultFile(url)
|
||||
|
||||
#expect(output == nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ struct VaultClientTests: TestCase {
|
||||
func decrypt(input: TestOptions) async throws {
|
||||
try await withCapturingCommandClient("decrypt") {
|
||||
$0.configurationClient = .mock(input.configuration)
|
||||
$0.fileClient.findVaultFileInCurrentDirectory = { URL(filePath: "/vault.yml") }
|
||||
$0.fileClient.findVaultFile = { _ in URL(filePath: "/vault.yml") }
|
||||
$0.vaultClient = .liveValue
|
||||
} run: {
|
||||
@Dependency(\.vaultClient) var vaultClient
|
||||
@@ -45,7 +45,7 @@ struct VaultClientTests: TestCase {
|
||||
func encrypt(input: TestOptions) async throws {
|
||||
try await withCapturingCommandClient("decrypt") {
|
||||
$0.configurationClient = .mock(input.configuration)
|
||||
$0.fileClient.findVaultFileInCurrentDirectory = { URL(filePath: "/vault.yml") }
|
||||
$0.fileClient.findVaultFile = { _ in URL(filePath: "/vault.yml") }
|
||||
$0.vaultClient = .liveValue
|
||||
} run: {
|
||||
@Dependency(\.vaultClient) var vaultClient
|
||||
|
||||
Reference in New Issue
Block a user