From b11464121ceda18f415d33ef309038bea7242451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=A4felfinger?= Date: Tue, 2 Apr 2019 23:26:55 +0200 Subject: [PATCH] added first test and empty function --- internal/pkg/category/category.go | 5 +++ internal/pkg/category/category_test.go | 58 ++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 internal/pkg/category/category_test.go diff --git a/internal/pkg/category/category.go b/internal/pkg/category/category.go index e505379..b9061eb 100644 --- a/internal/pkg/category/category.go +++ b/internal/pkg/category/category.go @@ -8,6 +8,7 @@ package category import ( "errors" "fmt" + "git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/datastore" "git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/localFileStructure" "git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/piwigo" "github.com/sirupsen/logrus" @@ -15,6 +16,10 @@ import ( "sort" ) +func SynchronizePiwigoCategories(piwigoApi piwigo.PiwigoCategoryApi, datastore datastore.CategoryProvider) error { + return errors.New("N/A") +} + func GetAllCategoriesFromServer(piwigoApi piwigo.PiwigoCategoryApi) (map[string]*piwigo.PiwigoCategory, error) { logrus.Debugln("Starting GetAllCategories") categories, err := piwigoApi.GetAllCategories() diff --git a/internal/pkg/category/category_test.go b/internal/pkg/category/category_test.go new file mode 100644 index 0000000..eebc79f --- /dev/null +++ b/internal/pkg/category/category_test.go @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2019 Philipp Haefelfinger (http://www.haefelfinger.ch/). All Rights Reserved. + * This application is licensed under GPLv2. See the LICENSE file in the root directory of the project. + */ + +package category + +import ( + "git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/datastore" + "git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/piwigo" + "github.com/golang/mock/gomock" + "testing" +) + +//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) { + mockCtrl := gomock.NewController(t) + defer mockCtrl.Finish() + + piwigoCategory := createTestPiwigoCategory(1) + piwigoCategories := []piwigo.PiwigoCategory{piwigoCategory} + + category := createTestCategoryData(1) + + dbmock := NewMockCategoryProvider(mockCtrl) + dbmock.EXPECT().SaveCategory(category).Times(1) + + piwigoMock := NewMockPiwigoCategoryApi(mockCtrl) + piwigoMock.EXPECT().GetAllCategories().Return(piwigoCategories).Times(1) + + err := SynchronizePiwigoCategories(piwigoMock, dbmock) + if err != nil { + t.Error(err) + } +} + +func createTestPiwigoCategory(piwigoId int) piwigo.PiwigoCategory { + cat := piwigo.PiwigoCategory{ + Id: piwigoId, + Name: "2019", + Key: "2019", + ParentId: 0, + } + return cat +} + +func createTestCategoryData(piwigoId int) datastore.CategoryData { + cat := datastore.CategoryData{ + CategoryId: 1, + PiwigoId: piwigoId, + PiwigoParentId: 0, + Name: "2019", + Key: "2019", + } + return cat +}