package main

import (
	"path/filepath"
	"testing"
)

func TestLoadAppConfigUsesEnvironment(t *testing.T) {
	t.Setenv("PEGASUS_MEDIA_ROOT", "/srv/media")
	t.Setenv("PEGASUS_USER_MAP_FILE", "/cfg/user-map.yaml")
	t.Setenv("PEGASUS_TUS_DIR", "")

	cfg := loadAppConfig()
	if cfg.mediaRoot != "/srv/media" {
		t.Fatalf("unexpected media root %q", cfg.mediaRoot)
	}
	if cfg.userMapFile != "/cfg/user-map.yaml" {
		t.Fatalf("unexpected user map file %q", cfg.userMapFile)
	}
	if cfg.tusDir != filepath.Join("/srv/media", ".pegasus-tus") {
		t.Fatalf("unexpected tus dir %q", cfg.tusDir)
	}
	if cfg.jf == nil {
		t.Fatalf("expected jellyfin client")
	}
}
