MCPcopy
hub / github.com/dnote/dnote / TestLocalMigration14

Function TestLocalMigration14

pkg/cli/migrate/migrate_test.go:1099–1144  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1097}
1098
1099func TestLocalMigration14(t *testing.T) {
1100 // set up
1101 db := database.InitTestMemoryDBRaw(t, "./fixtures/local-14-pre-schema.sql")
1102 ctx := context.InitTestCtxWithDB(t, db)
1103
1104 b1UUID := testutils.MustGenerateUUID(t)
1105 database.MustExec(t, "inserting book", db, "INSERT INTO books (uuid, label) VALUES (?, ?)", b1UUID, "b1")
1106
1107 n1UUID := testutils.MustGenerateUUID(t)
1108 database.MustExec(t, "inserting note", db, `INSERT INTO notes
1109 (uuid, book_uuid, body, added_on, edited_on, public, dirty, usn, deleted) VALUES
1110 (?, ?, ?, ?, ?, ?, ?, ?, ?)`, n1UUID, b1UUID, "test note", 1, 2, true, false, 0, false)
1111
1112 // Execute
1113 tx, err := db.Begin()
1114 if err != nil {
1115 t.Fatal(errors.Wrap(err, "beginning a transaction"))
1116 }
1117
1118 err = lm14.run(ctx, tx)
1119 if err != nil {
1120 tx.Rollback()
1121 t.Fatal(errors.Wrap(err, "failed to run"))
1122 }
1123
1124 tx.Commit()
1125
1126 // Test - verify public column was dropped by checking column names
1127 rows, err := db.Query("SELECT name FROM pragma_table_info('notes')")
1128 if err != nil {
1129 t.Fatal(errors.Wrap(err, "getting table info"))
1130 }
1131 defer rows.Close()
1132
1133 for rows.Next() {
1134 var name string
1135 err := rows.Scan(&name)
1136 if err != nil {
1137 t.Fatal(errors.Wrap(err, "scanning column name"))
1138 }
1139
1140 if name == "public" {
1141 t.Fatal("public column still exists after migration")
1142 }
1143 }
1144}
1145
1146func TestRemoteMigration1(t *testing.T) {
1147 // set up

Callers

nothing calls this directly

Calls 9

InitTestMemoryDBRawFunction · 0.92
InitTestCtxWithDBFunction · 0.92
MustGenerateUUIDFunction · 0.92
MustExecFunction · 0.92
BeginMethod · 0.65
RollbackMethod · 0.65
CommitMethod · 0.65
QueryMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected