1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-07 20:10:08 +02:00

Added tests for Homebrew service parsing (#72)

This commit is contained in:
2022-01-11 21:18:05 +01:00
parent 3b4a1a0654
commit b16250c2be

View File

@ -9,12 +9,15 @@
import XCTest import XCTest
class BrewJsonParserTest: XCTestCase { class BrewJsonParserTest: XCTestCase {
// - MARK: SYNTHETIC TESTS
static var jsonBrewFile: URL { static var jsonBrewFile: URL {
return Bundle(for: Self.self).url(forResource: "brew", withExtension: "json")! return Bundle(for: Self.self)
.url(forResource: "brew", withExtension: "json")!
} }
func testCanLoadExtension() throws { func testCanLoadExtensionJson() throws {
let json = try! String(contentsOf: Self.jsonBrewFile, encoding: .utf8) let json = try! String(contentsOf: Self.jsonBrewFile, encoding: .utf8)
let package = try! JSONDecoder().decode( let package = try! JSONDecoder().decode(
[HomebrewPackage].self, from: json.data(using: .utf8)! [HomebrewPackage].self, from: json.data(using: .utf8)!
@ -29,7 +32,8 @@ class BrewJsonParserTest: XCTestCase {
} }
static var jsonBrewServicesFile: URL { static var jsonBrewServicesFile: URL {
return Bundle(for: Self.self).url(forResource: "brew-services", withExtension: "json")! return Bundle(for: Self.self)
.url(forResource: "brew-services", withExtension: "json")!
} }
func testCanParseServicesJson() throws { func testCanParseServicesJson() throws {
@ -42,5 +46,37 @@ class BrewJsonParserTest: XCTestCase {
XCTAssertEqual(services.first?.name, "dnsmasq") XCTAssertEqual(services.first?.name, "dnsmasq")
XCTAssertEqual(services.first?.service_name, "homebrew.mxcl.dnsmasq") XCTAssertEqual(services.first?.service_name, "homebrew.mxcl.dnsmasq")
} }
// - MARK: LIVE TESTS
/// This test requires that you have a valid Homebrew installation set up,
/// and requires the Valet services to be installed: php, nginx and dnsmasq.
/// Otherwise, this test won't fail. If this test fails, there is an issue with
/// your Homebrew installation or the JSON API of the Homebrew output may have changed.
func testCanParseServicesJsonFromCliOutput() throws {
let services = try! JSONDecoder().decode(
[HomebrewService].self,
from: Shell.pipe(
"sudo \(Paths.brew) services info --all --json",
requiresPath: true
).data(using: .utf8)!
)
XCTAssertTrue(services.contains(where: {$0.name == "php"} ))
XCTAssertTrue(services.contains(where: {$0.name == "nginx"} ))
XCTAssertTrue(services.contains(where: {$0.name == "dnsmasq"} ))
}
/// This test requires that you have a valid Homebrew installation set up,
/// and requires the Valet services to be installed: php, nginx and dnsmasq.
/// Otherwise, this test won't fail. If this test fails, there is an issue with
/// your Homebrew installation or the JSON API of the Homebrew output may have changed.
func testCanLoadExtensionJsonFromCliOutput() throws {
let package = try! JSONDecoder().decode(
[HomebrewPackage].self,
from: Shell.pipe("\(Paths.brew) info php --json", requiresPath: true).data(using: .utf8)!
).first!
XCTAssertTrue(package.name == "php")
}
} }