added ImageMetadataToDelete to the datastore
added test if it selectes the records to delete added todo to refactor some image tests to use the generated mocks
This commit is contained in:
parent
5503a429c3
commit
560f5057ac
@ -38,6 +38,7 @@ func (img *ImageMetaData) String() string {
|
||||
type ImageMetadataProvider interface {
|
||||
ImageMetadata(fullImagePath string) (ImageMetaData, error)
|
||||
ImageMetadataToUpload() ([]ImageMetaData, error)
|
||||
ImageMetadataToDelete() ([]ImageMetaData, error)
|
||||
SaveImageMetadata(m ImageMetaData) error
|
||||
SavePiwigoIdAndUpdateUploadFlag(md5Sum string, piwigoId int) error
|
||||
}
|
||||
@ -98,6 +99,35 @@ func (d *localDataStore) ImageMetadata(fullImagePath string) (ImageMetaData, err
|
||||
return img, err
|
||||
}
|
||||
|
||||
func (d *localDataStore) ImageMetadataToDelete() ([]ImageMetaData, error) {
|
||||
logrus.Tracef("Query all image metadata that represent files queued to delete")
|
||||
|
||||
db, err := d.openDatabase()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
rows, err := db.Query("SELECT imageId, piwigoId, fullImagePath, fileName, md5sum, lastChanged, categoryPath, categoryId, uploadRequired, deleteRequired FROM image WHERE deleteRequired = 1")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
images := []ImageMetaData{}
|
||||
for rows.Next() {
|
||||
img := &ImageMetaData{}
|
||||
err = ReadImageMetadataFromRow(rows, img)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
images = append(images, *img)
|
||||
}
|
||||
err = rows.Err()
|
||||
|
||||
return images, err
|
||||
}
|
||||
|
||||
func (d *localDataStore) ImageMetadataToUpload() ([]ImageMetaData, error) {
|
||||
logrus.Tracef("Query all image metadata that represent files queued to upload")
|
||||
|
||||
|
@ -47,6 +47,21 @@ func (mr *MockImageMetadataProviderMockRecorder) ImageMetadata(arg0 interface{})
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ImageMetadata", reflect.TypeOf((*MockImageMetadataProvider)(nil).ImageMetadata), arg0)
|
||||
}
|
||||
|
||||
// ImageMetadataToDelete mocks base method
|
||||
func (m *MockImageMetadataProvider) ImageMetadataToDelete() ([]ImageMetaData, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ImageMetadataToDelete")
|
||||
ret0, _ := ret[0].([]ImageMetaData)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// ImageMetadataToDelete indicates an expected call of ImageMetadataToDelete
|
||||
func (mr *MockImageMetadataProviderMockRecorder) ImageMetadataToDelete() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ImageMetadataToDelete", reflect.TypeOf((*MockImageMetadataProvider)(nil).ImageMetadataToDelete))
|
||||
}
|
||||
|
||||
// ImageMetadataToUpload mocks base method
|
||||
func (m *MockImageMetadataProvider) ImageMetadataToUpload() ([]ImageMetaData, error) {
|
||||
m.ctrl.T.Helper()
|
||||
|
@ -105,6 +105,37 @@ func Test_save_and_query_for_upload_records_do_not_contain_images_to_delete(t *t
|
||||
EnsureMetadataAreEqual("toupload", img1, imgLoad, t)
|
||||
}
|
||||
|
||||
func Test_save_and_query_for_deleted_records_do_contain_images(t *testing.T) {
|
||||
if !dbinitOk {
|
||||
t.Skip("Skipping test as TestDataStoreInitialize failed!")
|
||||
}
|
||||
dataStore := setupDatabase(t)
|
||||
defer cleanupDatabase(t)
|
||||
|
||||
img1 := getExampleImageMetadata("blah/foo/bar.jpg")
|
||||
img1.UploadRequired = false
|
||||
img1.DeleteRequired = true
|
||||
|
||||
saveImageShouldNotFail("todelete", dataStore, img1, t)
|
||||
img1.ImageId = 1
|
||||
|
||||
images, err := dataStore.ImageMetadataToDelete()
|
||||
if err != nil {
|
||||
t.Fatalf("Could not query images to delete! %s", err)
|
||||
}
|
||||
|
||||
if len(images) > 1 {
|
||||
t.Fatal("Got more than one image to delete but only one is expected")
|
||||
}
|
||||
|
||||
if len(images) < 1 {
|
||||
t.Fatal("Got no image to delete but one is expected!")
|
||||
}
|
||||
|
||||
imgLoad := images[0]
|
||||
EnsureMetadataAreEqual("todelete", img1, imgLoad, t)
|
||||
}
|
||||
|
||||
func Test_load_metadata_not_found(t *testing.T) {
|
||||
if !dbinitOk {
|
||||
t.Skip("Skipping test as TestDataStoreInitialize failed!")
|
||||
|
@ -412,6 +412,7 @@ func Test_uploadImages_saves_same_id_to_db(t *testing.T) {
|
||||
}
|
||||
|
||||
// test metadata store to store save the metadat and simulate the database
|
||||
//TODO: refactor to use generated test implementation
|
||||
type testStore struct {
|
||||
savedMetadata map[string]ImageMetaData
|
||||
}
|
||||
@ -437,6 +438,10 @@ func (d *testStore) ImageMetadataToUpload() ([]ImageMetaData, error) {
|
||||
return nil, errors.New("N/A")
|
||||
}
|
||||
|
||||
func (d *testStore) ImageMetadataToDelete() ([]ImageMetaData, error) {
|
||||
return nil, errors.New("N/A")
|
||||
}
|
||||
|
||||
func (d *testStore) SavePiwigoIdAndUpdateUploadFlag(md5Sum string, piwigoId int) error {
|
||||
return errors.New("N/A")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user