NetNewsWire/Frameworks/Account/AccountTests/AccountCredentialsTest.swift

101 lines
2.3 KiB
Swift
Raw Normal View History

//
// AccountCredentialsTest.swift
// AccountTests
//
// Created by Maurice Parker on 5/4/19.
// Copyright © 2019 Ranchero Software, LLC. All rights reserved.
//
import XCTest
2019-05-04 22:14:49 +02:00
import RSWeb
@testable import Account
class AccountCredentialsTest: XCTestCase {
private var account: Account!
override func setUp() {
2019-05-05 22:41:20 +02:00
account = TestAccountManager.shared.createAccount(type: .feedbin, transport: TestTransport())
}
override func tearDown() {
TestAccountManager.shared.deleteAccount(account)
}
2019-05-04 22:14:49 +02:00
func testCreateRetrieveDelete() {
2019-05-04 22:14:49 +02:00
// Make sure any left over from failed tests are gone
do {
try account.removeCredentials(type: .basic)
2019-05-04 22:14:49 +02:00
} catch {
XCTFail(error.localizedDescription)
}
var credentials: Credentials? = Credentials(type: .basic, username: "maurice", secret: "hardpasswd")
2019-05-04 22:14:49 +02:00
// Store the credentials
do {
try account.storeCredentials(credentials!)
} catch {
XCTFail(error.localizedDescription)
}
// Retrieve them
credentials = nil
do {
credentials = try account.retrieveCredentials(type: .basic)
2019-05-04 22:14:49 +02:00
} catch {
XCTFail(error.localizedDescription)
}
2019-05-05 10:25:21 +02:00
switch credentials!.type {
case .basic:
XCTAssertEqual("maurice", credentials?.username)
XCTAssertEqual("hardpasswd", credentials?.secret)
default:
XCTFail("Expected \(CredentialsType.basic), received \(credentials!.type)")
2019-05-05 10:25:21 +02:00
}
2019-05-04 22:14:49 +02:00
// Update them
credentials = Credentials(type: .basic, username: "maurice", secret: "easypasswd")
2019-05-04 22:14:49 +02:00
do {
try account.storeCredentials(credentials!)
} catch {
XCTFail(error.localizedDescription)
}
// Retrieve them again
credentials = nil
do {
credentials = try account.retrieveCredentials(type: .basic)
2019-05-04 22:14:49 +02:00
} catch {
XCTFail(error.localizedDescription)
}
2019-05-05 10:25:21 +02:00
switch credentials!.type {
case .basic:
XCTAssertEqual("maurice", credentials?.username)
XCTAssertEqual("easypasswd", credentials?.secret)
default:
XCTFail("Expected \(CredentialsType.basic), received \(credentials!.type)")
2019-05-05 10:25:21 +02:00
}
2019-05-04 22:14:49 +02:00
// Delete them
do {
try account.removeCredentials(type: .basic)
2019-05-04 22:14:49 +02:00
} catch {
XCTFail(error.localizedDescription)
}
// Make sure they are gone
do {
try credentials = account.retrieveCredentials(type: .basic)
2019-05-04 22:14:49 +02:00
} catch {
XCTFail(error.localizedDescription)
}
XCTAssertNil(credentials)
}
}