-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathapp_settings_test.go
More file actions
76 lines (66 loc) · 1.94 KB
/
Copy pathapp_settings_test.go
File metadata and controls
76 lines (66 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"os"
"path/filepath"
"testing"
)
func TestGetSettingsIncludesDefaultWallpaperFolder(t *testing.T) {
configHome := t.TempDir()
home := t.TempDir()
t.Setenv("XDG_CONFIG_HOME", configHome)
t.Setenv("HOME", home)
settings := NewApp().GetSettings()
got, ok := settings[wallpaperFolderSetting].(string)
if !ok {
t.Fatalf("wallpaper folder type = %T; want string", settings[wallpaperFolderSetting])
}
want := filepath.Join(home, "Wallpapers")
if got != want {
t.Errorf("wallpaper folder = %q; want %q", got, want)
}
}
func TestScanLocalWallpapersUsesConfiguredFolder(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
folder := t.TempDir()
nested := filepath.Join(folder, "landscapes")
if err := os.Mkdir(nested, 0o755); err != nil {
t.Fatal(err)
}
imagePath := filepath.Join(nested, "mountain.png")
if err := os.WriteFile(imagePath, []byte("image"), 0o644); err != nil {
t.Fatal(err)
}
app := NewApp()
if err := app.SaveSettings(map[string]interface{}{
wallpaperFolderSetting: folder,
}); err != nil {
t.Fatal(err)
}
wallpapers, err := app.ScanLocalWallpapers()
if err != nil {
t.Fatal(err)
}
if len(wallpapers) != 1 {
t.Fatalf("wallpaper count = %d; want 1", len(wallpapers))
}
if wallpapers[0].Path != imagePath {
t.Errorf("wallpaper path = %q; want %q", wallpapers[0].Path, imagePath)
}
wantName := filepath.Join("landscapes", "mountain.png")
if wallpapers[0].Name != wantName {
t.Errorf("wallpaper name = %q; want %q", wallpapers[0].Name, wantName)
}
}
func TestScanLocalWallpapersReportsMissingConfiguredFolder(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
app := NewApp()
missing := filepath.Join(t.TempDir(), "missing")
if err := app.SaveSettings(map[string]interface{}{
wallpaperFolderSetting: missing,
}); err != nil {
t.Fatal(err)
}
if _, err := app.ScanLocalWallpapers(); err == nil {
t.Fatal("ScanLocalWallpapers() error = nil; want missing folder error")
}
}