From 390a60418fd4d74efabcd3743f6297d6fb072532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=A4felfinger?= Date: Wed, 20 Mar 2019 00:33:53 +0100 Subject: [PATCH] added unittest to test upload required in datastore -> probably not a good idea to set the flag here ;-) --- internal/app/datastore_test.go | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/internal/app/datastore_test.go b/internal/app/datastore_test.go index 471f2d7..72944b4 100644 --- a/internal/app/datastore_test.go +++ b/internal/app/datastore_test.go @@ -119,17 +119,43 @@ func TestUpdatePiwigoIdByChecksum(t *testing.T) { filePath := "blah/foo/bar.jpg" img := getExampleImageMetadata(filePath) - saveImageShouldNotFail("insert", dataStore, img, t) + saveImageShouldNotFail("SavePiwigoIdAndUpdateUploadFlag", dataStore, img, t) img.ImageId = 1 img.PiwigoId = 1234 + img.UploadRequired = false err := dataStore.SavePiwigoIdAndUpdateUploadFlag(img.Md5Sum, img.PiwigoId) if err != nil { - t.Errorf("SavePiwigoId: Could not update piwigo id: %s", err) + t.Errorf("SavePiwigoIdAndUpdateUploadFlag: Could not update piwigo id: %s", err) } imgLoad := loadMetadataShouldNotFail("update", dataStore, filePath, t) - EnsureMetadataAreEqual("update", img, imgLoad, t) + EnsureMetadataAreEqual("SavePiwigoIdAndUpdateUploadFlag", img, imgLoad, t) + + cleanupDatabase(t) +} + +func TestUpdatePiwigoIdByChecksumFoundNoImage(t *testing.T) { + if !dbinitOk { + t.Skip("Skipping test as TestDataStoreInitialize failed!") + } + dataStore := setupDatabase(t) + + filePath := "blah/foo/bar.jpg" + img := getExampleImageMetadata(filePath) + + saveImageShouldNotFail("SavePiwigoIdAndUpdateUploadFlag", dataStore, img, t) + img.ImageId = 1 + img.PiwigoId = 0 + img.UploadRequired = true + + err := dataStore.SavePiwigoIdAndUpdateUploadFlag(img.Md5Sum, img.PiwigoId) + if err != nil { + t.Errorf("SavePiwigoIdAndUpdateUploadFlag: Could not update piwigo id: %s", err) + } + + imgLoad := loadMetadataShouldNotFail("update", dataStore, filePath, t) + EnsureMetadataAreEqual("SavePiwigoIdAndUpdateUploadFlag", img, imgLoad, t) cleanupDatabase(t) }