Files
cmautobuy/admin/repository/inner_code_test.go
T

41 lines
1.3 KiB
Go
Raw Normal View History

package repository
import (
"database/sql"
"testing"
_ "modernc.org/sqlite"
)
func TestInterruptApplyingInnerCodes_只收敛回写中记录(t *testing.T) {
db, err := sql.Open("sqlite", "file:inner_code_interrupt?mode=memory&cache=shared")
if err != nil {
t.Fatal(err)
}
defer db.Close()
if _, err := db.Exec(`CREATE TABLE syb_inner_code_records (
id INTEGER PRIMARY KEY,status TEXT NOT NULL,result_message TEXT,updated_at TEXT NOT NULL
)`); err != nil {
t.Fatal(err)
}
if _, err := db.Exec(`INSERT INTO syb_inner_code_records(id,status,updated_at) VALUES
(1,'applying','old'),(2,'ready','old')`); err != nil {
t.Fatal(err)
}
count, err := InterruptApplyingInnerCodes(db, "2026-08-15T01:00:00Z")
if err != nil || count != 1 {
t.Fatalf("count=%d err=%v", count, err)
}
var status, message, updatedAt string
if err := db.QueryRow(`SELECT status,result_message,updated_at FROM syb_inner_code_records WHERE id=1`).
Scan(&status, &message, &updatedAt); err != nil {
t.Fatal(err)
}
if status != "needs_check" || message == "" || updatedAt != "2026-08-15T01:00:00Z" {
t.Fatalf("status=%s message=%q updated=%s", status, message, updatedAt)
}
if err := db.QueryRow(`SELECT status FROM syb_inner_code_records WHERE id=2`).Scan(&status); err != nil || status != "ready" {
t.Fatalf("ready 记录不应变化 status=%s err=%v", status, err)
}
}