44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestLoadOrCreateConfig(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), configFileName)
|
|
cfg, created, err := loadOrCreateConfig(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !created {
|
|
t.Fatal("expected configuration to be created")
|
|
}
|
|
if cfg.IntervalMinutes != 30 || cfg.MaxCacheCount != 10 || cfg.WallpaperStyle != "keep" {
|
|
t.Fatalf("unexpected defaults: %+v", cfg)
|
|
}
|
|
|
|
loaded, created, err := loadOrCreateConfig(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if created || loaded != cfg {
|
|
t.Fatalf("unexpected loaded config: %+v", loaded)
|
|
}
|
|
}
|
|
|
|
func TestConfigValidation(t *testing.T) {
|
|
cfg := defaultConfig()
|
|
if err := cfg.validate(true); err == nil {
|
|
t.Fatal("expected empty API URL to fail when required")
|
|
}
|
|
cfg.APIURL = "ftp://example.com/image.jpg"
|
|
if err := cfg.validate(false); err == nil {
|
|
t.Fatal("expected non-http URL to fail")
|
|
}
|
|
cfg.APIURL = "https://example.com/random"
|
|
if err := cfg.validate(true); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|