Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DingDongSoLong4 committed Sep 5, 2023
1 parent 27016aa commit e6d865d
Show file tree
Hide file tree
Showing 6 changed files with 313 additions and 96 deletions.
67 changes: 51 additions & 16 deletions internal/autotag/gallery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,24 @@ func TestGalleryPerformers(t *testing.T) {
mockPerformerReader.On("QueryForAutoTag", testCtx, mock.Anything).Return([]*models.Performer{&performer, &reversedPerformer}, nil).Once()

if test.Matches {
mockGalleryReader.On("UpdatePartial", testCtx, galleryID, models.GalleryPartial{
PerformerIDs: &models.UpdateIDs{
IDs: []int{performerID},
Mode: models.RelationshipUpdateModeAdd,
},
}).Return(nil, nil).Once()
matchPartial := mock.MatchedBy(func(got models.GalleryPartial) bool {
expected := models.GalleryPartial{
PerformerIDs: &models.UpdateIDs{
IDs: []int{performerID},
Mode: models.RelationshipUpdateModeAdd,
},
}

// updated at should be set and not null
if !got.UpdatedAt.Set || got.UpdatedAt.Null {
return false
}
// else ignore the exact value
got.UpdatedAt = models.OptionalTime{}

return assert.Equal(got, expected)
})
mockGalleryReader.On("UpdatePartial", testCtx, galleryID, matchPartial).Return(nil, nil).Once()
}

gallery := models.Gallery{
Expand Down Expand Up @@ -91,10 +103,21 @@ func TestGalleryStudios(t *testing.T) {

doTest := func(mockStudioReader *mocks.StudioReaderWriter, mockGalleryReader *mocks.GalleryReaderWriter, test pathTestTable) {
if test.Matches {
expectedStudioID := studioID
mockGalleryReader.On("UpdatePartial", testCtx, galleryID, models.GalleryPartial{
StudioID: models.NewOptionalInt(expectedStudioID),
}).Return(nil, nil).Once()
matchPartial := mock.MatchedBy(func(got models.GalleryPartial) bool {
expected := models.GalleryPartial{
StudioID: models.NewOptionalInt(studioID),
}

// updated at should be set and not null
if !got.UpdatedAt.Set || got.UpdatedAt.Null {
return false
}
// else ignore the exact value
got.UpdatedAt = models.OptionalTime{}

return assert.Equal(got, expected)
})
mockGalleryReader.On("UpdatePartial", testCtx, galleryID, matchPartial).Return(nil, nil).Once()
}

gallery := models.Gallery{
Expand Down Expand Up @@ -162,12 +185,24 @@ func TestGalleryTags(t *testing.T) {

doTest := func(mockTagReader *mocks.TagReaderWriter, mockGalleryReader *mocks.GalleryReaderWriter, test pathTestTable) {
if test.Matches {
mockGalleryReader.On("UpdatePartial", testCtx, galleryID, models.GalleryPartial{
TagIDs: &models.UpdateIDs{
IDs: []int{tagID},
Mode: models.RelationshipUpdateModeAdd,
},
}).Return(nil, nil).Once()
matchPartial := mock.MatchedBy(func(got models.GalleryPartial) bool {
expected := models.GalleryPartial{
TagIDs: &models.UpdateIDs{
IDs: []int{tagID},
Mode: models.RelationshipUpdateModeAdd,
},
}

// updated at should be set and not null
if !got.UpdatedAt.Set || got.UpdatedAt.Null {
return false
}
// else ignore the exact value
got.UpdatedAt = models.OptionalTime{}

return assert.Equal(got, expected)
})
mockGalleryReader.On("UpdatePartial", testCtx, galleryID, matchPartial).Return(nil, nil).Once()
}

gallery := models.Gallery{
Expand Down
67 changes: 51 additions & 16 deletions internal/autotag/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,24 @@ func TestImagePerformers(t *testing.T) {
mockPerformerReader.On("QueryForAutoTag", testCtx, mock.Anything).Return([]*models.Performer{&performer, &reversedPerformer}, nil).Once()

if test.Matches {
mockImageReader.On("UpdatePartial", testCtx, imageID, models.ImagePartial{
PerformerIDs: &models.UpdateIDs{
IDs: []int{performerID},
Mode: models.RelationshipUpdateModeAdd,
},
}).Return(nil, nil).Once()
matchPartial := mock.MatchedBy(func(got models.ImagePartial) bool {
expected := models.ImagePartial{
PerformerIDs: &models.UpdateIDs{
IDs: []int{performerID},
Mode: models.RelationshipUpdateModeAdd,
},
}

// updated at should be set and not null
if !got.UpdatedAt.Set || got.UpdatedAt.Null {
return false
}
// else ignore the exact value
got.UpdatedAt = models.OptionalTime{}

return assert.Equal(got, expected)
})
mockImageReader.On("UpdatePartial", testCtx, imageID, matchPartial).Return(nil, nil).Once()
}

image := models.Image{
Expand Down Expand Up @@ -88,10 +100,21 @@ func TestImageStudios(t *testing.T) {

doTest := func(mockStudioReader *mocks.StudioReaderWriter, mockImageReader *mocks.ImageReaderWriter, test pathTestTable) {
if test.Matches {
expectedStudioID := studioID
mockImageReader.On("UpdatePartial", testCtx, imageID, models.ImagePartial{
StudioID: models.NewOptionalInt(expectedStudioID),
}).Return(nil, nil).Once()
matchPartial := mock.MatchedBy(func(got models.ImagePartial) bool {
expected := models.ImagePartial{
StudioID: models.NewOptionalInt(studioID),
}

// updated at should be set and not null
if !got.UpdatedAt.Set || got.UpdatedAt.Null {
return false
}
// else ignore the exact value
got.UpdatedAt = models.OptionalTime{}

return assert.Equal(got, expected)
})
mockImageReader.On("UpdatePartial", testCtx, imageID, matchPartial).Return(nil, nil).Once()
}

image := models.Image{
Expand Down Expand Up @@ -159,12 +182,24 @@ func TestImageTags(t *testing.T) {

doTest := func(mockTagReader *mocks.TagReaderWriter, mockImageReader *mocks.ImageReaderWriter, test pathTestTable) {
if test.Matches {
mockImageReader.On("UpdatePartial", testCtx, imageID, models.ImagePartial{
TagIDs: &models.UpdateIDs{
IDs: []int{tagID},
Mode: models.RelationshipUpdateModeAdd,
},
}).Return(nil, nil).Once()
matchPartial := mock.MatchedBy(func(got models.ImagePartial) bool {
expected := models.ImagePartial{
TagIDs: &models.UpdateIDs{
IDs: []int{tagID},
Mode: models.RelationshipUpdateModeAdd,
},
}

// updated at should be set and not null
if !got.UpdatedAt.Set || got.UpdatedAt.Null {
return false
}
// else ignore the exact value
got.UpdatedAt = models.OptionalTime{}

return assert.Equal(got, expected)
})
mockImageReader.On("UpdatePartial", testCtx, imageID, matchPartial).Return(nil, nil).Once()
}

image := models.Image{
Expand Down
75 changes: 57 additions & 18 deletions internal/autotag/performer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,25 @@ func testPerformerScenes(t *testing.T, performerName, expectedRegex string) {

for i := range matchingPaths {
sceneID := i + 1
mockSceneReader.On("UpdatePartial", mock.Anything, sceneID, models.ScenePartial{
PerformerIDs: &models.UpdateIDs{
IDs: []int{performerID},
Mode: models.RelationshipUpdateModeAdd,
},
}).Return(nil, nil).Once()

matchPartial := mock.MatchedBy(func(got models.ScenePartial) bool {
expected := models.ScenePartial{
PerformerIDs: &models.UpdateIDs{
IDs: []int{performerID},
Mode: models.RelationshipUpdateModeAdd,
},
}

// updated at should be set and not null
if !got.UpdatedAt.Set || got.UpdatedAt.Null {
return false
}
// else ignore the exact value
got.UpdatedAt = models.OptionalTime{}

return assert.Equal(t, got, expected)
})
mockSceneReader.On("UpdatePartial", mock.Anything, sceneID, matchPartial).Return(nil, nil).Once()
}

tagger := Tagger{
Expand Down Expand Up @@ -178,12 +191,25 @@ func testPerformerImages(t *testing.T, performerName, expectedRegex string) {

for i := range matchingPaths {
imageID := i + 1
mockImageReader.On("UpdatePartial", mock.Anything, imageID, models.ImagePartial{
PerformerIDs: &models.UpdateIDs{
IDs: []int{performerID},
Mode: models.RelationshipUpdateModeAdd,
},
}).Return(nil, nil).Once()

matchPartial := mock.MatchedBy(func(got models.ImagePartial) bool {
expected := models.ImagePartial{
PerformerIDs: &models.UpdateIDs{
IDs: []int{performerID},
Mode: models.RelationshipUpdateModeAdd,
},
}

// updated at should be set and not null
if !got.UpdatedAt.Set || got.UpdatedAt.Null {
return false
}
// else ignore the exact value
got.UpdatedAt = models.OptionalTime{}

return assert.Equal(t, got, expected)
})
mockImageReader.On("UpdatePartial", mock.Anything, imageID, matchPartial).Return(nil, nil).Once()
}

tagger := Tagger{
Expand Down Expand Up @@ -267,12 +293,25 @@ func testPerformerGalleries(t *testing.T, performerName, expectedRegex string) {

for i := range matchingPaths {
galleryID := i + 1
mockGalleryReader.On("UpdatePartial", mock.Anything, galleryID, models.GalleryPartial{
PerformerIDs: &models.UpdateIDs{
IDs: []int{performerID},
Mode: models.RelationshipUpdateModeAdd,
},
}).Return(nil, nil).Once()

matchPartial := mock.MatchedBy(func(got models.GalleryPartial) bool {
expected := models.GalleryPartial{
PerformerIDs: &models.UpdateIDs{
IDs: []int{performerID},
Mode: models.RelationshipUpdateModeAdd,
},
}

// updated at should be set and not null
if !got.UpdatedAt.Set || got.UpdatedAt.Null {
return false
}
// else ignore the exact value
got.UpdatedAt = models.OptionalTime{}

return assert.Equal(t, got, expected)
})
mockGalleryReader.On("UpdatePartial", mock.Anything, galleryID, matchPartial).Return(nil, nil).Once()
}

tagger := Tagger{
Expand Down
67 changes: 51 additions & 16 deletions internal/autotag/scene_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,24 @@ func TestScenePerformers(t *testing.T) {
}

if test.Matches {
mockSceneReader.On("UpdatePartial", testCtx, sceneID, models.ScenePartial{
PerformerIDs: &models.UpdateIDs{
IDs: []int{performerID},
Mode: models.RelationshipUpdateModeAdd,
},
}).Return(nil, nil).Once()
matchPartial := mock.MatchedBy(func(got models.ScenePartial) bool {
expected := models.ScenePartial{
PerformerIDs: &models.UpdateIDs{
IDs: []int{performerID},
Mode: models.RelationshipUpdateModeAdd,
},
}

// updated at should be set and not null
if !got.UpdatedAt.Set || got.UpdatedAt.Null {
return false
}
// else ignore the exact value
got.UpdatedAt = models.OptionalTime{}

return assert.Equal(got, expected)
})
mockSceneReader.On("UpdatePartial", testCtx, sceneID, matchPartial).Return(nil, nil).Once()
}

err := ScenePerformers(testCtx, &scene, mockSceneReader, mockPerformerReader, nil)
Expand Down Expand Up @@ -224,10 +236,21 @@ func TestSceneStudios(t *testing.T) {

doTest := func(mockStudioReader *mocks.StudioReaderWriter, mockSceneReader *mocks.SceneReaderWriter, test pathTestTable) {
if test.Matches {
expectedStudioID := studioID
mockSceneReader.On("UpdatePartial", testCtx, sceneID, models.ScenePartial{
StudioID: models.NewOptionalInt(expectedStudioID),
}).Return(nil, nil).Once()
matchPartial := mock.MatchedBy(func(got models.ScenePartial) bool {
expected := models.ScenePartial{
StudioID: models.NewOptionalInt(studioID),
}

// updated at should be set and not null
if !got.UpdatedAt.Set || got.UpdatedAt.Null {
return false
}
// else ignore the exact value
got.UpdatedAt = models.OptionalTime{}

return assert.Equal(got, expected)
})
mockSceneReader.On("UpdatePartial", testCtx, sceneID, matchPartial).Return(nil, nil).Once()
}

scene := models.Scene{
Expand Down Expand Up @@ -295,12 +318,24 @@ func TestSceneTags(t *testing.T) {

doTest := func(mockTagReader *mocks.TagReaderWriter, mockSceneReader *mocks.SceneReaderWriter, test pathTestTable) {
if test.Matches {
mockSceneReader.On("UpdatePartial", testCtx, sceneID, models.ScenePartial{
TagIDs: &models.UpdateIDs{
IDs: []int{tagID},
Mode: models.RelationshipUpdateModeAdd,
},
}).Return(nil, nil).Once()
matchPartial := mock.MatchedBy(func(got models.ScenePartial) bool {
expected := models.ScenePartial{
TagIDs: &models.UpdateIDs{
IDs: []int{tagID},
Mode: models.RelationshipUpdateModeAdd,
},
}

// updated at should be set and not null
if !got.UpdatedAt.Set || got.UpdatedAt.Null {
return false
}
// else ignore the exact value
got.UpdatedAt = models.OptionalTime{}

return assert.Equal(got, expected)
})
mockSceneReader.On("UpdatePartial", testCtx, sceneID, matchPartial).Return(nil, nil).Once()
}

scene := models.Scene{
Expand Down
Loading

0 comments on commit e6d865d

Please sign in to comment.