WIP: refactored tests
This commit is contained in:
parent
41bf858523
commit
550230195a
@ -19,19 +19,17 @@ func Test_SynchronizePiwigoCategories_adds_new_categories(t *testing.T) {
|
|||||||
mockCtrl := gomock.NewController(t)
|
mockCtrl := gomock.NewController(t)
|
||||||
defer mockCtrl.Finish()
|
defer mockCtrl.Finish()
|
||||||
|
|
||||||
piwigoCategory := createTestPiwigoCategory(1)
|
piwigoCategories := createTwoServerCategories()
|
||||||
|
dbCategories := createDbCategoriesFrom(piwigoCategories)
|
||||||
piwigoCategories := make(map[string]*piwigo.PiwigoCategory)
|
|
||||||
piwigoCategories[piwigoCategory.Key] = &piwigoCategory
|
|
||||||
numberOfCategories := len(piwigoCategories)
|
|
||||||
|
|
||||||
category := createTestCategoryData(1)
|
|
||||||
|
|
||||||
dbmock := NewMockCategoryProvider(mockCtrl)
|
dbmock := NewMockCategoryProvider(mockCtrl)
|
||||||
dbmock.EXPECT().SaveCategory(category).Times(numberOfCategories)
|
|
||||||
|
for _, cat := range dbCategories {
|
||||||
|
dbmock.EXPECT().SaveCategory(cat).Times(1)
|
||||||
|
}
|
||||||
|
|
||||||
piwigoMock := NewMockPiwigoCategoryApi(mockCtrl)
|
piwigoMock := NewMockPiwigoCategoryApi(mockCtrl)
|
||||||
piwigoMock.EXPECT().GetAllCategories().Return(piwigoCategories, nil).Times(len(piwigoCategories))
|
piwigoMock.EXPECT().GetAllCategories().Return(piwigoCategories, nil).Times(1)
|
||||||
|
|
||||||
err := SynchronizePiwigoCategories(piwigoMock, dbmock)
|
err := SynchronizePiwigoCategories(piwigoMock, dbmock)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -39,23 +37,36 @@ func Test_SynchronizePiwigoCategories_adds_new_categories(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTestPiwigoCategory(piwigoId int) piwigo.PiwigoCategory {
|
func createDbCategoriesFrom(categories map[string]*piwigo.PiwigoCategory) []datastore.CategoryData {
|
||||||
cat := piwigo.PiwigoCategory{
|
dbCategories := []datastore.CategoryData{}
|
||||||
Id: piwigoId,
|
for _, cat := range categories {
|
||||||
|
dbCat := datastore.CategoryData{
|
||||||
|
PiwigoId: cat.Id,
|
||||||
|
PiwigoParentId: cat.ParentId,
|
||||||
|
Key: cat.Key,
|
||||||
|
Name: cat.Name,
|
||||||
|
CategoryId: 0,
|
||||||
|
}
|
||||||
|
dbCategories = append(dbCategories, dbCat)
|
||||||
|
}
|
||||||
|
return dbCategories
|
||||||
|
}
|
||||||
|
|
||||||
|
func createTwoServerCategories() map[string]*piwigo.PiwigoCategory {
|
||||||
|
piwigoCategory1 := piwigo.PiwigoCategory{
|
||||||
|
Id: 1,
|
||||||
Name: "2019",
|
Name: "2019",
|
||||||
Key: "2019",
|
Key: "2019",
|
||||||
ParentId: 0,
|
ParentId: 0,
|
||||||
}
|
}
|
||||||
return cat
|
piwigoCategory2 := piwigo.PiwigoCategory{
|
||||||
}
|
Id: 2,
|
||||||
|
Name: "SubCategory",
|
||||||
func createTestCategoryData(piwigoId int) datastore.CategoryData {
|
Key: "2019/SubCategory",
|
||||||
cat := datastore.CategoryData{
|
ParentId: 1,
|
||||||
CategoryId: 0,
|
|
||||||
PiwigoId: piwigoId,
|
|
||||||
PiwigoParentId: 0,
|
|
||||||
Name: "2019",
|
|
||||||
Key: "2019",
|
|
||||||
}
|
}
|
||||||
return cat
|
piwigoCategories := make(map[string]*piwigo.PiwigoCategory)
|
||||||
|
piwigoCategories[piwigoCategory1.Key] = &piwigoCategory1
|
||||||
|
piwigoCategories[piwigoCategory2.Key] = &piwigoCategory2
|
||||||
|
return piwigoCategories
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user