Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/LucaCore/Core/Downloader/Downloading.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

import Foundation

protocol Downloading {
public protocol Downloading {
func downloadRelease(at url: URL) async throws -> URL
}
11 changes: 7 additions & 4 deletions Sources/LucaCore/Core/Installer/Installer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,25 @@ public struct Installer {
private let binaryFinder: BinaryFinding
private let checksumValidator: ChecksumValidating
private let architectureValidator: ArchitectureValidating
private let fileDownloader: FileDownloading
private let downloader: Downloading
private let permissionManager: PermissionManaging
private let symLinker: SymLinking
private let linkedToolsLister: LinkedToolsLister
private let unlinker: Unlinker
private let ignoreArchitectureCheck: Bool

public init(fileManager: FileManaging, ignoreArchitectureCheck: Bool, printer: Printing) {
public init(
fileManager: FileManaging,
ignoreArchitectureCheck: Bool,
printer: Printing,
downloader: Downloading? = nil
) {
self.fileManager = fileManager
self.printer = printer
self.binaryFinder = BinaryFinder(fileManager: fileManager)
self.checksumValidator = ChecksumValidator(fileManager: fileManager)
self.architectureValidator = ArchitectureValidator(fileManager: fileManager)
self.fileDownloader = FileDownloader(session: .shared)
self.downloader = Downloader(fileDownloader: fileDownloader)
self.downloader = downloader ?? Downloader(fileDownloader: FileDownloader(session: .shared))
self.permissionManager = PermissionManager(fileManager: fileManager)
self.symLinker = SymLinker(fileManager: fileManager)
self.linkedToolsLister = LinkedToolsLister(fileManager: fileManager)
Expand Down
243 changes: 124 additions & 119 deletions Tests/Core/InstallerTests.swift

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions Tests/Fixtures/Lucafiles/Lucafile_HighVersion.yml

This file was deleted.

8 changes: 0 additions & 8 deletions Tests/Fixtures/Lucafiles/Lucafile_LowVersion.yml

This file was deleted.

22 changes: 22 additions & 0 deletions Tests/Fixtures/Lucafiles/Lucafile_mock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
tools:
- name: MockToolA
binaryPath: bin/ToggleGen
version: 1.0.0
url: https://example.com/mock/MockToolA.zip
- name: MockToolB
binaryPath: bin/ToggleGen
version: 2.0.0
url: https://example.com/mock/MockToolB.zip
- name: MockToolC
binaryPath: bin/ToggleGen
version: 3.0.0
url: https://example.com/mock/MockToolC.zip
- name: MockToolD
binaryPath: bin/ToggleGen
version: 4.0.0
url: https://example.com/mock/MockToolD.zip
checksum: 76b801daea0ed90f2871b0c66ebb8c4b9680d14e8011277d971cd74445fdaac5
algorithm: sha256

version: 0.0.1
8 changes: 8 additions & 0 deletions Tests/Fixtures/Lucafiles/Lucafile_mock_highversion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
tools:
- name: MockTool
binaryPath: bin/ToggleGen
version: 2.0.0
url: https://example.com/mock/MockTool-2.0.0.zip

version: 0.0.1
8 changes: 8 additions & 0 deletions Tests/Fixtures/Lucafiles/Lucafile_mock_lowversion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
tools:
- name: MockTool
binaryPath: bin/ToggleGen
version: 1.0.0
url: https://example.com/mock/MockTool-1.0.0.zip

version: 0.0.1
12 changes: 12 additions & 0 deletions Tests/Fixtures/Lucafiles/Lucafile_mock_subset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
tools:
- name: MockToolA
binaryPath: bin/ToggleGen
version: 1.0.0
url: https://example.com/mock/MockToolA.zip
- name: MockToolB
binaryPath: bin/ToggleGen
version: 2.0.0
url: https://example.com/mock/MockToolB.zip

version: 0.0.1
26 changes: 26 additions & 0 deletions Tests/Mocks/DownloaderMock.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// DownloaderMock.swift

import Foundation
import Testing
@testable import LucaCore

struct DownloaderMock: Downloading {

enum Result {
case fixture(Fixture)
case error(Error)
}

var result: Result

func downloadRelease(at url: URL) async throws -> URL {
switch result {
case .fixture(let fixture):
let bundle = Bundle.module
let path = try #require(bundle.path(forResource: fixture.filename, ofType: fixture.type))
return URL(fileURLWithPath: path)
case .error(let error):
throw error
}
}
}