Additional tests for 'ON CONFLICT DO NOTHING without conflict target does not appear in generated SQL' bug.

This commit is contained in:
go-jet 2024-03-24 13:02:23 +01:00
parent 60d8f15513
commit 39de87671e
5 changed files with 71 additions and 3 deletions

View file

@ -87,6 +87,24 @@ func TestInsertOnConflict(t *testing.T) {
t.Run("do nothing", func(t *testing.T) {
employee := model.Employee{EmployeeID: rand.Int31()}
stmt := Employee.INSERT(Employee.AllColumns).
MODEL(employee).
MODEL(employee).
ON_CONFLICT().DO_NOTHING()
testutils.AssertStatementSql(t, stmt, `
INSERT INTO test_sample.employee (employee_id, first_name, last_name, employment_date, manager_id)
VALUES ($1, $2, $3, $4, $5),
($6, $7, $8, $9, $10)
ON CONFLICT DO NOTHING;
`)
testutils.AssertExecAndRollback(t, stmt, db, 1)
requireLogged(t, stmt)
})
t.Run("do nothing with index", func(t *testing.T) {
employee := model.Employee{EmployeeID: rand.Int31()}
stmt := Employee.INSERT(Employee.AllColumns).
MODEL(employee).
MODEL(employee).
@ -207,6 +225,21 @@ ON CONFLICT (id) WHERE (id * 2) > 10 DO UPDATE
testutils.AssertExecAndRollback(t, stmt, db, 1)
})
t.Run("nil action removes ON CONFLICT clause", func(t *testing.T) {
employee := model.Employee{EmployeeID: rand.Int31()}
stmt := Employee.INSERT(Employee.AllColumns).
MODEL(employee).
ON_CONFLICT().DO_UPDATE(nil)
testutils.AssertStatementSql(t, stmt, `
INSERT INTO test_sample.employee (employee_id, first_name, last_name, employment_date, manager_id)
VALUES ($1, $2, $3, $4, $5);
`)
testutils.AssertExecAndRollback(t, stmt, db, 1)
requireLogged(t, stmt)
})
}
func TestInsertModelObject(t *testing.T) {