This repository has been archived by the owner on Mar 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from paulhovey/existingFileRename
Attempt at fixing existing filename issue when exporting
- Loading branch information
Showing
3 changed files
with
51 additions
and
13 deletions.
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
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,32 @@ | ||
package pkg | ||
|
||
import ( | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestGenerateUniqueFileName(t *testing.T) { | ||
existingFilenames := make(map[string]bool) | ||
testFilename := "FullSizeRender.jpg" // what Apple calls shared files | ||
|
||
existingFilenames[strings.ToLower(testFilename)] = true | ||
|
||
a := &albumDiskInfo{ | ||
FileNames: &existingFilenames, | ||
} | ||
|
||
// this is taken from downloadEntry() | ||
extension := filepath.Ext(testFilename) | ||
baseFileName := strings.TrimSuffix(filepath.Clean(filepath.Base(testFilename)), extension) | ||
|
||
for i := 0; i < 100; i++ { | ||
newFilename := a.GenerateUniqueFileName(baseFileName, extension) | ||
if strings.Contains(newFilename, "_1_2") { | ||
t.Fatalf("Filename contained _1_2") | ||
} else { | ||
// add generated name to existing files | ||
existingFilenames[strings.ToLower(newFilename)] = true | ||
} | ||
} | ||
} |
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