added some tests to the image code
This commit is contained in:
parent
c9b6a7e6db
commit
8efd309a9c
@ -345,6 +345,68 @@ func Test_updatePiwigoIdIfAlreadyUploaded_with_image_to_check(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_uploadImages_saves_new_id_to_db(t *testing.T) {
|
||||||
|
mockCtrl := gomock.NewController(t)
|
||||||
|
defer mockCtrl.Finish()
|
||||||
|
|
||||||
|
img := ImageMetaData{
|
||||||
|
ImageId: 1,
|
||||||
|
PiwigoId: 0,
|
||||||
|
FullImagePath: "/nonexisting/file.jpg",
|
||||||
|
UploadRequired: true,
|
||||||
|
Md5Sum: "1234",
|
||||||
|
CategoryId: 2,
|
||||||
|
}
|
||||||
|
images := []ImageMetaData{img}
|
||||||
|
|
||||||
|
imgToSave := img
|
||||||
|
imgToSave.PiwigoId = 5
|
||||||
|
imgToSave.UploadRequired = false
|
||||||
|
|
||||||
|
dbmock := NewMockImageMetadataProvider(mockCtrl)
|
||||||
|
dbmock.EXPECT().ImageMetadataToUpload().Times(1).Return(images, nil)
|
||||||
|
dbmock.EXPECT().SaveImageMetadata(imgToSave).Times(1)
|
||||||
|
|
||||||
|
piwigomock := NewMockPiwigoImageApi(mockCtrl)
|
||||||
|
piwigomock.EXPECT().UploadImage(0, "/nonexisting/file.jpg", "1234", 2).Times(1).Return(5, nil)
|
||||||
|
|
||||||
|
err := uploadImages(piwigomock, dbmock)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_uploadImages_saves_same_id_to_db(t *testing.T) {
|
||||||
|
mockCtrl := gomock.NewController(t)
|
||||||
|
defer mockCtrl.Finish()
|
||||||
|
|
||||||
|
img := ImageMetaData{
|
||||||
|
ImageId: 1,
|
||||||
|
PiwigoId: 5,
|
||||||
|
FullImagePath: "/nonexisting/file.jpg",
|
||||||
|
UploadRequired: true,
|
||||||
|
Md5Sum: "1234",
|
||||||
|
CategoryId: 2,
|
||||||
|
}
|
||||||
|
images := []ImageMetaData{img}
|
||||||
|
|
||||||
|
imgToSave := img
|
||||||
|
imgToSave.UploadRequired = false
|
||||||
|
|
||||||
|
dbmock := NewMockImageMetadataProvider(mockCtrl)
|
||||||
|
dbmock.EXPECT().ImageMetadataToUpload().Times(1).Return(images, nil)
|
||||||
|
dbmock.EXPECT().SaveImageMetadata(imgToSave).Times(1)
|
||||||
|
|
||||||
|
piwigomock := NewMockPiwigoImageApi(mockCtrl)
|
||||||
|
piwigomock.EXPECT().UploadImage(5, "/nonexisting/file.jpg", "1234", 2).Times(1).Return(5, nil)
|
||||||
|
|
||||||
|
err := uploadImages(piwigomock, dbmock)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// test metadata store to store save the metadat and simulate the database
|
// test metadata store to store save the metadat and simulate the database
|
||||||
type testStore struct {
|
type testStore struct {
|
||||||
savedMetadata map[string]ImageMetaData
|
savedMetadata map[string]ImageMetaData
|
||||||
|
Loading…
Reference in New Issue
Block a user