Skip to content

Commit ea860ac

Browse files
committed
Made new test leaner
1 parent 77f9a60 commit ea860ac

2 files changed

Lines changed: 28 additions & 32 deletions

File tree

tests/integration/db_changes_postgres_test.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -506,56 +506,45 @@ func TestSinker_Integration_ComplexDependentTableOrdering(t *testing.T) {
506506
postgresContainer,
507507
rawSQLInput(`
508508
CREATE TABLE IF NOT EXISTS %[1]s.departments (
509-
id TEXT PRIMARY KEY,
510-
name TEXT NOT NULL
509+
id TEXT PRIMARY KEY
511510
);
512511
CREATE TABLE IF NOT EXISTS %[1]s.employees (
513512
id TEXT PRIMARY KEY,
514-
name TEXT NOT NULL,
515513
department_id TEXT NOT NULL,
516-
manager_id TEXT,
517514
CONSTRAINT fk_department
518515
FOREIGN KEY(department_id)
519-
REFERENCES %[1]s.departments(id),
520-
CONSTRAINT fk_manager
521-
FOREIGN KEY(manager_id)
522-
REFERENCES %[1]s.employees(id)
516+
REFERENCES %[1]s.departments(id)
523517
);
524518
525519
-- Pre-existing data, like if the sinker had stopped at that point
526-
INSERT INTO %[1]s.departments (id, name) VALUES ('dept1', 'Engineering');
520+
INSERT INTO %[1]s.departments (id) VALUES ('dept1');
527521
`, testSchema),
528522
streamMock(
529523
dbChangesBlockData(t, "10a", finalBlock("10a"),
530-
insertRowSinglePK("employees", "emp1", "name", "Alice Manager", "department_id", "dept1"),
531-
insertRowSinglePK("departments", "dept2", "name", "Sales"),
532-
insertRowSinglePK("employees", "emp3", "name", "Carol Sales", "department_id", "dept2"),
524+
insertRowSinglePK("employees", "emp1", "department_id", "dept1"),
525+
insertRowSinglePK("departments", "dept2"),
526+
insertRowSinglePK("employees", "emp2", "department_id", "dept2"),
533527
),
534528
),
535529
func(t *testing.T, dbx *sqlx.DB) {
536530
type DepartmentRow struct {
537-
ID string `db:"id"`
538-
Name string `db:"name"`
531+
ID string `db:"id"`
539532
}
540533

541534
type EmployeeRow struct {
542-
ID string `db:"id"`
543-
Name string `db:"name"`
544-
DepartmentID string `db:"department_id"`
545-
ManagerID *string `db:"manager_id"`
535+
ID string `db:"id"`
536+
DepartmentID string `db:"department_id"`
546537
}
547538

548-
expectedDepts := []*DepartmentRow{
549-
{ID: "dept1", Name: "Engineering"},
550-
{ID: "dept2", Name: "Sales"},
551-
}
552-
require.Equal(t, expectedDepts, readDbChangesRows[DepartmentRow](t, dbx, "departments"))
539+
require.Equal(t, []*DepartmentRow{
540+
{ID: "dept1"},
541+
{ID: "dept2"},
542+
}, readDbChangesRows[DepartmentRow](t, dbx, "departments"))
553543

554-
expectedEmps := []*EmployeeRow{
555-
{ID: "emp1", Name: "Alice Manager", DepartmentID: "dept1", ManagerID: nil},
556-
{ID: "emp3", Name: "Carol Sales", DepartmentID: "dept2", ManagerID: nil},
557-
}
558-
require.Equal(t, expectedEmps, readDbChangesRows[EmployeeRow](t, dbx, "employees"))
544+
require.Equal(t, []*EmployeeRow{
545+
{ID: "emp1", DepartmentID: "dept1"},
546+
{ID: "emp2", DepartmentID: "dept2"},
547+
}, readDbChangesRows[EmployeeRow](t, dbx, "employees"))
559548
},
560549
"Block #10 (10a) - LIB #10 (10a)",
561550
)
@@ -769,6 +758,17 @@ func insertRowCompositePK(table string, pk map[string]string, fieldsAndValues ..
769758
}
770759
}
771760

761+
func updateRowSinglePK(table string, pk string, fieldsAndValues ...string) *pbdatabase.TableChange {
762+
return &pbdatabase.TableChange{
763+
Table: table,
764+
PrimaryKey: &pbdatabase.TableChange_Pk{
765+
Pk: pk,
766+
},
767+
Operation: pbdatabase.TableChange_OPERATION_UPDATE,
768+
Fields: getFields(fieldsAndValues...),
769+
}
770+
}
771+
772772
func upsertRowSinglePK(table string, pk string, fieldsAndValues ...string) *pbdatabase.TableChange {
773773
return &pbdatabase.TableChange{
774774
Table: table,

tests/integration/helpers_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,3 @@ func readDbChangesRows[T any](t *testing.T, db *sqlx.DB, table string) []*T {
386386

387387
return readRowsBy[T](t, db, fmt.Sprintf(`"%s"."%s"`, dbChangesSchemaName, table), "id")
388388
}
389-
390-
func ptr[T any](in T) *T {
391-
return &in
392-
}

0 commit comments

Comments
 (0)