Tests/OrgWorkspaceTests/WorkspaceRootTests.swift

design-themes-widgets
orgstar/Tests/OrgWorkspaceTests/WorkspaceRootTests.swift history · blame · raw

33 lines · 1416 bytes

 1import Foundation
 2import OrgCore
 3import Testing
 4@testable import OrgWorkspace
 5
 6struct WorkspaceRootTests {
 7    @Test func plainBookmarkResolves() throws {
 8        let folder = try Folder()
 9        let root = try WorkspaceRoot(url: folder.url)
10        let resolved = try root.resolve()
11        #expect(resolved.url.resolvingSymlinksInPath() == folder.url.resolvingSymlinksInPath())
12        #expect(root.path == folder.url.path)
13    }
14
15    /// Tests run unsandboxed, so roots keep the Developer ID build's plain bookmarks.
16    @Test func unsandboxedByDefault() throws {
17        #expect(!Sandbox.isActive)
18        let folder = try Folder()
19        let root = try WorkspaceRoot(url: folder.url)
20        #expect(try root.resolve(sandboxed: false).url.resolvingSymlinksInPath() == folder.url.resolvingSymlinksInPath())
21        #expect(root.bookmark == (try WorkspaceRoot(url: folder.url, sandboxed: false)).bookmark)
22    }
23
24    #if os(macOS)
25    /// The sandboxed build's bookmarks carry their scope, and resolve with it.
26    @Test func securityScopedBookmarkResolves() throws {
27        let folder = try Folder()
28        let root = try WorkspaceRoot(url: folder.url, sandboxed: true)
29        #expect(try root.resolve(sandboxed: true).url.resolvingSymlinksInPath() == folder.url.resolvingSymlinksInPath())
30        #expect(root.bookmark != (try WorkspaceRoot(url: folder.url, sandboxed: false)).bookmark)
31    }
32    #endif
33}