Skip to content

Commit c6db831

Browse files
authored
Trim whitespace from technologies (#74)
1 parent eb5a700 commit c6db831

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

pkg/move/technologies.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ func filterFilesByTechnology(log logr.Logger, fs afero.Afero, source string, tec
126126
var paths []string
127127

128128
for _, tech := range technologies {
129+
tech := strings.TrimSpace(tech)
129130
techData, exists := manifest.Technologies[tech]
131+
130132
if !exists {
131133
log.Info("technology not found", "tech", tech)
132134
continue

pkg/move/technologies_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,21 @@ func TestCopyFolderWithTechnologyFiltering(t *testing.T) {
7373
assertFileExists(t, fs, filepath.Join(targetDir, "fileB1.txt"))
7474
assertFileNotExists(t, fs, filepath.Join(targetDir, "fileC1.txt"))
7575
})
76+
t.Run("copy with multiple technology filter with whitespace", func(t *testing.T) {
77+
t.Cleanup(func() {
78+
_ = fs.RemoveAll(targetDir)
79+
_ = fs.MkdirAll(targetDir, 0755)
80+
})
81+
82+
technology := "java, python"
83+
err := CopyByTechnology(testLog, fs, sourceDir, targetDir, technology)
84+
require.NoError(t, err)
85+
86+
assertFileExists(t, fs, filepath.Join(targetDir, "fileA1.txt"))
87+
assertFileExists(t, fs, filepath.Join(targetDir, "fileA2.txt"))
88+
assertFileExists(t, fs, filepath.Join(targetDir, "fileB1.txt"))
89+
assertFileNotExists(t, fs, filepath.Join(targetDir, "fileC1.txt"))
90+
})
7691
t.Run("copy with invalid technology filter", func(t *testing.T) {
7792
t.Cleanup(func() {
7893
_ = fs.RemoveAll(targetDir)
@@ -192,6 +207,15 @@ func TestFilterFilesByTechnology(t *testing.T) {
192207
filepath.Join("fileB1.txt"),
193208
}, paths)
194209
})
210+
t.Run("filter multiple technologies with white spaces", func(t *testing.T) {
211+
paths, err := filterFilesByTechnology(testLog, fs, sourceDir, []string{"java ", " python "})
212+
require.NoError(t, err)
213+
assert.ElementsMatch(t, []string{
214+
filepath.Join("fileA1.txt"),
215+
filepath.Join("fileA2.txt"),
216+
filepath.Join("fileB1.txt"),
217+
}, paths)
218+
})
195219
t.Run("not filter non-existing technology", func(t *testing.T) {
196220
paths, err := filterFilesByTechnology(testLog, fs, sourceDir, []string{"php"})
197221
require.NoError(t, err)

0 commit comments

Comments
 (0)