From 8c91dd210726d0eb4a1ec4f559a06386483dddc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=A4felfinger?= Date: Thu, 4 Apr 2019 15:39:32 +0200 Subject: [PATCH] WIP: renamed function and made it package internal as it gets orchestrated by another sync function --- internal/pkg/category/category.go | 7 ++++--- internal/pkg/category/category_test.go | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) 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) }