Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//
// CredentialPinParserTests.swift
// SplitTests
// HostDomainFilterTests.swift
// HttpTests
//
// Created by Javier Avrudsky on 28/07/2024.
// Copyright © 2024 Split. All rights reserved.
//

import Foundation
import XCTest
@testable import Split
@testable import Http

class CredentialPinParserTests: XCTestCase {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//
// EndpointTest.swift
// SplitTests
// HttpTests
//
// Created by Javier L. Avrudsky on 23/06/2020.
// Copyright © 2020 Split. All rights reserved.
//

import Foundation
import XCTest
@testable import Split
@testable import Http

class EndpointTest: XCTestCase {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
//
// HttpRequestListTest.swift
// SplitTests
// HttpTests
//
// Created by Javier L. Avrudsky on 23/06/2020.
// Copyright © 2020 Split. All rights reserved.
//

import Foundation
import XCTest
@testable import Split
#if !COCOAPODS
import Http
#endif
@testable import Http

class HttpRequestListTest: XCTestCase {
var requestList: HttpRequestList!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,46 @@
//
// HttpResponseTest.swift
// SplitTests
// HttpTests
//
// Created by Javier L. Avrudsky on 24/06/2020.
// Copyright © 2020 Split. All rights reserved.
//

import Foundation
import XCTest
@testable import Split
@testable import Http

class HttpResponseTest: XCTestCase {
override func setUp() {
}

func testHttp200() {
// Create http response code > 200 and < 300 should be SUCCESS
let response = HttpResponse(code: 200)
let response = HttpResponse(code: 200)

XCTAssertTrue(response.result.isSuccess)
XCTAssertTrue(response.isSuccess)
}


func testHttp299() {
// Create http response code > 200 and < 300 should be SUCCESS
// Put some values in input stream (from output stream anywhere)
// Check values received
let response = HttpResponse(code: 299)
let response = HttpResponse(code: 299)

XCTAssertTrue(response.result.isSuccess)
XCTAssertTrue(response.isSuccess)
}


func testHttp104() {
// Http 104-199 is unassgned so far
// Create http response code < 104 should not be considered SUCCESSs
let response = HttpResponse(code: 104)
// Http 104-199 is unassigned so far
// Create http response code < 104 should not be considered SUCCESS
let response = HttpResponse(code: 104)

XCTAssertFalse(response.result.isSuccess)
XCTAssertFalse(response.isSuccess)
}

func testHttp300() {
// Create http response code > 299 should be considered ERROR
let response = HttpResponse(code: 300)
let response = HttpResponse(code: 300)

XCTAssertFalse(response.result.isSuccess)
XCTAssertFalse(response.isSuccess)
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
//
// HttpStreamRequestTest.swift
// SplitTests
// HttpTests
//
// Created by Javier L. Avrudsky on 25/06/2020.
// Copyright © 2020 Split. All rights reserved.
//

import Foundation
import XCTest
@testable import Split
@testable import Http

private extension Data {
var stringRepresentation: String {
String(data: self, encoding: .utf8) ?? ""
}
}

class HttpStreamRequestTest: XCTestCase {

Expand Down Expand Up @@ -54,7 +60,7 @@ class HttpStreamRequestTest: XCTestCase {
let httpRequest = try DefaultHttpStreamRequest(session: httpSession, url: url, parameters: nil, headers: nil)

_ = httpRequest.getResponse(responseHandler: { response in
responseIsSuccess = response.result.isSuccess
responseIsSuccess = response.isSuccess

}, incomingDataHandler: { data in
receivedData.append(data.stringRepresentation)
Expand Down Expand Up @@ -90,7 +96,7 @@ class HttpStreamRequestTest: XCTestCase {
let httpRequest = try DefaultHttpStreamRequest(session: httpSession, url: url, parameters: nil, headers: nil)

_ = httpRequest.getResponse(responseHandler: { response in
responseIsSuccess = response.result.isSuccess
responseIsSuccess = response.isSuccess
onResponseExpectation.fulfill()

}, incomingDataHandler: { data in
Expand Down
9 changes: 0 additions & 9 deletions Sources/Http/Tests/HttpTests.swift

This file was deleted.

56 changes: 56 additions & 0 deletions Sources/Http/Tests/Mocks/HttpRequestManagerMock.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// HttpRequestManagerMock.swift
// HttpTests
//
// Created by Javier L. Avrudsky on 07/07/2020.
// Copyright © 2020 Split. All rights reserved.
//

import Foundation
@testable import Http

class HttpRequestManagerMock: HttpRequestManager, @unchecked Sendable {

// Function counters
var addRequestCallCount = 0
var appendDataCallCount = 0
var setResponseCodeCallCount = 0
var notifyErrorCallCount = 0
var request: HttpRequest!

var setResponseCodeDummyValue = false

func addRequest(_ request: HttpRequest) {
addRequestCallCount+=1
self.request = request
}

func append(data: Data, to taskIdentifier: Int) {
appendDataCallCount+=1

if let r = request as? HttpDataRequest {
r.notifyIncomingData(data)
} else if let r = request as? HttpStreamRequest {
r.notifyIncomingData(data)
}
}

func complete(taskIdentifier: Int, error: HttpError?) {
notifyErrorCallCount+=1
request.complete(error: error)
}

func set(responseCode: Int, to taskIdentifier: Int) -> Bool {
setResponseCodeCallCount+=1
request.setResponse(code: responseCode)
request.complete(error: nil)
return setResponseCodeDummyValue
}

func destroy() {
addRequestCallCount = 0
appendDataCallCount = 0
setResponseCodeCallCount = 0
notifyErrorCallCount = 0
}
}
47 changes: 47 additions & 0 deletions Sources/Http/Tests/Mocks/HttpRequestMock.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// HttpRequestMock.swift
// HttpTests
//
// Created by Javier L. Avrudsky on 10/07/2020.
// Copyright © 2020 Split. All rights reserved.
//

import Foundation
@testable import Http

class HttpRequestMock: HttpRequest, @unchecked Sendable {
var pinnedCredentialFail: Bool = false

func notifyPinnedCredentialFail() {
}

var identifier: Int

var url: URL = URL(string: "http://split.com")!

var method: HttpMethod = .get

var parameters: HttpParameters?

var headers: HttpHeaders = [:]

var body: Data?

var responseCode: Int = -1

init(identifier: Int) {
self.identifier = identifier
}

func send() {
}

func setResponse(code: Int) {
}

func notifyIncomingData(_ data: Data) {
}

func complete(error: HttpError?) {
}
}
22 changes: 22 additions & 0 deletions Sources/Http/Tests/Mocks/HttpSessionMock.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// HttpSessionMock.swift
// HttpTests
//
// Created by Javier L. Avrudsky on 25/06/2020.
// Copyright © 2020 Split. All rights reserved.
//

import Foundation
@testable import Http

class HttpSessionMock: HttpSession, @unchecked Sendable {

func finalize() {
}

private(set) var dataTaskCallCount: Int = 0
func startTask(with request: HttpRequest) -> HttpTask? {
dataTaskCallCount+=1
return HttpTaskMock(identifier: 100)
}
}
22 changes: 22 additions & 0 deletions Sources/Http/Tests/Mocks/HttpTaskMock.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// HttpTaskMock.swift
// HttpTests
//
// Created by Javier L. Avrudsky on 25/06/2020.
// Copyright © 2020 Split. All rights reserved.
//

import Foundation
@testable import Http

class HttpTaskMock: HttpTask, @unchecked Sendable {
var identifier: Int = -1

init(identifier: Int) {
self.identifier = identifier
}

func cancel() {
}

}
Loading
Loading