From 8a3338b0785f968f12f55ea229174413b688f3b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Wed, 21 Dec 2016 18:04:16 +0100 Subject: [PATCH] Extracted function --- Tests/SUUnarchiverTest.swift | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Tests/SUUnarchiverTest.swift b/Tests/SUUnarchiverTest.swift index c047f4c5..29acad85 100644 --- a/Tests/SUUnarchiverTest.swift +++ b/Tests/SUUnarchiverTest.swift @@ -13,8 +13,7 @@ class SUUnarchiverTest: XCTestCase var password: String? = nil var unarchivedSuccessExpectation: XCTestExpectation? = nil - func unarchiveTestAppWithExtension(_ archiveExtension: String) - { + func unarchiveTestAppWithExtension(_ archiveExtension: String) { let appName = "SparkleTestCodeSignApp" let archiveResourceURL = Bundle(for: type(of: self)).url(forResource: appName, withExtension: archiveExtension)! @@ -29,21 +28,28 @@ class SUUnarchiverTest: XCTestCase let tempArchiveURL = tempDirectoryURL.appendingPathComponent(archiveResourceURL.lastPathComponent) let extractedAppURL = tempDirectoryURL.appendingPathComponent(appName).appendingPathExtension("app") + + self.unarchiveTestSuccessAppWithExtension(archiveExtension, appName: appName, tempDirectoryURL: tempDirectoryURL, tempArchiveURL: tempArchiveURL, archiveResourceURL: archiveResourceURL); + + super.waitForExpectations(timeout: 7.0, handler: nil) + + XCTAssertTrue(fileManager.fileExists(atPath: extractedAppURL.path)) + + XCTAssertEqual("6a60ab31430cfca8fb499a884f4a29f73e59b472", hashOfTree(extractedAppURL.path)) + } + + func unarchiveTestSuccessAppWithExtension(_ archiveExtension: String, appName: String, tempDirectoryURL: URL, tempArchiveURL: URL, archiveResourceURL: URL) { + + let fileManager = FileManager.default try! fileManager.copyItem(at: archiveResourceURL, to: tempArchiveURL) - + let unarchiver = SUUnarchiver(forPath: tempArchiveURL.path, updatingHostBundlePath: nil, withPassword: self.password)! unarchiver.unarchive(completionBlock: {(error: Error?) -> Void in XCTAssertNil(error); self.unarchivedSuccessExpectation!.fulfill() }, progressBlock:{(progress: Double) -> Void in }); - - super.waitForExpectations(timeout: 7.0, handler: nil) - - XCTAssertTrue(fileManager.fileExists(atPath: extractedAppURL.path)) - - XCTAssertEqual("6a60ab31430cfca8fb499a884f4a29f73e59b472", hashOfTree(extractedAppURL.path)) } func testUnarchivingZip()