openclaw/apps/macos/Tests/ClawdbotIPCTests/ClawdbotConfigFileTests.swift

50 lines
1.4 KiB
Swift
Raw Normal View History

import Foundation
import Testing
2026-01-04 14:32:47 +00:00
@testable import Clawdbot
@Suite
2026-01-04 14:32:47 +00:00
struct ClawdbotConfigFileTests {
@Test
func configPathRespectsEnvOverride() {
let override = FileManager.default.temporaryDirectory
2026-01-04 14:32:47 +00:00
.appendingPathComponent("clawdbot-config-\(UUID().uuidString)")
.appendingPathComponent("clawdbot.json")
.path
2026-01-04 14:32:47 +00:00
self.withEnv("CLAWDBOT_CONFIG_PATH", value: override) {
#expect(ClawdbotConfigFile.url().path == override)
}
}
@Test
func stateDirOverrideSetsConfigPath() {
let dir = FileManager.default.temporaryDirectory
2026-01-04 14:32:47 +00:00
.appendingPathComponent("clawdbot-state-\(UUID().uuidString)", isDirectory: true)
.path
2026-01-04 14:32:47 +00:00
self.withEnv("CLAWDBOT_CONFIG_PATH", value: nil) {
self.withEnv("CLAWDBOT_STATE_DIR", value: dir) {
#expect(ClawdbotConfigFile.stateDirURL().path == dir)
#expect(ClawdbotConfigFile.url().path == "\(dir)/clawdbot.json")
}
}
}
private func withEnv(_ key: String, value: String?, _ body: () -> Void) {
let previous = ProcessInfo.processInfo.environment[key]
if let value {
setenv(key, value, 1)
} else {
unsetenv(key)
}
defer {
if let previous {
setenv(key, previous, 1)
} else {
unsetenv(key)
}
}
body()
}
}