diff --git a/internal/pkg/category/category.go b/internal/pkg/category/category.go index 31db69b..bda3669 100644 --- a/internal/pkg/category/category.go +++ b/internal/pkg/category/category.go @@ -16,7 +16,9 @@ import ( "sort" ) -func SynchronizePiwigoCategories(piwigoApi piwigo.PiwigoCategoryApi, db datastore.CategoryProvider) error { +func updatePiwigoCategoriesFromServer(piwigoApi piwigo.PiwigoCategoryApi, db datastore.CategoryProvider) error { + logrus.Debug("Entering updatePiwigoCategoriesFromServer") + defer logrus.Debug("Leaving updatePiwigoCategoriesFromServer") categories, err := piwigoApi.GetAllCategories() if err != nil { @@ -24,12 +26,11 @@ func SynchronizePiwigoCategories(piwigoApi piwigo.PiwigoCategoryApi, db datastor } for _, pwgcat := range categories { - dbcat, err := db.GetCategoryByPiwigoId(pwgcat.Id) if err == datastore.ErrorRecordNotFound { logrus.Debugf("Adding category %s", pwgcat.Key) dbcat = datastore.CategoryData{ - PiwigoId: pwgcat.Id, + PiwigoId: pwgcat.Id, } } else if err != nil { return err diff --git a/internal/pkg/category/category_test.go b/internal/pkg/category/category_test.go index bd6b1d2..2b0f600 100644 --- a/internal/pkg/category/category_test.go +++ b/internal/pkg/category/category_test.go @@ -15,7 +15,7 @@ import ( //go:generate mockgen -destination=./piwigo_mock_test.go -package=category git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/piwigo PiwigoApi,PiwigoCategoryApi,PiwigoImageApi //go:generate mockgen -destination=./datastore_mock_test.go -package=category git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/datastore CategoryProvider -func Test_SynchronizePiwigoCategories_adds_new_categories(t *testing.T) { +func Test_updatePiwigoCategoriesFromServer_adds_new_categories(t *testing.T) { mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() @@ -31,13 +31,13 @@ func Test_SynchronizePiwigoCategories_adds_new_categories(t *testing.T) { piwigoMock := NewMockPiwigoCategoryApi(mockCtrl) piwigoMock.EXPECT().GetAllCategories().Return(piwigoCategories, nil).Times(1) - err := SynchronizePiwigoCategories(piwigoMock, dbmock) + err := updatePiwigoCategoriesFromServer(piwigoMock, dbmock) if err != nil { t.Error(err) } } -func Test_SynchronizePiwigoCategories_updates_a_category(t *testing.T) { +func Test_updatePiwigoCategoriesFromServer_updates_a_category(t *testing.T) { mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() @@ -68,7 +68,7 @@ func Test_SynchronizePiwigoCategories_updates_a_category(t *testing.T) { piwigoMock := NewMockPiwigoCategoryApi(mockCtrl) piwigoMock.EXPECT().GetAllCategories().Return(piwigoCategories, nil).Times(1) - err := SynchronizePiwigoCategories(piwigoMock, dbmock) + err := updatePiwigoCategoriesFromServer(piwigoMock, dbmock) if err != nil { t.Error(err) }