mirror of
https://git.evilfox.cc/test2/wg.git
synced 2026-07-31 20:03:22 +00:00
45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
package mysqlimport
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseDump(t *testing.T) {
|
|
path := `D:\Новая папка (10)\wg\wg.sql`
|
|
raw, err := os.ReadFile(path)
|
|
if err != nil {
|
|
t.Skip(err)
|
|
}
|
|
text := string(raw)
|
|
counts := map[string]int{}
|
|
for _, m := range reInsert.FindAllStringSubmatch(text, -1) {
|
|
table := m[1]
|
|
rows, err := splitValueTuples(m[2])
|
|
if err != nil {
|
|
t.Fatalf("%s: %v", table, err)
|
|
}
|
|
for _, row := range rows {
|
|
cols, err := tableColumns(table)
|
|
if err != nil {
|
|
t.Fatalf("cols %s: %v", table, err)
|
|
}
|
|
vals, err := parseRowValues(row)
|
|
if err != nil {
|
|
t.Fatalf("row %s: %v", table, err)
|
|
}
|
|
if len(vals) != len(cols) {
|
|
t.Fatalf("%s col mismatch got=%d want=%d sample=%s", table, len(vals), len(cols), truncate(row, 100))
|
|
}
|
|
}
|
|
counts[table] += len(rows)
|
|
}
|
|
if counts["wg_configs"] < 1 {
|
|
t.Fatalf("expected wg_configs rows, got %+v", counts)
|
|
}
|
|
if counts["users"] < 1 {
|
|
t.Fatalf("expected users rows, got %+v", counts)
|
|
}
|
|
t.Logf("counts: %+v", counts)
|
|
}
|