Move config file to XDG config dir
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestConfigFilePathUsesXDGConfigDir(t *testing.T) {
|
||||
t.Setenv("HOME", t.TempDir())
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
|
||||
got, legacy, err := configFilePath()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := filepath.Join(os.Getenv("XDG_CONFIG_HOME"), "docspell-cli", "config.json")
|
||||
if got != want {
|
||||
t.Fatalf("expected %q, got %q", want, got)
|
||||
}
|
||||
if legacy != "" {
|
||||
t.Fatalf("expected no legacy fallback, got %q", legacy)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigFilePathFallsBackToLegacyHomeFile(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
xdg := filepath.Join(t.TempDir(), "config")
|
||||
t.Setenv("HOME", home)
|
||||
t.Setenv("XDG_CONFIG_HOME", xdg)
|
||||
legacyPath := filepath.Join(home, "docspell-cli.json")
|
||||
if err := os.WriteFile(legacyPath, []byte("{}"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
got, legacy, err := configFilePath()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != legacyPath {
|
||||
t.Fatalf("expected legacy path %q, got %q", legacyPath, got)
|
||||
}
|
||||
wantLegacy := filepath.Join(xdg, "docspell-cli", "config.json")
|
||||
if legacy != wantLegacy {
|
||||
t.Fatalf("expected XDG target %q, got %q", wantLegacy, legacy)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user