Skip to content

Commit 12283c3

Browse files
committed
adjusting git tests
1 parent 247166d commit 12283c3

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

Tests/UnitTests/GitTests.swift

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,78 @@ class GitTests: XCTestCase {
1414
let repository = "repository"
1515
let branch = "branch"
1616
let targetDirectoryPath = "targetDirectoryPath"
17+
let shellResult = "shell-result"
18+
19+
let shellExpectation = expectation(description: "MockShell.execute was called once")
20+
let fileHandlerExpectation = expectation(description: "MockFileHandler.handleContentsOfDirectory was called once")
21+
let loggerLogExpectation = expectation(description: "MockLogger.handleLog was called once")
22+
let loggerDebugExpectation = expectation(description: "MockLogger.handleDebug was called once")
23+
let allExpectations = [shellExpectation, fileHandlerExpectation, loggerLogExpectation, loggerDebugExpectation]
1724

1825
let mockShell = MockShell { command in
1926
XCTAssertEqual(command, "git clone -b \(branch) \(repository) \(targetDirectoryPath)")
20-
return ""
27+
shellExpectation.fulfill()
28+
return shellResult
29+
}
30+
var mockFileHandler = MockFileHandler()
31+
mockFileHandler.handleContentsOfDirectory = { directoryPath in
32+
XCTAssertEqual(targetDirectoryPath, directoryPath)
33+
fileHandlerExpectation.fulfill()
34+
return ["NonEmpty"]
2135
}
22-
23-
let mockFileHandler = MockFileHandler(handleFileExists: { _ in true })
2436
var mockLogger = MockLogger()
2537
mockLogger.handleLog = { message, subsystem in
2638
XCTAssertEqual(message, "🐱 Cloning repository @ branch into targetDirectoryPath")
2739
XCTAssertEqual(subsystem, "Git")
40+
loggerLogExpectation.fulfill()
41+
}
42+
mockLogger.handleDebug = { message, subsystem in
43+
XCTAssertEqual(message, shellResult)
44+
XCTAssertEqual(subsystem, "Git")
45+
loggerDebugExpectation.fulfill()
2846
}
2947

3048
let git = Git(shell: mockShell, fileHandler: mockFileHandler, logger: mockLogger)
3149
try git.clone(repository, at: branch, targetDirectoryPath: targetDirectoryPath)
50+
51+
wait(for: allExpectations, timeout: 1)
3252
}
3353

3454
func test_clone_fail() throws {
3555

3656
let repository = "repository"
3757
let branch = "branch"
3858
let targetDirectoryPath = "targetDirectoryPath"
59+
let shellResult = "shell-result"
60+
61+
let shellExpectation = expectation(description: "MockShell.execute was called once")
62+
let fileHandlerExpectation = expectation(description: "MockFileHandler.handleContentsOfDirectory was called once")
63+
let loggerLogExpectation = expectation(description: "MockLogger.handleLog was called once")
64+
let loggerDebugExpectation = expectation(description: "MockLogger.handleDebug was called once")
65+
let allExpectations = [shellExpectation, fileHandlerExpectation, loggerLogExpectation, loggerDebugExpectation]
3966

4067
let mockShell = MockShell { command in
4168
XCTAssertEqual(command, "git clone -b \(branch) \(repository) \(targetDirectoryPath)")
42-
return ""
69+
shellExpectation.fulfill()
70+
return shellResult
4371
}
4472

45-
let mockFileHandler = MockFileHandler(handleFileExists: { _ in false })
73+
var mockFileHandler = MockFileHandler()
74+
mockFileHandler.handleContentsOfDirectory = { directoryPath in
75+
XCTAssertEqual(targetDirectoryPath, directoryPath)
76+
fileHandlerExpectation.fulfill()
77+
return []
78+
}
4679
var mockLogger = MockLogger()
4780
mockLogger.handleLog = { message, subsystem in
4881
XCTAssertEqual(message, "🐱 Cloning repository @ branch into targetDirectoryPath")
4982
XCTAssertEqual(subsystem, "Git")
83+
loggerLogExpectation.fulfill()
84+
}
85+
mockLogger.handleDebug = { message, subsystem in
86+
XCTAssertEqual(message, shellResult)
87+
XCTAssertEqual(subsystem, "Git")
88+
loggerDebugExpectation.fulfill()
5089
}
5190

5291
let git = Git(shell: mockShell, fileHandler: mockFileHandler, logger: mockLogger)
@@ -58,5 +97,7 @@ class GitTests: XCTestCase {
5897
let fileHandlerError = try XCTUnwrap(error as? GitError)
5998
XCTAssertEqual(fileHandlerError, GitError.couldNotClone(branchOrTag: branch, repository: repository))
6099
}
100+
101+
wait(for: allExpectations, timeout: 1)
61102
}
62103
}

0 commit comments

Comments
 (0)