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:
@@ -6,7 +6,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
pb "github.com/bergabruh/stats-gateway/gen/stats/v1"
|
||||
)
|
||||
@@ -63,12 +62,14 @@ func extractRows(ctx context.Context, db *sql.DB, sinceID int64) ([]extractedRow
|
||||
continue
|
||||
}
|
||||
|
||||
var tsUnix int64
|
||||
if ts.Valid {
|
||||
fmt.Sscanf(ts.String, "%d", &tsUnix)
|
||||
if !ts.Valid {
|
||||
log.Printf("skip id=%d: null timestamp", id)
|
||||
continue
|
||||
}
|
||||
if tsUnix == 0 {
|
||||
tsUnix = time.Now().Unix()
|
||||
var tsUnix int64
|
||||
if _, err := fmt.Sscanf(ts.String, "%d", &tsUnix); err != nil || tsUnix == 0 {
|
||||
log.Printf("skip id=%d: bad timestamp %q", id, ts.String)
|
||||
continue
|
||||
}
|
||||
|
||||
out = append(out, extractedRow{
|
||||
|
||||
Reference in New Issue
Block a user