Skip to content

Commit 89e5990

Browse files
committed
Modernize code for Go 1.24
Brought to you by modernize -fix -test ./... Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent b042b6d commit 89e5990

File tree

14 files changed

+17
-25
lines changed

14 files changed

+17
-25
lines changed

exec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func getSubCgroupPaths(args []string) (map[string]string, error) {
132132
// Split into controller:path.
133133
if ctr, path, ok := strings.Cut(c, ":"); ok {
134134
// There may be a few comma-separated controllers.
135-
for _, ctrl := range strings.Split(ctr, ",") {
135+
for ctrl := range strings.SplitSeq(ctr, ",") {
136136
if ctrl == "" {
137137
return nil, fmt.Errorf("invalid --cgroup argument: %s (empty <controller> prefix)", c)
138138
}

libcontainer/configs/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ func toCPUSet(str string) (*unix.CPUSet, error) {
325325
return int(ret), nil
326326
}
327327

328-
for _, r := range strings.Split(str, ",") {
328+
for r := range strings.SplitSeq(str, ",") {
329329
// Allow extra spaces around.
330330
r = strings.TrimSpace(r)
331331
// Allow empty elements (extra commas).

libcontainer/configs/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestUnmarshalHooks(t *testing.T) {
3030

3131
for _, hookName := range configs.HookNameList {
3232
hooks := configs.Hooks{}
33-
err = hooks.UnmarshalJSON([]byte(fmt.Sprintf(`{"%s" :[%s]}`, hookName, hookJson)))
33+
err = hooks.UnmarshalJSON(fmt.Appendf(nil, `{"%s" :[%s]}`, hookName, hookJson))
3434
if err != nil {
3535
t.Fatal(err)
3636
}

libcontainer/configs/tocpuset_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ func TestToCPUSet(t *testing.T) {
5757
}
5858

5959
for _, tc := range testCases {
60-
tc := tc
6160
t.Run(tc.in, func(t *testing.T) {
6261
out, err := toCPUSet(tc.in)
6362
t.Logf("toCPUSet(%q) = %v (error: %v)", tc.in, out, err)

libcontainer/configs/validate/rootless.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func rootlessEUIDMount(config *configs.Config) error {
6060
if !strings.Contains(mount.Data, "id=") {
6161
continue
6262
}
63-
for _, opt := range strings.Split(mount.Data, ",") {
63+
for opt := range strings.SplitSeq(mount.Data, ",") {
6464
if str, ok := strings.CutPrefix(opt, "uid="); ok {
6565
uid, err := strconv.Atoi(str)
6666
if err != nil {

libcontainer/configs/validate/rootless_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ func BenchmarkRootlessEUIDMount(b *testing.B) {
154154
},
155155
}
156156

157-
b.ResetTimer()
158-
for i := 0; i < b.N; i++ {
157+
for b.Loop() {
159158
err := rootlessEUIDMount(config)
160159
if err != nil {
161160
b.Fatal(err)

libcontainer/configs/validate/validator_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,6 @@ func TestValidateIDMapMounts(t *testing.T) {
774774
}
775775

776776
for _, tc := range testCases {
777-
tc := tc
778777
t.Run(tc.name, func(t *testing.T) {
779778
config := tc.config
780779
config.Rootfs = "/var"

libcontainer/integration/bench_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ func BenchmarkExecTrue(b *testing.B) {
3434
}()
3535
ok(b, err)
3636

37-
b.ResetTimer()
38-
for i := 0; i < b.N; i++ {
37+
for b.Loop() {
3938
exec := &libcontainer.Process{
4039
Cwd: "/",
4140
Args: []string{"/bin/true"},
@@ -101,8 +100,7 @@ func BenchmarkExecInBigEnv(b *testing.B) {
101100
wantOut.WriteString(e + "\n")
102101
}
103102

104-
b.ResetTimer()
105-
for i := 0; i < b.N; i++ {
103+
for b.Loop() {
106104
buffers := newStdBuffers()
107105
exec := &libcontainer.Process{
108106
Cwd: "/",

libcontainer/integration/exec_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -850,8 +850,8 @@ func TestMountCgroupRO(t *testing.T) {
850850
buffers := runContainerOk(t, config, "mount")
851851

852852
mountInfo := buffers.Stdout.String()
853-
lines := strings.Split(mountInfo, "\n")
854-
for _, l := range lines {
853+
lines := strings.SplitSeq(mountInfo, "\n")
854+
for l := range lines {
855855
if strings.HasPrefix(l, "tmpfs on /sys/fs/cgroup") {
856856
if !strings.Contains(l, "ro") ||
857857
!strings.Contains(l, "nosuid") ||
@@ -892,8 +892,8 @@ func TestMountCgroupRW(t *testing.T) {
892892
buffers := runContainerOk(t, config, "mount")
893893

894894
mountInfo := buffers.Stdout.String()
895-
lines := strings.Split(mountInfo, "\n")
896-
for _, l := range lines {
895+
lines := strings.SplitSeq(mountInfo, "\n")
896+
for l := range lines {
897897
if strings.HasPrefix(l, "tmpfs on /sys/fs/cgroup") {
898898
if !strings.Contains(l, "rw") ||
899899
!strings.Contains(l, "nosuid") ||
@@ -1206,8 +1206,8 @@ func TestRootfsPropagationSlaveMount(t *testing.T) {
12061206
dir2cont = filepath.Join(dir1cont, filepath.Base(dir2host))
12071207

12081208
propagationInfo := stdout2.String()
1209-
lines := strings.Split(propagationInfo, "\n")
1210-
for _, l := range lines {
1209+
lines := strings.SplitSeq(propagationInfo, "\n")
1210+
for l := range lines {
12111211
linefields := strings.Split(l, " ")
12121212
if len(linefields) < 5 {
12131213
continue

libcontainer/internal/userns/usernsfd_linux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func BenchmarkSpawnProc(b *testing.B) {
4242
}
4343
})
4444

45-
for i := 0; i < b.N; i++ {
45+
for b.Loop() {
4646
proc, err := spawnProc(mapping)
4747
if err != nil {
4848
b.Error(err)

0 commit comments

Comments
 (0)