Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove accepted images from failed image path. #70

Merged
merged 4 commits into from
Apr 9, 2018

Conversation

babbage
Copy link
Collaborator

@babbage babbage commented Apr 6, 2018

When a new image is accepted, remove the reference image, failed image, and diff image from the failed image path. As discussed in #27

Copy link
Owner

@Antondomashnev Antondomashnev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @babbage!
I've left some comments to discuss 😄

@@ -10,7 +10,13 @@ import Foundation

extension FileManager {
func moveItem(at fromURL: URL, to toURL: URL) throws {
try self.removeItem(at: toURL)
try deleteItem(at: toURL)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary here to add a new method?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can rename deleteItem to something like deleteIfExists?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, deleteIfExists would be much better and I'd been thinking exactly the same thing since making the pull request. The reason for it being a separate method is because it's used both in moveItem here, and is called directly from the removeTestImages function in SnapshotTestResultSwapper.swift.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you mean the overhead of checking if file exists? I think it's fine and it should not add any performance cost 😄

guard case let SnapshotTestResult.failed(testInformation, _, _, failedImagePath, build) = testResult, canSwap(testResult) else {
throw SnapshotTestResultSwapperError.canNotBeSwapped(testResult: testResult)
}
let failedImageURL = URL(fileURLWithPath: failedImagePath, isDirectory: false)
do {
let recordedImageURL = try buildRecordedImageURL(from: failedImagePath, of: testResult)
try fileManager.moveItem(at: failedImageURL, to: recordedImageURL)

if removeAcceptedImages {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may want to test it somehow? Can you think of a unit or maybe integration test here?

babbage added 3 commits April 9, 2018 12:43
When a new image is accepted, remove the reference image, failed image, and diff image from the failed image path.
Implemented here partly to ease merge with proposed changes in other pull requests.
@babbage
Copy link
Collaborator Author

babbage commented Apr 9, 2018

Have rebased this branch on the current master after the Accept/Accept All change was committed, as that changed quite a lot of file and function names so there were conflicts. Lost your comment re tests in that rebasing but agree should be tested (sigh!) so will see what I can come up with.

Have renamed the function to deleteIfExists.

Note in this pull request I separated removeTestImages out into a separate function partly to maintain simplicity of functions, but additionally because a removeTestImages function is also needed by the Reject images proposal which is in pull request: #71.

@Antondomashnev Antondomashnev merged commit 72b1c2e into Antondomashnev:master Apr 9, 2018
@babbage babbage deleted the RemoveAccepted branch November 15, 2018 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants