refactor: use slices.Contains to simplify code (#10121)

There is a [new function](https://pkg.go.dev/slices@go1.21.0#Contains)
added in the go1.21 standard library, which can make the code more
concise and easy to read.
This commit is contained in:
pullmerge
2025-05-23 10:36:06 +00:00
committed by GitHub
parent 2532ac35cf
commit beda37f28b
3 changed files with 12 additions and 24 deletions
+5 -8
View File
@@ -17,6 +17,7 @@ import (
"os"
"path/filepath"
"runtime/pprof"
"slices"
"sort"
"strconv"
"strings"
@@ -1253,10 +1254,8 @@ func TestAutoAcceptPausedWhenFolderConfigChanged(t *testing.T) {
} else if fcfg.Path != idOther {
t.Error("folder path changed")
} else {
for _, dev := range fcfg.DeviceIDs() {
if dev == device1 {
return
}
if slices.Contains(fcfg.DeviceIDs(), device1) {
return
}
t.Error("device missing")
}
@@ -1302,10 +1301,8 @@ func TestAutoAcceptPausedWhenFolderConfigNotChanged(t *testing.T) {
} else if fcfg.Path != idOther {
t.Error("folder path changed")
} else {
for _, dev := range fcfg.DeviceIDs() {
if dev == device1 {
return
}
if slices.Contains(fcfg.DeviceIDs(), device1) {
return
}
t.Error("device missing")
}