-
Notifications
You must be signed in to change notification settings - Fork 92
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
fix: correct detection of obsolete files #776
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/test/java/com/crowdin/cli/commands/functionality/ObsoleteSourcesUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.crowdin.cli.commands.functionality; | ||
|
||
import com.crowdin.cli.utils.Utils; | ||
import com.crowdin.client.sourcefiles.model.File; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class ObsoleteSourcesUtilsTest { | ||
|
||
@Test | ||
public void testFindObsoleteProjectFiles() { | ||
Map<String, File> projectFilesFromApi = new HashMap<String, File>() { | ||
{ | ||
put(Utils.normalizePath("test/en/test.md"), new File()); | ||
put(Utils.normalizePath("test/en/support.md"), new File()); | ||
put(Utils.normalizePath("test/en/help.md"), new File()); | ||
} | ||
}; | ||
boolean preserveHierarchy = true; | ||
List<String> filesToUpload = Arrays.asList(Utils.normalizePath("test/en/test.md"), | ||
Utils.normalizePath("test/en/help.md")); | ||
String sourcePattern = Utils.normalizePath("/test/en/*.md"); | ||
String exportPattern = Utils.normalizePath("/test/%two_letters_code%/%original_path%/%original_file_name%"); | ||
List<String> ignorePatterns = Arrays.asList(Utils.normalizePath("**/.*")); | ||
|
||
Map<String, File> obsoleteFiles = ObsoleteSourcesUtils.findObsoleteProjectFiles(projectFilesFromApi, | ||
preserveHierarchy, | ||
filesToUpload, sourcePattern, exportPattern, ignorePatterns); | ||
|
||
assertEquals(1, obsoleteFiles.size()); | ||
anbraten marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assertEquals(true, obsoleteFiles.containsKey(Utils.normalizePath("test/en/support.md"))); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andrii-bodnar What do you think of this approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that files with the
null
export pattern will be considered obsolete and deleted, or the opposite?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It basically uses all projectFiles (files received by the api) and checks for each file:
isFileDontHaveUpdate=true
(which seems to check if the file is not part of the local files anymore)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I adjusted some var and method names so they match the rest of the code and are hopefully more descriptive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anbraten great, I just tested it locally and the fix works for me, thank you! 🚀