| 1 |
package msgview |
| 2 |
|
| 3 |
import "testing" |
| 4 |
|
| 5 |
func TestGetCollisionlessFilename(t *testing.T) { |
| 6 |
tests := []struct { |
| 7 |
originalFilename string |
| 8 |
expectedNewName string |
| 9 |
existingFiles map[string]struct{} |
| 10 |
}{ |
| 11 |
{"test", "test", map[string]struct{}{}}, |
| 12 |
{"test", "test", map[string]struct{}{"other-file": {}}}, |
| 13 |
{"test.txt", "test.txt", map[string]struct{}{"test.log": {}}}, |
| 14 |
{"test.txt", "test_1.txt", map[string]struct{}{"test.txt": {}}}, |
| 15 |
{"test.txt", "test_2.txt", map[string]struct{}{"test.txt": {}, "test_1.txt": {}}}, |
| 16 |
{"test.txt", "test_1.txt", map[string]struct{}{"test.txt": {}, "test_2.txt": {}}}, |
| 17 |
} |
| 18 |
for _, tt := range tests { |
| 19 |
actual := getCollisionlessFilename(tt.originalFilename, tt.existingFiles) |
| 20 |
if actual != tt.expectedNewName { |
| 21 |
t.Errorf("expected %s, actual %s", tt.expectedNewName, actual) |
| 22 |
} |
| 23 |
} |
| 24 |
} |