Skip to content

Commit

Permalink
Add error description in KeychainError (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
omaralbeik authored Nov 16, 2022
1 parent 505db9d commit b835f7e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Sources/Keychain/KeychainError.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
#if canImport(Security)

import Security
import Foundation

enum KeychainError: Error {
enum KeychainError: LocalizedError {
case keychain(OSStatus)
case invalidResult

var errorDescription: String? {
switch self {
case .keychain(let oSStatus):
return "Keychain Error: OSStatus=\(oSStatus)."
case .invalidResult:
return "Keychain Error: Invalid result."
}
}
}

#endif
22 changes: 22 additions & 0 deletions Tests/Keychain/KeychainErrorTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#if canImport(Security)

@testable import KeychainStore

import Foundation
import XCTest

final class KeychainErrorTests: XCTestCase {
func testErrorDescription() {
XCTAssertEqual(
KeychainError.invalidResult.errorDescription,
"Keychain Error: Invalid result."
)

XCTAssertEqual(
KeychainError.keychain(0).errorDescription,
"Keychain Error: OSStatus=0."
)
}
}

#endif

0 comments on commit b835f7e

Please sign in to comment.