Initial commit of Descrybe v2 without local scratch artifacts.
Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestResolveMySQLDumpPathExplicit(t *testing.T) {
|
||||
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) {
|
||||
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 TestMappedCoveragePct(t *testing.T) {
|
||||
c := mappedCoverage{Total: 200, WithDesc: 100, WithCat: 50, WithAttrs: 200}
|
||||
if c.pct(c.WithDesc) != 50 {
|
||||
t.Fatalf("desc pct=%v want 50", c.pct(c.WithDesc))
|
||||
}
|
||||
if c.pct(c.WithCat) != 25 {
|
||||
t.Fatalf("cat pct=%v want 25", c.pct(c.WithCat))
|
||||
}
|
||||
empty := mappedCoverage{}
|
||||
if empty.pct(1) != 0 {
|
||||
t.Fatalf("empty total should yield 0")
|
||||
}
|
||||
}
|
||||
|
||||
func TestScanA1ProcessedCategoriesKeepsDescriptionNullSafe(t *testing.T) {
|
||||
// Dump original description/attributes are often NULL; category must still map.
|
||||
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"])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user