Created
September 3, 2017 23:00
-
-
Save ncreated/4ad64e0a24415ee8ba10c25d7e6a9f87 to your computer and use it in GitHub Desktop.
Medium blogpost snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func test_givenUnlockedSecureStorage_whenSavingValue_itCanBeLaterRead() { | |
let storage = SecureStorage<String>() | |
let unlockExpectation = self.expectation(description: "secure storage is unlocked") | |
let saveExpectation = self.expectation(description: "value is saved") | |
let readExpectation = self.expectation(description: "value is read") | |
storage.unlock { (unlocked) in | |
XCTAssertTrue(unlocked) | |
unlockExpectation.fulfill() | |
} | |
wait(for: [unlockExpectation], timeout: 1) | |
storage.save("secret") { | |
saveExpectation.fulfill() | |
} | |
wait(for: [saveExpectation], timeout: 1) | |
storage.read { value in | |
XCTAssertEqual(value, "secret") | |
readExpectation.fulfill() | |
} | |
wait(for: [readExpectation], timeout: 1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment