package main import ( "database/sql" "fmt" "testing" ) func TestMobileNumbering(t *testing.T) { cases := []struct { uid int64 want string }{ {30000001, "19900000001"}, {30000050, "19900000050"}, {30001000, "19900001000"}, } for _, c := range cases { got := formatMobile(c.uid) if got != c.want { t.Errorf("formatMobile(%d) = %q, want %q", c.uid, got, c.want) } } } func formatMobile(uid int64) string { return fmt.Sprintf("199%08d", uid-LoadtestUserMin+1) } func TestSequenceMapping(t *testing.T) { cases := map[string]string{ "users": "users_id_seq", "stars": "stars_star_id_seq", "booth_slots": "booth_slots_slot_id_seq", } for tbl, want := range cases { got, ok := loadtestSeqs[tbl] if !ok { t.Errorf("table %s not in loadtestSeqs", tbl) continue } if got != want { t.Errorf("seq for %s = %q, want %q", tbl, got, want) } } } func TestPKColumnMapping(t *testing.T) { cases := map[string]string{ "users": "id", "stars": "star_id", "booth_slots": "slot_id", "assets": "id", } for tbl, want := range cases { got, ok := pkColumns[tbl] if !ok { t.Errorf("table %s not in pkColumns", tbl) continue } if got != want { t.Errorf("pk for %s = %q, want %q", tbl, got, want) } } } func TestCleanupRejectsInvalidStarID(t *testing.T) { db, _ := sql.Open("postgres", "host=localhost sslmode=disable") defer db.Close() err := Cleanup(db, 87, false) if err == nil { t.Fatal("expected error for non-loadtest star_id, got nil") } } func TestJoinInt64(t *testing.T) { cases := []struct { in []int64 want string }{ {nil, ""}, {[]int64{42}, "42"}, {[]int64{1, 2, 3}, "1;2;3"}, } for _, c := range cases { got := joinInt64(c.in) if got != c.want { t.Errorf("joinInt64(%v) = %q, want %q", c.in, got, c.want) } } }