cmd/speedtest-sync: fail-fast on bad timestamps + minor cleanups

- Skip rows with null/malformed timestamps instead of silently
  re-stamping with time.Now() (data corruption hidden behind a
  fallback). Drops the time import.
- Replace ad-hoc parentDir() with stdlib filepath.Dir().
- Add t.Fatal error checks to TestExtractRows_SkipsBadExtra
  (CREATE TABLE / INSERT) and switch sql.Open to checked form.
- New TestExtractRows_SkipsBadTimestamp covers the null-ts path.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
BergaBruh
2026-05-09 18:53:34 +05:00
parent 367db68837
commit e6f1f63b8d
3 changed files with 53 additions and 21 deletions
+2 -10
View File
@@ -6,6 +6,7 @@ import (
"flag"
"log"
"os"
"path/filepath"
"strconv"
"time"
@@ -99,17 +100,8 @@ func readCursor(path string) int64 {
}
func writeCursor(path string, id int64) error {
if err := os.MkdirAll(parentDir(path), 0o755); err != nil {
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
return err
}
return os.WriteFile(path, []byte(strconv.FormatInt(id, 10)), 0o600)
}
func parentDir(p string) string {
for i := len(p) - 1; i >= 0; i-- {
if p[i] == '/' {
return p[:i]
}
}
return "."
}