Skip to content

Commit

Permalink
Add tests for ProductHasher
Browse files Browse the repository at this point in the history
  • Loading branch information
swiftyfinch committed Nov 29, 2023
1 parent e1738e1 commit 8f7a7d3
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 9 deletions.
14 changes: 9 additions & 5 deletions Sources/RugbyFoundation/Core/Common/Hashers/ProductHasher.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
final class ProductHasher {
private let foundationHasher: FoundationHasher
// MARK: - Interface

init(foundationHasher: FoundationHasher) {
self.foundationHasher = foundationHasher
}
protocol IProductHasher: AnyObject {
func hashContext(_ product: Product) -> [String: String?]
}

// MARK: - Implementation

final class ProductHasher {}

extension ProductHasher: IProductHasher {
func hashContext(_ product: Product) -> [String: String?] {
["name": product.name,
"type": product.type.rawValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ final class TargetsHasher {
private let buildPhaseHasher: IBuildPhaseHasher
private let cocoaPodsScriptsHasher: CocoaPodsScriptsHasher
private let configurationsHasher: ConfigurationsHasher
private let productHasher: ProductHasher
private let productHasher: IProductHasher
private let buildRulesHasher: BuildRulesHasher

init(foundationHasher: FoundationHasher,
swiftVersionProvider: ISwiftVersionProvider,
buildPhaseHasher: IBuildPhaseHasher,
cocoaPodsScriptsHasher: CocoaPodsScriptsHasher,
configurationsHasher: ConfigurationsHasher,
productHasher: ProductHasher,
productHasher: IProductHasher,
buildRulesHasher: BuildRulesHasher) {
self.foundationHasher = foundationHasher
self.swiftVersionProvider = swiftVersionProvider
Expand Down
2 changes: 1 addition & 1 deletion Sources/RugbyFoundation/Vault/Vault.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public final class Vault {
cocoaPodsScriptsHasher: CocoaPodsScriptsHasher(fileContentHasher: fileContentHasher),
configurationsHasher: ConfigurationsHasher(foundationHasher: foundationHasher,
excludeKeys: [settings.hasBackupKey]),
productHasher: ProductHasher(foundationHasher: foundationHasher),
productHasher: ProductHasher(),
buildRulesHasher: BuildRulesHasher(foundationHasher: foundationHasher,
fileContentHasher: fileContentHasher)
)
Expand Down
84 changes: 84 additions & 0 deletions Tests/FoundationTests/Core/Common/Hashers/ProductHasherTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
@testable import RugbyFoundation
import XCTest

final class ProductHasherTests: XCTestCase {
private var sut: IProductHasher!

override func setUp() {
super.setUp()
sut = ProductHasher()
}

override func tearDown() {
super.tearDown()
sut = nil
}
}

extension ProductHasherTests {
func test_framework() {
let product = Product(
name: "KeyboardLayoutGuide",
moduleName: "KeyboardLayoutGuide",
type: .framework,
parentFolderName: "Keyboard+LayoutGuide-framework"
)

// Act
let hashContext = sut.hashContext(product)

// Assert
XCTAssertEqual(
hashContext,
[
"parentFolderName": "Keyboard+LayoutGuide-framework",
"name": "KeyboardLayoutGuide",
"type": "com.apple.product-type.framework"
]
)
}

func test_library() {
let product = Product(
name: "Keyboard+LayoutGuide-library",
moduleName: "KeyboardLayoutGuide",
type: .staticLibrary,
parentFolderName: "Keyboard+LayoutGuide-library"
)

// Act
let hashContext = sut.hashContext(product)

// Assert
XCTAssertEqual(
hashContext,
[
"parentFolderName": "Keyboard+LayoutGuide-library",
"name": "Keyboard+LayoutGuide-library",
"type": "com.apple.product-type.library.static"
]
)
}

func test_bundle() {
let product = Product(
name: "LocalPodResources",
moduleName: nil,
type: .bundle,
parentFolderName: "LocalPod-framework"
)

// Act
let hashContext = sut.hashContext(product)

// Assert
XCTAssertEqual(
hashContext,
[
"parentFolderName": "LocalPod-framework",
"name": "LocalPodResources",
"type": "com.apple.product-type.bundle"
]
)
}
}
1 change: 0 additions & 1 deletion Tests/RugbyTests/Utils/Regex/RegexTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@testable import Rugby
import RugbyFoundation
import XCTest

final class RegexTests: XCTestCase {
Expand Down

0 comments on commit 8f7a7d3

Please sign in to comment.