(t *testing.T)
| 868 | } |
| 869 | |
| 870 | func TestFullSyncBook(t *testing.T) { |
| 871 | t.Run("exists on server only", func(t *testing.T) { |
| 872 | // set up |
| 873 | db := database.InitTestMemoryDB(t) |
| 874 | |
| 875 | b1UUID := testutils.MustGenerateUUID(t) |
| 876 | database.MustExec(t, "inserting book", db, "INSERT INTO books (uuid, usn, label, dirty, deleted) VALUES (?, ?, ?, ?, ?)", b1UUID, 555, "b1-label", true, false) |
| 877 | |
| 878 | // execute |
| 879 | tx, err := db.Begin() |
| 880 | if err != nil { |
| 881 | t.Fatal(errors.Wrap(err, "beginning a transaction").Error()) |
| 882 | } |
| 883 | |
| 884 | b2UUID := testutils.MustGenerateUUID(t) |
| 885 | b := client.SyncFragBook{ |
| 886 | UUID: b2UUID, |
| 887 | USN: 1, |
| 888 | AddedOn: 1541108743, |
| 889 | Label: "b2-label", |
| 890 | Deleted: false, |
| 891 | } |
| 892 | |
| 893 | if err := fullSyncBook(tx, b); err != nil { |
| 894 | tx.Rollback() |
| 895 | t.Fatal(errors.Wrap(err, "executing").Error()) |
| 896 | } |
| 897 | |
| 898 | tx.Commit() |
| 899 | |
| 900 | // test |
| 901 | var noteCount, bookCount int |
| 902 | database.MustScan(t, "counting notes", db.QueryRow("SELECT count(*) FROM notes"), ¬eCount) |
| 903 | database.MustScan(t, "counting books", db.QueryRow("SELECT count(*) FROM books"), &bookCount) |
| 904 | |
| 905 | assert.Equalf(t, noteCount, 0, "note count mismatch") |
| 906 | assert.Equalf(t, bookCount, 2, "book count mismatch") |
| 907 | |
| 908 | var b1, b2 database.Book |
| 909 | database.MustScan(t, "getting b1", |
| 910 | db.QueryRow("SELECT uuid, usn, label, dirty, deleted FROM books WHERE uuid = ?", b1UUID), |
| 911 | &b1.UUID, &b1.USN, &b1.Label, &b1.Dirty, &b1.Deleted) |
| 912 | database.MustScan(t, "getting b2", |
| 913 | db.QueryRow("SELECT uuid, usn, label, dirty, deleted FROM books WHERE uuid = ?", b2UUID), |
| 914 | &b2.UUID, &b2.USN, &b2.Label, &b2.Dirty, &b2.Deleted) |
| 915 | |
| 916 | assert.Equal(t, b1.UUID, b1UUID, "b1 UUID mismatch") |
| 917 | assert.Equal(t, b1.USN, 555, "b1 USN mismatch") |
| 918 | assert.Equal(t, b1.Label, "b1-label", "b1 Label mismatch") |
| 919 | assert.Equal(t, b1.Dirty, true, "b1 Dirty mismatch") |
| 920 | assert.Equal(t, b1.Deleted, false, "b1 Deleted mismatch") |
| 921 | |
| 922 | assert.Equal(t, b2.UUID, b2UUID, "b2 UUID mismatch") |
| 923 | assert.Equal(t, b2.USN, b.USN, "b2 USN mismatch") |
| 924 | assert.Equal(t, b2.Label, b.Label, "b2 Label mismatch") |
| 925 | assert.Equal(t, b2.Dirty, false, "b2 Dirty mismatch") |
| 926 | assert.Equal(t, b2.Deleted, b.Deleted, "b2 Deleted mismatch") |
| 927 | }) |
nothing calls this directly
no test coverage detected