(t *testing.T)
| 244 | } |
| 245 | |
| 246 | func TestRun_up_to_date(t *testing.T) { |
| 247 | testCases := []struct { |
| 248 | mode int |
| 249 | schemaKey string |
| 250 | }{ |
| 251 | { |
| 252 | mode: LocalMode, |
| 253 | schemaKey: consts.SystemSchema, |
| 254 | }, |
| 255 | { |
| 256 | mode: RemoteMode, |
| 257 | schemaKey: consts.SystemRemoteSchema, |
| 258 | }, |
| 259 | } |
| 260 | |
| 261 | for _, tc := range testCases { |
| 262 | func() { |
| 263 | // set up |
| 264 | db := initTestDBNoMigration(t) |
| 265 | ctx := context.InitTestCtxWithDB(t, db) |
| 266 | |
| 267 | database.MustExec(t, "creating a temporary table for testing", db, |
| 268 | "CREATE TABLE migrate_run_test ( name string )") |
| 269 | |
| 270 | database.MustExec(t, "inserting a schema", db, "INSERT INTO system (key, value) VALUES (?, ?)", tc.schemaKey, 3) |
| 271 | |
| 272 | sequence := []migration{ |
| 273 | { |
| 274 | name: "v1", |
| 275 | run: func(ctx context.DnoteCtx, db *database.DB) error { |
| 276 | database.MustExec(t, "marking v1 completed", db, "INSERT INTO migrate_run_test (name) VALUES (?)", "v1") |
| 277 | return nil |
| 278 | }, |
| 279 | }, |
| 280 | { |
| 281 | name: "v2", |
| 282 | run: func(ctx context.DnoteCtx, db *database.DB) error { |
| 283 | database.MustExec(t, "marking v2 completed", db, "INSERT INTO migrate_run_test (name) VALUES (?)", "v2") |
| 284 | return nil |
| 285 | }, |
| 286 | }, |
| 287 | { |
| 288 | name: "v3", |
| 289 | run: func(ctx context.DnoteCtx, db *database.DB) error { |
| 290 | database.MustExec(t, "marking v3 completed", db, "INSERT INTO migrate_run_test (name) VALUES (?)", "v3") |
| 291 | return nil |
| 292 | }, |
| 293 | }, |
| 294 | } |
| 295 | |
| 296 | // execute |
| 297 | err := Run(ctx, sequence, tc.mode) |
| 298 | if err != nil { |
| 299 | t.Fatal(errors.Wrap(err, "failed to run")) |
| 300 | } |
| 301 | |
| 302 | // test |
| 303 | var schema int |
nothing calls this directly
no test coverage detected