This commit is contained in:
1 parent
9a6ec940f7
commit
fd32419371
114 files changed
+21997
-96
No files matched your search
@@ -0,0 +1,43 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLoadDefaultsAndServiceSelection(t *testing.T) {
|
||||
t.Setenv("DATABASE_URL", "postgres://media:media@localhost/mediadb")
|
||||
t.Setenv("MEDIA_SERVICE", "MediaKiosk")
|
||||
t.Setenv("SERVICE", "viewer")
|
||||
t.Setenv("MEDIA_ROOTS", `./media;./other-media`)
|
||||
t.Setenv("MAX_UPLOAD_BYTES", "2mb")
|
||||
t.Setenv("WEB_ROOT", "./webui")
|
||||
|
||||
cfg, err := Load()
|
||||
if err != nil {
|
||||
t.Fatalf("Load() error = %v", err)
|
||||
}
|
||||
if cfg.Service != Kiosk {
|
||||
t.Fatalf("service = %q, want %q", cfg.Service, Kiosk)
|
||||
}
|
||||
if len(cfg.MediaRoots) != 2 {
|
||||
t.Fatalf("media roots = %#v, want two roots", cfg.MediaRoots)
|
||||
}
|
||||
if cfg.MaxUploadBytes != 2*1024*1024 {
|
||||
t.Fatalf("max upload bytes = %d", cfg.MaxUploadBytes)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRequiresDatabase(t *testing.T) {
|
||||
t.Setenv("DATABASE_URL", "")
|
||||
if _, err := Load(); err == nil {
|
||||
t.Fatal("Load() succeeded without DATABASE_URL")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseBytesRejectsInvalidValues(t *testing.T) {
|
||||
for _, value := range []string{"-1", "nope", "1tb"} {
|
||||
if _, err := parseBytes(value); err == nil {
|
||||
t.Errorf("parseBytes(%q) succeeded", value)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user