package appbackup

import (
	"os"
	"path/filepath"
	"testing"
)

// TestSharedContentGID pins the shared content group to 1000 (FileBrowser's gid + the apps' PUID/PGID).
func TestSharedContentGID(t *testing.T) {
	if SharedContentGID != 1000 {
		t.Errorf("SharedContentGID = %d, want 1000", SharedContentGID)
	}
}

// TestUserdataSkeleton_List asserts the locked skeleton subdir set.
func TestUserdataSkeleton_List(t *testing.T) {
	got := map[string]bool{}
	for _, s := range UserdataSkeleton() {
		got[s] = true
	}
	for _, want := range []string{
		"media/movies", "media/tv", "media/music", "media/audiobooks", "media/books",
		"media/comics", "media/photos", "downloads", "import/paperless", "import/calibre",
		"roms", "documents",
	} {
		if !got[want] {
			t.Errorf("skeleton missing %q", want)
		}
	}
}

// TestUserdataDir confirms the userdata root is a sibling under the namespace.
func TestUserdataDir(t *testing.T) {
	if got := UserdataDir("/mnt/felhom-usb"); got != filepath.Clean("/mnt/felhom-usb/userdata") {
		t.Errorf("UserdataDir = %q", got)
	}
}

// TestEnsureUserdataSkeleton_Structure: every skeleton dir is created (chown may fail off-root, which
// is ignored — dirs + setgid still land). Runs cross-platform.
func TestEnsureUserdataSkeleton_Structure(t *testing.T) {
	ns := t.TempDir()
	_ = EnsureUserdataSkeleton(ns) // ignore chown error on a non-root CI host
	base := UserdataDir(ns)
	for _, sub := range append([]string{""}, UserdataSkeleton()...) {
		p := filepath.Join(base, sub)
		if fi, err := os.Stat(p); err != nil || !fi.IsDir() {
			t.Errorf("skeleton dir missing: %s (%v)", p, err)
		}
	}
}
