Skip to content

Commit

Permalink
Refactor matching functions
Browse files Browse the repository at this point in the history
Matching functions were calling assert functions. Rewrote the assert functions to be internal matching functions for now.
  • Loading branch information
WithoutPants committed Sep 11, 2023
1 parent 021796b commit 6be3716
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 103 deletions.
19 changes: 16 additions & 3 deletions internal/autotag/gallery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ const galleryExt = "zip"

var testCtx = context.Background()

// returns got == expected
// ignores expected.UpdatedAt, but ensures that got.UpdatedAt is set and not null
func galleryPartialsEqual(got, expected models.GalleryPartial) bool {
// 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.ObjectsAreEqual(got, expected)
}

func TestGalleryPerformers(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -54,7 +67,7 @@ func TestGalleryPerformers(t *testing.T) {
},
}

return mocks.AssertGalleryPartial(t, got, expected)
return galleryPartialsEqual(got, expected)
})
mockGalleryReader.On("UpdatePartial", testCtx, galleryID, matchPartial).Return(nil, nil).Once()
}
Expand Down Expand Up @@ -101,7 +114,7 @@ func TestGalleryStudios(t *testing.T) {
StudioID: models.NewOptionalInt(studioID),
}

return mocks.AssertGalleryPartial(t, got, expected)
return galleryPartialsEqual(got, expected)
})
mockGalleryReader.On("UpdatePartial", testCtx, galleryID, matchPartial).Return(nil, nil).Once()
}
Expand Down Expand Up @@ -179,7 +192,7 @@ func TestGalleryTags(t *testing.T) {
},
}

return mocks.AssertGalleryPartial(t, got, expected)
return galleryPartialsEqual(got, expected)
})
mockGalleryReader.On("UpdatePartial", testCtx, galleryID, matchPartial).Return(nil, nil).Once()
}
Expand Down
19 changes: 16 additions & 3 deletions internal/autotag/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ import (

const imageExt = "jpg"

// returns got == expected
// ignores expected.UpdatedAt, but ensures that got.UpdatedAt is set and not null
func imagePartialsEqual(got, expected models.ImagePartial) bool {
// 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.ObjectsAreEqual(got, expected)
}

func TestImagePerformers(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -51,7 +64,7 @@ func TestImagePerformers(t *testing.T) {
},
}

return mocks.AssertImagePartial(t, got, expected)
return imagePartialsEqual(got, expected)
})
mockImageReader.On("UpdatePartial", testCtx, imageID, matchPartial).Return(nil, nil).Once()
}
Expand Down Expand Up @@ -98,7 +111,7 @@ func TestImageStudios(t *testing.T) {
StudioID: models.NewOptionalInt(studioID),
}

return mocks.AssertImagePartial(t, got, expected)
return imagePartialsEqual(got, expected)
})
mockImageReader.On("UpdatePartial", testCtx, imageID, matchPartial).Return(nil, nil).Once()
}
Expand Down Expand Up @@ -176,7 +189,7 @@ func TestImageTags(t *testing.T) {
},
}

return mocks.AssertImagePartial(t, got, expected)
return imagePartialsEqual(got, expected)
})
mockImageReader.On("UpdatePartial", testCtx, imageID, matchPartial).Return(nil, nil).Once()
}
Expand Down
6 changes: 3 additions & 3 deletions internal/autotag/performer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func testPerformerScenes(t *testing.T, performerName, expectedRegex string) {
},
}

return mocks.AssertScenePartial(t, got, expected)
return scenePartialsEqual(got, expected)
})
mockSceneReader.On("UpdatePartial", mock.Anything, sceneID, matchPartial).Return(nil, nil).Once()
}
Expand Down Expand Up @@ -193,7 +193,7 @@ func testPerformerImages(t *testing.T, performerName, expectedRegex string) {
},
}

return mocks.AssertImagePartial(t, got, expected)
return imagePartialsEqual(got, expected)
})
mockImageReader.On("UpdatePartial", mock.Anything, imageID, matchPartial).Return(nil, nil).Once()
}
Expand Down Expand Up @@ -288,7 +288,7 @@ func testPerformerGalleries(t *testing.T, performerName, expectedRegex string) {
},
}

return mocks.AssertGalleryPartial(t, got, expected)
return galleryPartialsEqual(got, expected)
})
mockGalleryReader.On("UpdatePartial", mock.Anything, galleryID, matchPartial).Return(nil, nil).Once()
}
Expand Down
19 changes: 16 additions & 3 deletions internal/autotag/scene_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ var testEndSeparators = []string{
",",
}

// asserts that got == expected
// ignores expected.UpdatedAt, but ensures that got.UpdatedAt is set and not null
func scenePartialsEqual(got, expected models.ScenePartial) bool {
// 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.ObjectsAreEqual(got, expected)
}

func generateNamePatterns(name, separator, ext string) []string {
var ret []string
ret = append(ret, fmt.Sprintf("%s%saaa.%s", name, separator, ext))
Expand Down Expand Up @@ -190,7 +203,7 @@ func TestScenePerformers(t *testing.T) {
},
}

return mocks.AssertScenePartial(t, got, expected)
return scenePartialsEqual(got, expected)
})
mockSceneReader.On("UpdatePartial", testCtx, sceneID, matchPartial).Return(nil, nil).Once()
}
Expand Down Expand Up @@ -234,7 +247,7 @@ func TestSceneStudios(t *testing.T) {
StudioID: models.NewOptionalInt(studioID),
}

return mocks.AssertScenePartial(t, got, expected)
return scenePartialsEqual(got, expected)
})
mockSceneReader.On("UpdatePartial", testCtx, sceneID, matchPartial).Return(nil, nil).Once()
}
Expand Down Expand Up @@ -312,7 +325,7 @@ func TestSceneTags(t *testing.T) {
},
}

return mocks.AssertScenePartial(t, got, expected)
return scenePartialsEqual(got, expected)
})
mockSceneReader.On("UpdatePartial", testCtx, sceneID, matchPartial).Return(nil, nil).Once()
}
Expand Down
6 changes: 3 additions & 3 deletions internal/autotag/studio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func testStudioScenes(t *testing.T, tc testStudioCase) {
StudioID: models.NewOptionalInt(studioID),
}

return mocks.AssertScenePartial(t, got, expected)
return scenePartialsEqual(got, expected)
})
mockSceneReader.On("UpdatePartial", mock.Anything, sceneID, matchPartial).Return(nil, nil).Once()
}
Expand Down Expand Up @@ -260,7 +260,7 @@ func testStudioImages(t *testing.T, tc testStudioCase) {
StudioID: models.NewOptionalInt(studioID),
}

return mocks.AssertImagePartial(t, got, expected)
return imagePartialsEqual(got, expected)
})
mockImageReader.On("UpdatePartial", mock.Anything, imageID, matchPartial).Return(nil, nil).Once()
}
Expand Down Expand Up @@ -362,7 +362,7 @@ func testStudioGalleries(t *testing.T, tc testStudioCase) {
StudioID: models.NewOptionalInt(studioID),
}

return mocks.AssertGalleryPartial(t, got, expected)
return galleryPartialsEqual(got, expected)
})
mockGalleryReader.On("UpdatePartial", mock.Anything, galleryID, matchPartial).Return(nil, nil).Once()
}
Expand Down
6 changes: 3 additions & 3 deletions internal/autotag/tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func testTagScenes(t *testing.T, tc testTagCase) {
},
}

return mocks.AssertScenePartial(t, got, expected)
return scenePartialsEqual(got, expected)
})
mockSceneReader.On("UpdatePartial", mock.Anything, sceneID, matchPartial).Return(nil, nil).Once()
}
Expand Down Expand Up @@ -267,7 +267,7 @@ func testTagImages(t *testing.T, tc testTagCase) {
},
}

return mocks.AssertImagePartial(t, got, expected)
return imagePartialsEqual(got, expected)
})
mockImageReader.On("UpdatePartial", mock.Anything, imageID, matchPartial).Return(nil, nil).Once()
}
Expand Down Expand Up @@ -374,7 +374,7 @@ func testTagGalleries(t *testing.T, tc testTagCase) {
},
}

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

Expand Down
85 changes: 0 additions & 85 deletions pkg/models/mocks/asserts.go

This file was deleted.

0 comments on commit 6be3716

Please sign in to comment.