Files
loov--lensm/settings_test.go
wehub-resource-sync c4536f7e05
CI / test (push) Failing after 1s
CI / macOS amd64 (push) Waiting to run
CI / macOS arm64 (push) Waiting to run
chore: import upstream snapshot with attribution
2026-07-13 12:30:31 +08:00

36 lines
775 B
Go

package main
import (
"os"
"path/filepath"
"testing"
"loov.dev/lensm/internal/atomicfile"
)
func TestAtomicWriteFileReplacesContentsAndCleansTemporaryFile(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "config.json")
if err := os.WriteFile(path, []byte("old"), 0o644); err != nil {
t.Fatal(err)
}
if err := atomicfile.Write(path, []byte("new"), 0o644); err != nil {
t.Fatal(err)
}
data, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
if got := string(data); got != "new" {
t.Fatalf("settings contents = %q, want new", got)
}
matches, err := filepath.Glob(filepath.Join(dir, ".lensm-settings-*.tmp"))
if err != nil {
t.Fatal(err)
}
if len(matches) != 0 {
t.Fatalf("temporary settings files remain: %v", matches)
}
}