Skip to content

Commit

Permalink
Add launchCommand tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tcamin committed Jan 11, 2023
1 parent ca2e5c1 commit 8dfb0dd
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- SBTUITestTunnelHost (2.0.0)
- SBTUITestTunnelHost (2.1.0)

DEPENDENCIES:
- SBTUITestTunnelHost (from `../`)
Expand All @@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
SBTUITestTunnelHost: 61b22376c8f6232440ac6cde330a4fc8746e092e
SBTUITestTunnelHost: 3dec16f0324aee7a92d25ebae3d1d3f4913cf93d

PODFILE CHECKSUM: 814a29fa0fd16a3c0594d87c72a44da4dc5af1db

Expand Down
57 changes: 56 additions & 1 deletion Example/UITests/SBTUITestTunnelHost_ExampleUITests_Swift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class SBTUITestTunnelHost_ExampleUITests_Swift: XCTestCase {
XCTAssert(app.cells["99"].isHittable)
}

func testCommandWithAmpersand() throws {
func testExecuteCommandWithAmpersand() throws {
let app = XCUIApplication()
app.launch()

Expand All @@ -76,6 +76,61 @@ class SBTUITestTunnelHost_ExampleUITests_Swift: XCTestCase {

wait { safari.state == .runningForeground }
}

func testLaunchCommandAndTerminate() throws {
let app = XCUIApplication()
app.launch()

host.connect()

let id = host.launchCommand("sleep 100")
let status = host.getStatusOfCommand(with: id)

let pid = try XCTUnwrap(status["pid"] as? Int)
let ps = try XCTUnwrap(host.executeCommand("ps -p \(pid)"))
XCTAssert(ps.contains("sleep 100"))

host.terminateCommand(with: id)

let psAfterTerminate = try XCTUnwrap(host.executeCommand("ps -p \(pid)"))
XCTAssertFalse(psAfterTerminate.contains("sleep 100"))
}

func testLaunchCommandAndInterrupt() throws {
let app = XCUIApplication()
app.launch()

host.connect()

let id = host.launchCommand("sleep 100")
let status = host.getStatusOfCommand(with: id)

let pid = try XCTUnwrap(status["pid"] as? Int)
let ps = try XCTUnwrap(host.executeCommand("ps -p \(pid)"))
XCTAssert(ps.contains("sleep 100"))

host.interruptCommand(with: id)

let psAfterInterrupt = try XCTUnwrap(host.executeCommand("ps -p \(pid)"))
XCTAssertFalse(psAfterInterrupt.contains("sleep 100"))
}

func testLaunchCommandAndWaitForCompletion() throws {
let app = XCUIApplication()
app.launch()

host.connect()

let id = host.launchCommand("date +%s000")
Thread.sleep(forTimeInterval: 0.1)
let status = host.getStatusOfCommand(with: id)

let currentDate = Int(Date().timeIntervalSince1970)
XCTAssert(try XCTUnwrap(status["stdOut"] as? String).contains("\(currentDate)"))

XCTAssertEqual(try XCTUnwrap(status["stdErr"] as? String), "")
XCTAssertEqual(try XCTUnwrap(status["terminationStatus"] as? Int), 0)
}

private func deviceIdentifier() throws -> String {
let bundlePathComponents = Bundle.main.bundleURL.pathComponents
Expand Down

0 comments on commit 8dfb0dd

Please sign in to comment.