mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-05 19:57:31 +00:00
Convert to Swift testing.
This commit is contained in:
1 parent
807d44a10d
commit
2b32f055a9
1 file changed
+21
-74
@@ -6,96 +6,43 @@
|
||||
// Copyright © 2019 Ranchero Software, LLC. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import RSWeb
|
||||
import Testing
|
||||
@testable import Account
|
||||
import Secrets
|
||||
|
||||
@MainActor final class AccountCredentialsTest: XCTestCase {
|
||||
@MainActor struct AccountCredentialsTest {
|
||||
|
||||
private var account: Account!
|
||||
|
||||
override func setUp() async throws {
|
||||
account = TestAccountManager.shared.createAccount(type: .feedbin)
|
||||
}
|
||||
|
||||
override func tearDown() async throws {
|
||||
TestAccountManager.shared.deleteAccount(account)
|
||||
}
|
||||
|
||||
func testCreateRetrieveDelete() {
|
||||
@Test func createRetrieveDelete() throws {
|
||||
let account = TestAccountManager.shared.createAccount(type: .feedbin)
|
||||
defer {
|
||||
TestAccountManager.shared.deleteAccount(account)
|
||||
}
|
||||
|
||||
// Make sure any left over from failed tests are gone
|
||||
do {
|
||||
try account.removeCredentials(type: .basic)
|
||||
} catch {
|
||||
XCTFail(error.localizedDescription)
|
||||
}
|
||||
|
||||
var credentials: Credentials? = Credentials(type: .basic, username: "maurice", secret: "hardpasswd")
|
||||
try account.removeCredentials(type: .basic)
|
||||
|
||||
// Store the credentials
|
||||
do {
|
||||
try account.storeCredentials(credentials!)
|
||||
} catch {
|
||||
XCTFail(error.localizedDescription)
|
||||
}
|
||||
try account.storeCredentials(Credentials(type: .basic, username: "maurice", secret: "hardpasswd"))
|
||||
|
||||
// Retrieve them
|
||||
credentials = nil
|
||||
do {
|
||||
credentials = try account.retrieveCredentials(type: .basic)
|
||||
} catch {
|
||||
XCTFail(error.localizedDescription)
|
||||
}
|
||||
|
||||
switch credentials!.type {
|
||||
case .basic:
|
||||
XCTAssertEqual("maurice", credentials?.username)
|
||||
XCTAssertEqual("hardpasswd", credentials?.secret)
|
||||
default:
|
||||
XCTFail("Expected \(CredentialsType.basic), received \(credentials!.type)")
|
||||
}
|
||||
let storedCredentials = try #require(try account.retrieveCredentials(type: .basic))
|
||||
#expect(storedCredentials.type == .basic)
|
||||
#expect(storedCredentials.username == "maurice")
|
||||
#expect(storedCredentials.secret == "hardpasswd")
|
||||
|
||||
// Update them
|
||||
credentials = Credentials(type: .basic, username: "maurice", secret: "easypasswd")
|
||||
do {
|
||||
try account.storeCredentials(credentials!)
|
||||
} catch {
|
||||
XCTFail(error.localizedDescription)
|
||||
}
|
||||
try account.storeCredentials(Credentials(type: .basic, username: "maurice", secret: "easypasswd"))
|
||||
|
||||
// Retrieve them again
|
||||
credentials = nil
|
||||
do {
|
||||
credentials = try account.retrieveCredentials(type: .basic)
|
||||
} catch {
|
||||
XCTFail(error.localizedDescription)
|
||||
}
|
||||
|
||||
switch credentials!.type {
|
||||
case .basic:
|
||||
XCTAssertEqual("maurice", credentials?.username)
|
||||
XCTAssertEqual("easypasswd", credentials?.secret)
|
||||
default:
|
||||
XCTFail("Expected \(CredentialsType.basic), received \(credentials!.type)")
|
||||
}
|
||||
let updatedCredentials = try #require(try account.retrieveCredentials(type: .basic))
|
||||
#expect(updatedCredentials.type == .basic)
|
||||
#expect(updatedCredentials.username == "maurice")
|
||||
#expect(updatedCredentials.secret == "easypasswd")
|
||||
|
||||
// Delete them
|
||||
do {
|
||||
try account.removeCredentials(type: .basic)
|
||||
} catch {
|
||||
XCTFail(error.localizedDescription)
|
||||
}
|
||||
try account.removeCredentials(type: .basic)
|
||||
|
||||
// Make sure they are gone
|
||||
do {
|
||||
try credentials = account.retrieveCredentials(type: .basic)
|
||||
} catch {
|
||||
XCTFail(error.localizedDescription)
|
||||
}
|
||||
|
||||
XCTAssertNil(credentials)
|
||||
}
|
||||
|
||||
#expect(try account.retrieveCredentials(type: .basic) == nil)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user