Files
descrybe/apps/api/internal/processing/mysql_dump_path_test.go
T
2026-08-16 18:36:56 +02:00

66 lines
1.7 KiB
Go

package processing
import (
"os"
"path/filepath"
"strings"
"testing"
)
func TestResolveMySQLDumpPathExplicit(t *testing.T) {
t.Parallel()
dir := t.TempDir()
p := filepath.Join(dir, "descrybe_new.sql")
if err := os.WriteFile(p, []byte("-- dump\n"), 0o644); err != nil {
t.Fatal(err)
}
got := ResolveMySQLDumpPath(p)
if got != p {
t.Fatalf("got %q want %q", got, p)
}
}
func TestResolveMySQLDumpPathMissingExplicitFallsBack(t *testing.T) {
dir := t.TempDir()
want := filepath.Join(dir, "descrybe_new (1).sql")
if err := os.WriteFile(want, []byte("-- dump\n"), 0o644); err != nil {
t.Fatal(err)
}
t.Setenv("SEED_A1_MYSQL_DUMP", want)
got := ResolveMySQLDumpPath(filepath.Join(dir, "missing.sql"))
if got != want {
t.Fatalf("got %q want fallback %q", got, want)
}
}
func TestMySQLDumpCandidatesIncludeDownloadsName(t *testing.T) {
t.Parallel()
found := false
for _, c := range MySQLDumpCandidates() {
if filepath.Base(c) == "descrybe_new (1).sql" {
found = true
break
}
}
if !found {
t.Fatal("expected Downloads/descrybe_new (1).sql among candidates")
}
}
func TestScanA1ProcessedCategoriesKeepsDescriptionNullSafe(t *testing.T) {
t.Parallel()
const legacy = "97e1a309-3d23-4aa2-b518-8e8d7afdfec7"
dump := strings.Join([]string{
"INSERT INTO `processed_products` VALUES",
"(1,\t'u',\t'790069217715',\t'Name',\t'103',\tNULL,\t'<p>ai</p>',\tNULL,\tNULL,\t'completed',\tNULL,\t0,\t'2026-01-01 00:00:00',\t'2026-01-01 00:00:00',\t1,\t'" + legacy + "',\t1);",
"CREATE TABLE `x` (",
}, "\n")
got, err := ScanA1ProcessedCategories(strings.NewReader(dump), legacy)
if err != nil {
t.Fatal(err)
}
if got["790069217715"] != "103" {
t.Fatalf("category=%q want 103", got["790069217715"])
}
}