MCPcopy Index your code
hub / github.com/dnote/dnote / TestStepSyncBook

Function TestStepSyncBook

pkg/cli/cmd/sync/sync_test.go:1278–1461  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1276}
1277
1278func TestStepSyncBook(t *testing.T) {
1279 t.Run("exists on server only", func(t *testing.T) {
1280 // set up
1281 db := database.InitTestMemoryDB(t)
1282
1283 b1UUID := testutils.MustGenerateUUID(t)
1284 database.MustExec(t, "inserting book", db, "INSERT INTO books (uuid, usn, label, dirty, deleted) VALUES (?, ?, ?, ?, ?)", b1UUID, 555, "b1-label", true, false)
1285
1286 // execute
1287 tx, err := db.Begin()
1288 if err != nil {
1289 t.Fatal(errors.Wrap(err, "beginning a transaction").Error())
1290 }
1291
1292 b2UUID := testutils.MustGenerateUUID(t)
1293 b := client.SyncFragBook{
1294 UUID: b2UUID,
1295 USN: 1,
1296 AddedOn: 1541108743,
1297 Label: "b2-label",
1298 Deleted: false,
1299 }
1300
1301 if err := stepSyncBook(tx, b); err != nil {
1302 tx.Rollback()
1303 t.Fatal(errors.Wrap(err, "executing").Error())
1304 }
1305
1306 tx.Commit()
1307
1308 // test
1309 var noteCount, bookCount int
1310 database.MustScan(t, "counting notes", db.QueryRow("SELECT count(*) FROM notes"), &noteCount)
1311 database.MustScan(t, "counting books", db.QueryRow("SELECT count(*) FROM books"), &bookCount)
1312
1313 assert.Equalf(t, noteCount, 0, "note count mismatch")
1314 assert.Equalf(t, bookCount, 2, "book count mismatch")
1315
1316 var b1, b2 database.Book
1317 database.MustScan(t, "getting b1",
1318 db.QueryRow("SELECT uuid, usn, label, dirty, deleted FROM books WHERE uuid = ?", b1UUID),
1319 &b1.UUID, &b1.USN, &b1.Label, &b1.Dirty, &b1.Deleted)
1320 database.MustScan(t, "getting b2",
1321 db.QueryRow("SELECT uuid, usn, label, dirty, deleted FROM books WHERE uuid = ?", b2UUID),
1322 &b2.UUID, &b2.USN, &b2.Label, &b2.Dirty, &b2.Deleted)
1323
1324 assert.Equal(t, b1.UUID, b1UUID, "b1 UUID mismatch")
1325 assert.Equal(t, b1.USN, 555, "b1 USN mismatch")
1326 assert.Equal(t, b1.Label, "b1-label", "b1 Label mismatch")
1327 assert.Equal(t, b1.Dirty, true, "b1 Dirty mismatch")
1328 assert.Equal(t, b1.Deleted, false, "b1 Deleted mismatch")
1329
1330 assert.Equal(t, b2.UUID, b2UUID, "b2 UUID mismatch")
1331 assert.Equal(t, b2.USN, b.USN, "b2 USN mismatch")
1332 assert.Equal(t, b2.Label, b.Label, "b2 Label mismatch")
1333 assert.Equal(t, b2.Dirty, false, "b2 Dirty mismatch")
1334 assert.Equal(t, b2.Deleted, b.Deleted, "b2 Deleted mismatch")
1335 })

Callers

nothing calls this directly

Calls 13

InitTestMemoryDBFunction · 0.92
MustGenerateUUIDFunction · 0.92
MustExecFunction · 0.92
MustScanFunction · 0.92
EqualfFunction · 0.92
EqualFunction · 0.92
stepSyncBookFunction · 0.85
fullSyncBookFunction · 0.85
BeginMethod · 0.65
RollbackMethod · 0.65
CommitMethod · 0.65
QueryRowMethod · 0.65

Tested by

no test coverage detected