Skip to content

Commit

Permalink
refactor: remove unused code, renamed function
Browse files Browse the repository at this point in the history
  • Loading branch information
Zebradil committed May 22, 2024
1 parent 83d090b commit f7e3e43
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 151 deletions.
47 changes: 0 additions & 47 deletions internal/myks/path.go

This file was deleted.

103 changes: 0 additions & 103 deletions internal/myks/path_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/myks/smart_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (g *Globe) runSmartMode(changedFiles ChangedFiles) EnvAppMap {
for env, apps := range envAppMap {
if apps != nil {
// Remove duplicates
envAppMap[env] = removeDuplicates(apps)
envAppMap[env] = unique(apps)
}
}

Expand Down
12 changes: 12 additions & 0 deletions internal/myks/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,3 +505,15 @@ func isDir(path string) (bool, error) {
}
return fileInfo.IsDir(), nil
}

func unique[T comparable](slice []T) []T {
seen := make(map[T]struct{})
result := []T{}
for _, item := range slice {
if _, exists := seen[item]; !exists {
seen[item] = struct{}{}
result = append(result, item)
}
}
return result
}
25 changes: 25 additions & 0 deletions internal/myks/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,3 +539,28 @@ func Test_findSubPath(t *testing.T) {
})
}
}

func Test_unique(t *testing.T) {
type args struct {
slice []string
}
tests := []struct {
name string
args args
want []string
}{
{"happy path", args{[]string{"test", "test", "test2"}}, []string{"test", "test2"}},
{"empty slice", args{[]string{}}, []string{}},
{"one element", args{[]string{"test"}}, []string{"test"}},
{"several duplicates", args{[]string{"test", "test", "test"}}, []string{"test"}},
{"grouped duplicates", args{[]string{"test", "test2", "test", "test2"}}, []string{"test", "test2"}},
{"no duplicates", args{[]string{"test", "test2"}}, []string{"test", "test2"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := unique(tt.args.slice); !reflect.DeepEqual(got, tt.want) {
t.Errorf("unique() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit f7e3e43

Please sign in to comment.