30 lines
1.2 KiB
Go
30 lines
1.2 KiB
Go
package mariadb
|
|
|
|
import "testing"
|
|
|
|
func TestSnapshotTriggerReferences(t *testing.T) {
|
|
for _, tt := range []struct {
|
|
name, body, mode string
|
|
fail bool
|
|
}{
|
|
{"local", "INSERT INTO audit VALUES (NEW.id, OLD.value)", "", false},
|
|
{"local qualified", "UPDATE `example`.`audit` SET id=NEW.id", "", false},
|
|
{"alias", "SELECT 1 FROM audit a WHERE a.id=OLD.id", "", false},
|
|
{"literal", "INSERT INTO audit VALUES ('example.com', '$.field', 'UPDATE other.audit')", "", false},
|
|
{"comment", "/* UPDATE other.audit */ INSERT INTO audit VALUES (NEW.id)", "", false},
|
|
{"external write", "UPDATE other.audit SET id=NEW.id", "", true},
|
|
{"external insert", "INSERT INTO `other`.`audit` VALUES (NEW.id)", "", true},
|
|
{"ANSI external", `UPDATE "other"."audit" SET id=NEW.id`, "ANSI_QUOTES", true},
|
|
{"external function", "SET NEW.value=other.example(NEW.value)", "", true},
|
|
{"routine", "CALL example.change_rows()", "", true},
|
|
{"executable", "/*!50000 UPDATE other.audit SET id=1 */", "", true},
|
|
} {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
err := validateSnapshotTriggerReferences(snapshotTrigger{Name: "example", Body: tt.body, SQLMode: tt.mode}, "example")
|
|
if (err != nil) != tt.fail {
|
|
t.Fatalf("error=%v", err)
|
|
}
|
|
})
|
|
}
|
|
}
|