diff --git a/CHANGELOG.md b/CHANGELOG.md index f3d509b..3a70560 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ has a matching GitHub release whose body comes from its section below. ### Fixed +- `go test ./internal/cli` on a Windows machine with Berth installed no longer deletes the installed services' + launchers (`units\*.vbs` in the state directory). Three service tests ran a real uninstall or install against + the user's own state directory instead of a temporary one. (#351) - On Windows, `berth service install --notify` no longer opens a console window at logon. The Run key started `berth.exe notify` itself, a console program, and closing that window ended the tray. It now starts the tray through the hidden launcher the other services use, and its output goes to `logs\berth-notify.log`. Run the diff --git a/internal/cli/service_windows_test.go b/internal/cli/service_windows_test.go index b4b4847..d324034 100644 --- a/internal/cli/service_windows_test.go +++ b/internal/cli/service_windows_test.go @@ -245,6 +245,7 @@ func TestServiceInstallWindows(t *testing.T) { } func TestServiceInstallWindowsCommandFails(t *testing.T) { + t.Setenv("XDG_STATE_HOME", t.TempDir()) dir := t.TempDir() ops, _ := fakeOps(t, dir, func(a argv) (string, error) { return "ERROR: Access is denied.", errors.New("exit status 1") @@ -403,6 +404,9 @@ func TestServiceStatusWindows(t *testing.T) { } func TestServiceUninstallWindows(t *testing.T) { + // The uninstall removes each unit's stub for real: without its own + // state directory it deletes a live install's launchers (issue 351). + t.Setenv("XDG_STATE_HOME", t.TempDir()) ops, calls := fakeOps(t, t.TempDir(), func(a argv) (string, error) { if a.args[0] == "/Delete" { if a.args[2] == `\Berth\berth-gateway` { @@ -442,6 +446,7 @@ func TestServiceUninstallWindows(t *testing.T) { // A task that is not running makes /End fail; the uninstall still deletes it. func TestServiceUninstallWindowsIgnoresEndFailure(t *testing.T) { + t.Setenv("XDG_STATE_HOME", t.TempDir()) ops, _ := fakeOps(t, t.TempDir(), func(a argv) (string, error) { if a.args[0] == "/End" { return "ERROR: There is no running instance of the task.", errors.New("exit status 1")