(t *testing.T)
| 471 | } |
| 472 | |
| 473 | func TestLocalMigration3(t *testing.T) { |
| 474 | // set up |
| 475 | db := database.InitTestMemoryDBRaw(t, "./fixtures/local-1-pre-schema.sql") |
| 476 | ctx := context.InitTestCtxWithDB(t, db) |
| 477 | data := testutils.MustMarshalJSON(t, actions.AddNoteDataV2{NoteUUID: "note-1-uuid", BookName: "js", Content: "note 1", Public: false}) |
| 478 | a1UUID := testutils.MustGenerateUUID(t) |
| 479 | database.MustExec(t, "inserting action", db, |
| 480 | "INSERT INTO actions (uuid, schema, type, data, timestamp) VALUES (?, ?, ?, ?, ?)", a1UUID, 2, "add_note", string(data), 1537829463) |
| 481 | |
| 482 | data = testutils.MustMarshalJSON(t, actions.RemoveNoteDataV1{NoteUUID: "note-1-uuid", BookName: "js"}) |
| 483 | a2UUID := testutils.MustGenerateUUID(t) |
| 484 | database.MustExec(t, "inserting action", db, |
| 485 | "INSERT INTO actions (uuid, schema, type, data, timestamp) VALUES (?, ?, ?, ?, ?)", a2UUID, 1, "remove_note", string(data), 1537829463) |
| 486 | |
| 487 | data = testutils.MustMarshalJSON(t, actions.RemoveNoteDataV1{NoteUUID: "note-2-uuid", BookName: "js"}) |
| 488 | a3UUID := testutils.MustGenerateUUID(t) |
| 489 | database.MustExec(t, "inserting action", db, |
| 490 | "INSERT INTO actions (uuid, schema, type, data, timestamp) VALUES (?, ?, ?, ?, ?)", a3UUID, 1, "remove_note", string(data), 1537829463) |
| 491 | |
| 492 | // Execute |
| 493 | tx, err := db.Begin() |
| 494 | if err != nil { |
| 495 | t.Fatal(errors.Wrap(err, "beginning a transaction")) |
| 496 | } |
| 497 | |
| 498 | err = lm3.run(ctx, tx) |
| 499 | if err != nil { |
| 500 | tx.Rollback() |
| 501 | t.Fatal(errors.Wrap(err, "failed to run")) |
| 502 | } |
| 503 | |
| 504 | tx.Commit() |
| 505 | |
| 506 | // Test |
| 507 | var actionCount int |
| 508 | database.MustScan(t, "counting actions", db.QueryRow("SELECT count(*) FROM actions"), &actionCount) |
| 509 | assert.Equal(t, actionCount, 3, "action count mismatch") |
| 510 | |
| 511 | var a1, a2, a3 actions.Action |
| 512 | var a1DataRaw, a2DataRaw, a3DataRaw string |
| 513 | database.MustScan(t, "getting action 1", db.QueryRow("SELECT schema, type, data, timestamp FROM actions WHERE uuid = ?", a1UUID), |
| 514 | &a1.Schema, &a1.Type, &a1DataRaw, &a1.Timestamp) |
| 515 | database.MustScan(t, "getting action 2", db.QueryRow("SELECT schema, type, data, timestamp FROM actions WHERE uuid = ?", a2UUID), |
| 516 | &a2.Schema, &a2.Type, &a2DataRaw, &a2.Timestamp) |
| 517 | database.MustScan(t, "getting action 3", db.QueryRow("SELECT schema, type, data, timestamp FROM actions WHERE uuid = ?", a3UUID), |
| 518 | &a3.Schema, &a3.Type, &a3DataRaw, &a3.Timestamp) |
| 519 | |
| 520 | var a1Data actions.AddNoteDataV2 |
| 521 | var a2Data, a3Data actions.RemoveNoteDataV2 |
| 522 | testutils.MustUnmarshalJSON(t, []byte(a1DataRaw), &a1Data) |
| 523 | testutils.MustUnmarshalJSON(t, []byte(a2DataRaw), &a2Data) |
| 524 | testutils.MustUnmarshalJSON(t, []byte(a3DataRaw), &a3Data) |
| 525 | |
| 526 | assert.Equal(t, a1.Schema, 2, "a1 schema mismatch") |
| 527 | assert.Equal(t, a1.Type, "add_note", "a1 type mismatch") |
| 528 | assert.Equal(t, a1.Timestamp, int64(1537829463), "a1 timestamp mismatch") |
| 529 | assert.Equal(t, a1Data.NoteUUID, "note-1-uuid", "a1 data note_uuid mismatch") |
| 530 | assert.Equal(t, a1Data.BookName, "js", "a1 data book_name mismatch") |
nothing calls this directly
no test coverage detected