Skip to content

Commit 6f76129

Browse files
committed
Use slices.Contains
Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 56a8014 commit 6f76129

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

utils_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"path/filepath"
77
"reflect"
8+
"slices"
89
"strings"
910
"testing"
1011

@@ -273,14 +274,7 @@ func TestGetCgroupMounts(t *testing.T) {
273274
if !strings.HasPrefix(m.Mountpoint, "/sys/fs/cgroup/") && !strings.Contains(m.Mountpoint, ss) {
274275
t.Fatalf("unexpected mountpoint for %s: %s", ss, m.Mountpoint)
275276
}
276-
var ssFound bool
277-
for _, mss := range m.Subsystems {
278-
if mss == ss {
279-
ssFound = true
280-
break
281-
}
282-
}
283-
if !ssFound {
277+
if !slices.Contains(m.Subsystems, ss) {
284278
t.Fatalf("subsystem %s not found in Subsystems field %v", ss, m.Subsystems)
285279
}
286280
}

v1_utils.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8+
"slices"
89
"strings"
910
"sync"
1011
"syscall"
@@ -144,10 +145,8 @@ func FindCgroupMountpointAndRoot(cgroupPath, subsystem string) (string, string,
144145
func findCgroupMountpointAndRootFromMI(mounts []*mountinfo.Info, cgroupPath, subsystem string) (string, string, error) {
145146
for _, mi := range mounts {
146147
if strings.HasPrefix(mi.Mountpoint, cgroupPath) {
147-
for _, opt := range strings.Split(mi.VFSOptions, ",") {
148-
if opt == subsystem {
149-
return mi.Mountpoint, mi.Root, nil
150-
}
148+
if slices.Contains(strings.Split(mi.VFSOptions, ","), subsystem) {
149+
return mi.Mountpoint, mi.Root, nil
151150
}
152151
}
153152
}

0 commit comments

Comments
 (0)