MastodonTests.swift 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. withExtendedLifetime(cancellable) {
  39. wait(for: [expectation], timeout: 10)
  40. }
  41. }
  42. func testConnectOnion() async throws {
  43. let request = URLRequest(
  44. url: URL(string: "http://a232ncr7jexk2chvubaq2v6qdizbocllqap7mnn7w7vrdutyvu32jeyd.onion/@k0gen")!,
  45. cachePolicy: .reloadIgnoringLocalAndRemoteCacheData,
  46. timeoutInterval: 10
  47. )
  48. do {
  49. let data = try await URLSession.shared.data(for: request, delegate: nil)
  50. print(data)
  51. } catch {
  52. debugPrint(error)
  53. assertionFailure(error.localizedDescription)
  54. }
  55. }
  56. }