From 06649f47a8b1d65590ee8a8f78668d064e92f56b Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Sun, 28 Jul 2024 14:55:56 -0600 Subject: rename and capitalize --- .../SwiftGopherClientTests.swift | 89 ++++++++++++++++++++++ .../SwiftGopherServerTests.swift | 63 +++++++++++++++ .../swiftGopherClientTests.swift | 89 ---------------------- .../swiftGopherServerTests.swift | 63 --------------- 4 files changed, 152 insertions(+), 152 deletions(-) create mode 100644 Tests/SwiftGopherClientTests/SwiftGopherClientTests.swift create mode 100644 Tests/SwiftGopherServerTests/SwiftGopherServerTests.swift delete mode 100644 Tests/swiftGopherClientTests/swiftGopherClientTests.swift delete mode 100644 Tests/swiftGopherServerTests/swiftGopherServerTests.swift (limited to 'Tests') diff --git a/Tests/SwiftGopherClientTests/SwiftGopherClientTests.swift b/Tests/SwiftGopherClientTests/SwiftGopherClientTests.swift new file mode 100644 index 0000000..2f559cd --- /dev/null +++ b/Tests/SwiftGopherClientTests/SwiftGopherClientTests.swift @@ -0,0 +1,89 @@ +// +// swiftGopherClientTests.swift +// +// +// Created by Navan Chauhan on 12/12/23. +// + +import NIO +import XCTest + +@testable import SwiftGopherClient + +final class GopherClientTests: XCTestCase { + + var client: GopherClient! + + override func setUp() { + super.setUp() + client = GopherClient() + } + + override func tearDown() { + client = nil + super.tearDown() + } + + func testInitialization() { + XCTAssertNotNil(client, "GopherClient should be initialized successfully") + } + + func testSendRequestCompletion() { + let expectation = XCTestExpectation(description: "Send request completion") + + client.sendRequest(to: "gopher.navan.dev", message: "\r\n") { result in + switch result { + case .success(let items): + XCTAssertFalse(items.isEmpty, "Response should contain gopher items") + case .failure(let error): + XCTFail("Request failed with error: \(error)") + } + expectation.fulfill() + } + + wait(for: [expectation], timeout: 10.0) + } + + @available(iOS 13.0, macOS 10.15, *) + func testSendRequestAsync() async throws { + do { + let items = try await client.sendRequest(to: "gopher.navan.dev", message: "\r\n") + XCTAssertFalse(items.isEmpty, "Response should contain gopher items") + } catch { + XCTFail("Async request failed with error: \(error)") + } + } + + func testInvalidHost() { + let expectation = XCTestExpectation(description: "Invalid host request") + + client.sendRequest(to: "invalid.host.example", message: "") { result in + switch result { + case .success: + XCTFail("Request should fail for invalid host") + case .failure: + // Expected failure + break + } + expectation.fulfill() + } + + wait(for: [expectation], timeout: 10.0) + } + + func testCustomPort() { + let expectation = XCTestExpectation(description: "Custom port request") + + client.sendRequest(to: "gopher.navan.dev", port: 70, message: "\r\n") { result in + switch result { + case .success(let items): + XCTAssertFalse(items.isEmpty, "Response should contain gopher items") + case .failure(let error): + XCTFail("Request failed with error: \(error)") + } + expectation.fulfill() + } + + wait(for: [expectation], timeout: 10.0) + } +} diff --git a/Tests/SwiftGopherServerTests/SwiftGopherServerTests.swift b/Tests/SwiftGopherServerTests/SwiftGopherServerTests.swift new file mode 100644 index 0000000..0413d90 --- /dev/null +++ b/Tests/SwiftGopherServerTests/SwiftGopherServerTests.swift @@ -0,0 +1,63 @@ +// +// swiftGopherServerTests.swift +// +// +// Created by Navan Chauhan on 7/28/24. +// + +import ArgumentParser +import NIO +import XCTest + +@testable import swift_gopher + +final class SwiftGopherTests: XCTestCase { + + func testDefaultValues() throws { + let gopher = try swiftGopher.parse([]) + + XCTAssertEqual(gopher.gopherHostName, "localhost") + XCTAssertEqual(gopher.host, "0.0.0.0") + XCTAssertEqual(gopher.port, 8080) + XCTAssertEqual(gopher.gopherDataDir, "./example-gopherdata") + XCTAssertFalse(gopher.disableSearch) + XCTAssertFalse(gopher.disableGophermap) + } + + func testCustomValues() throws { + let args = [ + "--gopher-host-name", "example.com", + "--host", "127.0.0.1", + "--port", "9090", + "--gopher-data-dir", "/custom/path", + "--disable-search", + "--disable-gophermap", + ] + + let gopher = try swiftGopher.parse(args) + + XCTAssertEqual(gopher.gopherHostName, "example.com") + XCTAssertEqual(gopher.host, "127.0.0.1") + XCTAssertEqual(gopher.port, 9090) + XCTAssertEqual(gopher.gopherDataDir, "/custom/path") + XCTAssertTrue(gopher.disableSearch) + XCTAssertTrue(gopher.disableGophermap) + } + + func testShortOptions() throws { + let args = [ + "-g", "short.com", + "-h", "192.168.1.1", + "-p", "7070", + "-d", "/short/path", + ] + + let gopher = try swiftGopher.parse(args) + + XCTAssertEqual(gopher.gopherHostName, "short.com") + XCTAssertEqual(gopher.host, "192.168.1.1") + XCTAssertEqual(gopher.port, 7070) + XCTAssertEqual(gopher.gopherDataDir, "/short/path") + } + +} diff --git a/Tests/swiftGopherClientTests/swiftGopherClientTests.swift b/Tests/swiftGopherClientTests/swiftGopherClientTests.swift deleted file mode 100644 index 088124d..0000000 --- a/Tests/swiftGopherClientTests/swiftGopherClientTests.swift +++ /dev/null @@ -1,89 +0,0 @@ -// -// swiftGopherClientTests.swift -// -// -// Created by Navan Chauhan on 12/12/23. -// - -import NIO -import XCTest - -@testable import swiftGopherClient - -final class GopherClientTests: XCTestCase { - - var client: GopherClient! - - override func setUp() { - super.setUp() - client = GopherClient() - } - - override func tearDown() { - client = nil - super.tearDown() - } - - func testInitialization() { - XCTAssertNotNil(client, "GopherClient should be initialized successfully") - } - - func testSendRequestCompletion() { - let expectation = XCTestExpectation(description: "Send request completion") - - client.sendRequest(to: "gopher.navan.dev", message: "\r\n") { result in - switch result { - case .success(let items): - XCTAssertFalse(items.isEmpty, "Response should contain gopher items") - case .failure(let error): - XCTFail("Request failed with error: \(error)") - } - expectation.fulfill() - } - - wait(for: [expectation], timeout: 10.0) - } - - @available(iOS 13.0, macOS 10.15, *) - func testSendRequestAsync() async throws { - do { - let items = try await client.sendRequest(to: "gopher.navan.dev", message: "\r\n") - XCTAssertFalse(items.isEmpty, "Response should contain gopher items") - } catch { - XCTFail("Async request failed with error: \(error)") - } - } - - func testInvalidHost() { - let expectation = XCTestExpectation(description: "Invalid host request") - - client.sendRequest(to: "invalid.host.example", message: "") { result in - switch result { - case .success: - XCTFail("Request should fail for invalid host") - case .failure: - // Expected failure - break - } - expectation.fulfill() - } - - wait(for: [expectation], timeout: 10.0) - } - - func testCustomPort() { - let expectation = XCTestExpectation(description: "Custom port request") - - client.sendRequest(to: "gopher.navan.dev", port: 70, message: "\r\n") { result in - switch result { - case .success(let items): - XCTAssertFalse(items.isEmpty, "Response should contain gopher items") - case .failure(let error): - XCTFail("Request failed with error: \(error)") - } - expectation.fulfill() - } - - wait(for: [expectation], timeout: 10.0) - } -} diff --git a/Tests/swiftGopherServerTests/swiftGopherServerTests.swift b/Tests/swiftGopherServerTests/swiftGopherServerTests.swift deleted file mode 100644 index 0413d90..0000000 --- a/Tests/swiftGopherServerTests/swiftGopherServerTests.swift +++ /dev/null @@ -1,63 +0,0 @@ -// -// swiftGopherServerTests.swift -// -// -// Created by Navan Chauhan on 7/28/24. -// - -import ArgumentParser -import NIO -import XCTest - -@testable import swift_gopher - -final class SwiftGopherTests: XCTestCase { - - func testDefaultValues() throws { - let gopher = try swiftGopher.parse([]) - - XCTAssertEqual(gopher.gopherHostName, "localhost") - XCTAssertEqual(gopher.host, "0.0.0.0") - XCTAssertEqual(gopher.port, 8080) - XCTAssertEqual(gopher.gopherDataDir, "./example-gopherdata") - XCTAssertFalse(gopher.disableSearch) - XCTAssertFalse(gopher.disableGophermap) - } - - func testCustomValues() throws { - let args = [ - "--gopher-host-name", "example.com", - "--host", "127.0.0.1", - "--port", "9090", - "--gopher-data-dir", "/custom/path", - "--disable-search", - "--disable-gophermap", - ] - - let gopher = try swiftGopher.parse(args) - - XCTAssertEqual(gopher.gopherHostName, "example.com") - XCTAssertEqual(gopher.host, "127.0.0.1") - XCTAssertEqual(gopher.port, 9090) - XCTAssertEqual(gopher.gopherDataDir, "/custom/path") - XCTAssertTrue(gopher.disableSearch) - XCTAssertTrue(gopher.disableGophermap) - } - - func testShortOptions() throws { - let args = [ - "-g", "short.com", - "-h", "192.168.1.1", - "-p", "7070", - "-d", "/short/path", - ] - - let gopher = try swiftGopher.parse(args) - - XCTAssertEqual(gopher.gopherHostName, "short.com") - XCTAssertEqual(gopher.host, "192.168.1.1") - XCTAssertEqual(gopher.port, 7070) - XCTAssertEqual(gopher.gopherDataDir, "/short/path") - } - -} -- cgit v1.2.3