MastodonTests.swift 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // MastodonTests.swift
  3. // MastodonTests
  4. //
  5. // Created by MainasuK Cirno on 2021/1/22.
  6. //
  7. import XCTest
  8. @testable import Mastodon
  9. import MastodonCore
  10. @MainActor
  11. class MastodonTests: XCTestCase {
  12. override func setUpWithError() throws {
  13. // Put setup code here. This method is called before the invocation of each test method in the class.
  14. }
  15. override func tearDownWithError() throws {
  16. // Put teardown code here. This method is called after the invocation of each test method in the class.
  17. }
  18. func testExample() throws {
  19. // This is an example of a functional test case.
  20. // Use XCTAssert and related functions to verify your tests produce the correct results.
  21. }
  22. func testPerformanceExample() throws {
  23. // This is an example of a performance test case.
  24. self.measure {
  25. // Put the code you want to measure the time of here.
  26. }
  27. }
  28. }
  29. extension MastodonTests {
  30. func testWebFinger() {
  31. let expectation = expectation(description: "webfinger")
  32. let cancellable = AppContext.shared.apiService.webFinger(domain: "pawoo.net")
  33. .sink { completion in
  34. expectation.fulfill()
  35. } receiveValue: { domain in
  36. expectation.fulfill()
  37. }
  38. wait(for: [expectation], timeout: 10)
  39. }
  40. @available(iOS 15.0, *)
  41. func testConnectOnion() async throws {
  42. let request = URLRequest(
  43. url: URL(string: "http://a232ncr7jexk2chvubaq2v6qdizbocllqap7mnn7w7vrdutyvu32jeyd.onion/@k0gen")!,
  44. cachePolicy: .reloadIgnoringLocalAndRemoteCacheData,
  45. timeoutInterval: 10
  46. )
  47. do {
  48. let data = try await URLSession.shared.data(for: request, delegate: nil)
  49. print(data)
  50. } catch {
  51. debugPrint(error)
  52. assertionFailure(error.localizedDescription)
  53. }
  54. }
  55. }