(t *testing.T)
| 2910 | } |
| 2911 | |
| 2912 | func TestCheckBookPristine(t *testing.T) { |
| 2913 | // set up |
| 2914 | db := database.InitTestMemoryDB(t) |
| 2915 | |
| 2916 | database.MustExec(t, "inserting b1", db, "INSERT INTO books (uuid, label, usn, dirty) VALUES (?, ?, ?, ?)", "b1-uuid", "b1-label", 5, false) |
| 2917 | database.MustExec(t, "inserting b2", db, "INSERT INTO books (uuid, label, usn, dirty) VALUES (?, ?, ?, ?)", "b2-uuid", "b2-label", 6, false) |
| 2918 | database.MustExec(t, "inserting n1", db, "INSERT INTO notes (uuid, book_uuid, added_on, body, dirty) VALUES (?, ?, ?, ?, ?)", "n1-uuid", "b1-uuid", 1541108743, "n1 body", false) |
| 2919 | database.MustExec(t, "inserting n2", db, "INSERT INTO notes (uuid, book_uuid, added_on, body, dirty) VALUES (?, ?, ?, ?, ?)", "n2-uuid", "b1-uuid", 1541108743, "n2 body", false) |
| 2920 | database.MustExec(t, "inserting n3", db, "INSERT INTO notes (uuid, book_uuid, added_on, body, dirty) VALUES (?, ?, ?, ?, ?)", "n3-uuid", "b1-uuid", 1541108743, "n3 body", true) |
| 2921 | database.MustExec(t, "inserting n4", db, "INSERT INTO notes (uuid, book_uuid, added_on, body, dirty) VALUES (?, ?, ?, ?, ?)", "n4-uuid", "b2-uuid", 1541108743, "n4 body", false) |
| 2922 | database.MustExec(t, "inserting n5", db, "INSERT INTO notes (uuid, book_uuid, added_on, body, dirty) VALUES (?, ?, ?, ?, ?)", "n5-uuid", "b2-uuid", 1541108743, "n5 body", false) |
| 2923 | |
| 2924 | t.Run("b1", func(t *testing.T) { |
| 2925 | // execute |
| 2926 | tx, err := db.Begin() |
| 2927 | if err != nil { |
| 2928 | t.Fatal(errors.Wrap(err, "beginning a transaction").Error()) |
| 2929 | } |
| 2930 | got, err := checkNotesPristine(tx, "b1-uuid") |
| 2931 | if err != nil { |
| 2932 | tx.Rollback() |
| 2933 | t.Fatal(errors.Wrap(err, "executing").Error()) |
| 2934 | } |
| 2935 | |
| 2936 | tx.Commit() |
| 2937 | |
| 2938 | // test |
| 2939 | assert.Equal(t, got, false, "b1 should not be pristine") |
| 2940 | }) |
| 2941 | |
| 2942 | t.Run("b2", func(t *testing.T) { |
| 2943 | // execute |
| 2944 | tx, err := db.Begin() |
| 2945 | if err != nil { |
| 2946 | t.Fatal(errors.Wrap(err, "beginning a transaction").Error()) |
| 2947 | } |
| 2948 | got, err := checkNotesPristine(tx, "b2-uuid") |
| 2949 | if err != nil { |
| 2950 | tx.Rollback() |
| 2951 | t.Fatal(errors.Wrap(err, "executing").Error()) |
| 2952 | } |
| 2953 | |
| 2954 | tx.Commit() |
| 2955 | |
| 2956 | // test |
| 2957 | assert.Equal(t, got, true, "b2 should be pristine") |
| 2958 | }) |
| 2959 | } |
| 2960 | |
| 2961 | func TestCheckNoteInList(t *testing.T) { |
| 2962 | list := syncList{ |
nothing calls this directly
no test coverage detected