Skip to content
Open
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
2 changes: 1 addition & 1 deletion Sources/tart/ControlSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ControlSocket {
func run() async throws {
// Remove control socket file from previous "tart run" invocations,
// if any, otherwise we may get the "address already in use" error
try? FileManager.default.removeItem(atPath: controlSocketURL.path())
try? FileManager.default.removeItem(atPath: controlSocketURL.path)

// Change the current working directory to a VM's base directory
// to work around Unix domain socket 104 byte limitation [1]
Expand Down
28 changes: 28 additions & 0 deletions Tests/TartTests/ControlSocketURLTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import XCTest
@testable import tart

final class ControlSocketURLTests: XCTestCase {
func testControlSocketURLResolvesToAbsolutePath() throws {
let baseURL = URL(fileURLWithPath: "/Users/test/.tart/vms/myvm/")
let vmDir = VMDirectory(baseURL: baseURL)

// The .path property resolves relative URLs to absolute paths,
// which is required for stale socket cleanup in ControlSocket.run()
// since it happens before the working directory is changed.
XCTAssertEqual(
vmDir.controlSocketURL.path,
"/Users/test/.tart/vms/myvm/control.sock"
)
}

func testControlSocketURLRelativePathIsJustFilename() throws {
let baseURL = URL(fileURLWithPath: "/Users/test/.tart/vms/myvm/")
let vmDir = VMDirectory(baseURL: baseURL)

// The .relativePath is used for socket binding after cwd is changed
XCTAssertEqual(
vmDir.controlSocketURL.relativePath,
"control.sock"
)
}
}