Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions utils/librarypath/librarypath.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (

"github.com/hashload/boss/pkg/pkgmanager"

"slices"

"github.com/hashload/boss/internal/core/domain"
"github.com/hashload/boss/pkg/consts"
"github.com/hashload/boss/pkg/env"
Expand Down Expand Up @@ -204,12 +202,13 @@ func getDefaultPath(fullPath bool, rootPath string) []string {

// cleanEmpty removes empty strings from a slice.
func cleanEmpty(paths []string) []string {
for index, value := range paths {
if value == "" {
paths = slices.Delete(paths, index, index+1)
cleaned := paths[:0]
for _, value := range paths {
if value != "" {
cleaned = append(cleaned, value)
}
}
return paths
return cleaned
}

// getNewBrowsingPathsFromDir returns a list of new browsing paths from a directory.
Expand Down
45 changes: 45 additions & 0 deletions utils/librarypath/librarypath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,51 @@ func TestCleanPath(t *testing.T) {
}
}

// TestCleanEmpty tests empty string removal from a slice.
func TestCleanEmpty(t *testing.T) {
tests := []struct {
name string
in []string
want []string
}{
{
name: "no empties",
in: []string{"a", "b"},
want: []string{"a", "b"},
},
{
name: "single empty",
in: []string{"a", "", "b"},
want: []string{"a", "b"},
},
{
name: "multiple empties",
in: []string{"", "a", "", "b", ""},
want: []string{"a", "b"},
},
{
name: "all empty",
in: []string{"", ""},
want: []string{},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := cleanEmpty(tt.in)

if len(result) != len(tt.want) {
t.Fatalf("cleanEmpty() = %v, want %v", result, tt.want)
}
for i, v := range result {
if v != tt.want[i] {
t.Errorf("cleanEmpty()[%d] = %q, want %q", i, v, tt.want[i])
}
}
})
}
}

// TestGetNewBrowsingPaths tests browsing paths retrieval.
func TestGetNewBrowsingPaths(t *testing.T) {
tempDir := t.TempDir()
Expand Down
Loading