Skip to content

Commit 6333dd5

Browse files
committed
More tests.
1 parent c7ca877 commit 6333dd5

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

dialects_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,41 @@ func TestEnsureMigrationTableExistsSQLError(t *testing.T) {
9898

9999
assert.Error(t, d.EnsureMigrationTableExists(db, "test"), "expected error")
100100
}
101+
102+
func TestEnsureMigrationTableExistsCommitError(t *testing.T) {
103+
d := BaseDialect{
104+
CreateTemplate: `
105+
CREATE TABLE t0 (
106+
id INTEGER PRIMARY KEY
107+
);
108+
109+
CREATE TABLE t1 (
110+
id INTEGER PRIMARY KEY,
111+
parent_id INTEGER REFERENCES t0 (id) DEFERRABLE INITIALLY DEFERRED
112+
);
113+
114+
INSERT INTO t0 (id) VALUES (1);
115+
INSERT INTO t1 (id, parent_id) VALUES (1, 1);
116+
117+
-- %s catching argument
118+
DELETE FROM t0 WHERE id = 1;`,
119+
}
120+
121+
dbFile, dbFileErr := prepareDB()
122+
123+
if dbFileErr != nil {
124+
t.Errorf("DB file could not be created: %v", dbFileErr)
125+
} else {
126+
// defer func() { _ = os.Remove(dbFile) }()
127+
}
128+
129+
db, dbErr := sql.Open("sqlite", "file://"+dbFile+"?_pragma=foreign_keys(1)")
130+
131+
if dbErr != nil {
132+
t.Errorf("DB file could not be created: %v", dbErr)
133+
} else {
134+
defer func() { _ = db.Close() }()
135+
}
136+
137+
assert.Error(t, d.EnsureMigrationTableExists(db, "test"), "expected error")
138+
}

migration_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func prepareDB() (string, error) {
2121
var result string
2222

2323
dbFile, dbFileErr := os.CreateTemp("", "")
24+
// dbFile, dbFileErr := os.Create("testdb.sqlite")
2425

2526
if dbFileErr != nil {
2627
return "", dbFileErr

0 commit comments

Comments
 (0)