package store

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

func TestMigrationsDirUsesEnvOverrideWhenValid(t *testing.T) {
	tempDir := t.TempDir()
	customDir := filepath.Join(tempDir, "migrations")
	if err := os.MkdirAll(customDir, 0o755); err != nil {
		t.Fatalf("create temp migrations dir: %v", err)
	}

	t.Setenv("DB_MIGRATIONS_DIR", customDir)
	if got := migrationsDir(); got != customDir {
		t.Fatalf("migrationsDir() = %q, want %q", got, customDir)
	}
}

func TestMigrationsDirFallsBackWhenEnvOverrideIsInvalid(t *testing.T) {
	t.Setenv("DB_MIGRATIONS_DIR", filepath.Join(t.TempDir(), "missing"))
	got := migrationsDir()
	if got == "" {
		t.Fatal("migrationsDir() should never return empty path")
	}
}
